diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h b/clang/include/clang/Lex/DependencyDirectivesScanner.h --- a/clang/include/clang/Lex/DependencyDirectivesScanner.h +++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h @@ -68,6 +68,7 @@ pp_pragma_push_macro, pp_pragma_pop_macro, pp_pragma_include_alias, + pp_pragma_system_header, pp_include_next, pp_if, pp_ifdef, 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 @@ -652,9 +652,22 @@ return false; } - // #pragma clang. - if (!isNextIdentifierOrSkipLine("module", First, End)) + FoundId = tryLexIdentifierOrSkipLine(First, End); + if (!FoundId) return false; + Id = *FoundId; + + // #pragma clang system_header + if (Id == "system_header") { + lexPPDirectiveBody(First, End); + pushDirective(pp_pragma_system_header); + return false; + } + + if (Id != "module") { + skipLine(First, End); + return false; + } // #pragma clang module. if (!isNextIdentifierOrSkipLine("import", First, End)) diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp --- a/clang/lib/Lex/Lexer.cpp +++ b/clang/lib/Lex/Lexer.cpp @@ -4480,6 +4480,7 @@ case pp_pragma_push_macro: case pp_pragma_pop_macro: case pp_pragma_include_alias: + case pp_pragma_system_header: case pp_include_next: case decl_at_import: case cxx_module_decl: 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 @@ -90,7 +90,8 @@ "#pragma pop_macro(A)\n" "#pragma include_alias(, )\n" "export module m;\n" - "import m;\n", + "import m;\n" + "#pragma clang system_header\n", Out, Tokens, Directives)); EXPECT_EQ(pp_define, Directives[0].Kind); EXPECT_EQ(pp_undef, Directives[1].Kind); @@ -113,7 +114,8 @@ EXPECT_EQ(pp_pragma_include_alias, Directives[18].Kind); EXPECT_EQ(cxx_export_module_decl, Directives[19].Kind); EXPECT_EQ(cxx_import_decl, Directives[20].Kind); - EXPECT_EQ(pp_eof, Directives[21].Kind); + EXPECT_EQ(pp_pragma_system_header, Directives[21].Kind); + EXPECT_EQ(pp_eof, Directives[22].Kind); } TEST(MinimizeSourceToDependencyDirectivesTest, EmptyHash) {