akyrtzi updated this revision to Diff 459888. akyrtzi added a comment. Add comment to clarify why we skip if `tok::hashhash` is encountered.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D133674/new/ https://reviews.llvm.org/D133674 Files: clang/lib/Lex/DependencyDirectivesScanner.cpp clang/unittests/Lex/DependencyDirectivesScannerTest.cpp Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp =================================================================== --- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp +++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp @@ -124,6 +124,21 @@ EXPECT_STREQ("#define MACRO a\n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) { + SmallVector<char, 128> Out; + + StringRef Source = R"( + #define S + #if 0 + ##pragma cool + ##include "t.h" + #endif + #define E + )"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data()); +} + TEST(MinimizeSourceToDependencyDirectivesTest, Define) { SmallVector<char, 128> Out; SmallVector<dependency_directives_scan::Token, 4> Tokens; Index: clang/lib/Lex/DependencyDirectivesScanner.cpp =================================================================== --- clang/lib/Lex/DependencyDirectivesScanner.cpp +++ clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -742,6 +742,14 @@ // Lex '#'. const dependency_directives_scan::Token &HashTok = lexToken(First, End); + if (HashTok.is(tok::hashhash)) { + // A \p tok::hashhash at this location is passed by the preprocessor to the + // parser to interpret, like any other token. So for dependency scanning + // skip it like a normal token not affecting the preprocessor. + skipLine(First, End); + assert(First <= End); + return false; + } assert(HashTok.is(tok::hash)); (void)HashTok;
Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp =================================================================== --- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp +++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp @@ -124,6 +124,21 @@ EXPECT_STREQ("#define MACRO a\n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) { + SmallVector<char, 128> Out; + + StringRef Source = R"( + #define S + #if 0 + ##pragma cool + ##include "t.h" + #endif + #define E + )"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data()); +} + TEST(MinimizeSourceToDependencyDirectivesTest, Define) { SmallVector<char, 128> Out; SmallVector<dependency_directives_scan::Token, 4> Tokens; Index: clang/lib/Lex/DependencyDirectivesScanner.cpp =================================================================== --- clang/lib/Lex/DependencyDirectivesScanner.cpp +++ clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -742,6 +742,14 @@ // Lex '#'. const dependency_directives_scan::Token &HashTok = lexToken(First, End); + if (HashTok.is(tok::hashhash)) { + // A \p tok::hashhash at this location is passed by the preprocessor to the + // parser to interpret, like any other token. So for dependency scanning + // skip it like a normal token not affecting the preprocessor. + skipLine(First, End); + assert(First <= End); + return false; + } assert(HashTok.is(tok::hash)); (void)HashTok;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits