diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp --- a/clang/lib/Lex/DependencyDirectivesScanner.cpp +++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp @@ -742,6 +742,11 @@ // Lex '#'. const dependency_directives_scan::Token &HashTok = lexToken(First, End); + if (HashTok.is(tok::hashhash)) { + skipLine(First, End); + assert(First <= End); + return false; + } assert(HashTok.is(tok::hash)); (void)HashTok; diff --git a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp --- a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp +++ b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp @@ -124,6 +124,21 @@ EXPECT_STREQ("#define MACRO a\n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) { + SmallVector 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 Out; SmallVector Tokens;