Skip to content

Commit fa5a534

Browse files
committed
[clang] Add LangOpts.ScanDeps to fix #88896
1 parent a4993a2 commit fa5a534

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ LANGOPT(CXXAssumptions, 1, 1, NotCompatible, "Enable or disable codegen and comp
438438

439439
LANGOPT(RawStringLiterals, 1, 1, NotCompatible, "Enable or disable raw string literals")
440440

441+
LANGOPT(ScanDeps, 1, 0, NotCompatible, "True if we are scanning by DependencyDirectivesScanner")
442+
441443
ENUM_LANGOPT(StrictFlexArraysLevel, StrictFlexArraysLevelKind, 2,
442444
StrictFlexArraysLevelKind::Default, NotCompatible,
443445
"Rely on strict definition of flexible arrays")

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct Scanner {
7474
LangOpts.ObjC = true;
7575
LangOpts.LineComment = true;
7676
LangOpts.RawStringLiterals = true;
77+
LangOpts.ScanDeps = true;
7778
// FIXME: we do not enable C11 or C++11, so we are missing u/u8/U"".
7879
return LangOpts;
7980
}

clang/lib/Lex/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ bool Lexer::LexNumericConstant(Token &Result, const char *CurPtr) {
20872087
}
20882088

20892089
// If we have a digit separator, continue.
2090-
if (C == '\'' && (LangOpts.CPlusPlus14 || LangOpts.C23)) {
2090+
if (C == '\'' && (LangOpts.CPlusPlus14 || LangOpts.C23 || LangOpts.ScanDeps)) {
20912091
auto [Next, NextSize] = getCharAndSizeNoWarn(CurPtr + Size, LangOpts);
20922092
if (isAsciiIdentifierContinue(Next)) {
20932093
if (!isLexingRawMode())

clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "clang/Lex/DependencyDirectivesScanner.h"
10+
#include "clang/Basic/TokenKinds.h"
1011
#include "llvm/ADT/SmallString.h"
1112
#include "gtest/gtest.h"
1213

@@ -1000,6 +1001,21 @@ int z = 128'78;
10001001
EXPECT_STREQ("#include <test.h>\n", Out.data());
10011002
}
10021003

1004+
TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralInPreprocessor) {
1005+
SmallVector<char, 128> Out;
1006+
SmallVector<dependency_directives_scan::Token, 8> Tokens;
1007+
SmallVector<Directive, 4> Directives;
1008+
1009+
StringRef Source = R"(
1010+
#if 1'2 == 12
1011+
#endif
1012+
)";
1013+
ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out, Tokens, Directives));
1014+
ASSERT_GE(Tokens.size(), 4u);
1015+
EXPECT_EQ(Tokens[2].Kind, tok::numeric_constant);
1016+
EXPECT_EQ(Tokens[3].Kind, tok::equalequal);
1017+
}
1018+
10031019
TEST(MinimizeSourceToDependencyDirectivesTest, PragmaOnce) {
10041020
SmallVector<char, 128> Out;
10051021
SmallVector<dependency_directives_scan::Token, 4> Tokens;

0 commit comments

Comments
 (0)