Skip to content

Commit d67ff0e

Browse files
committed
[clang][deps] Teach dep directive scanner about #pragma clang system_header
This ensures we get the correct FileCharacteristic during scanning. In a yet-to-be-upstreamed branch this fixes observable failures, but it's also good to handle this on principle: the FileCharacteristic is a property of the file that is observable in the scanner, so there is nothing preventing us from depending on it. rdar://108627403 Differential Revision: https://reviews.llvm.org/D149777 (cherry picked from commit 7b492d1)
1 parent e91f6ca commit d67ff0e

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

clang/include/clang/Lex/DependencyDirectivesScanner.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum DirectiveKind : uint8_t {
6868
pp_pragma_push_macro,
6969
pp_pragma_pop_macro,
7070
pp_pragma_include_alias,
71+
pp_pragma_system_header,
7172
pp_include_next,
7273
pp_if,
7374
pp_ifdef,

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,22 @@ bool Scanner::lexPragma(const char *&First, const char *const End) {
650650
return false;
651651
}
652652

653-
// #pragma clang.
654-
if (!isNextIdentifierOrSkipLine("module", First, End))
653+
FoundId = tryLexIdentifierOrSkipLine(First, End);
654+
if (!FoundId)
655655
return false;
656+
Id = *FoundId;
657+
658+
// #pragma clang system_header
659+
if (Id == "system_header") {
660+
lexPPDirectiveBody(First, End);
661+
pushDirective(pp_pragma_system_header);
662+
return false;
663+
}
664+
665+
if (Id != "module") {
666+
skipLine(First, End);
667+
return false;
668+
}
656669

657670
// #pragma clang module.
658671
if (!isNextIdentifierOrSkipLine("import", First, End))

clang/lib/Lex/Lexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4441,6 +4441,7 @@ bool Lexer::LexDependencyDirectiveTokenWhileSkipping(Token &Result) {
44414441
case pp_pragma_push_macro:
44424442
case pp_pragma_pop_macro:
44434443
case pp_pragma_include_alias:
4444+
case pp_pragma_system_header:
44444445
case pp_include_next:
44454446
case decl_at_import:
44464447
case cxx_module_decl:

clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ TEST(MinimizeSourceToDependencyDirectivesTest, AllTokens) {
9090
"#pragma pop_macro(A)\n"
9191
"#pragma include_alias(<A>, <B>)\n"
9292
"export module m;\n"
93-
"import m;\n",
93+
"import m;\n"
94+
"#pragma clang system_header\n",
9495
Out, Tokens, Directives));
9596
EXPECT_EQ(pp_define, Directives[0].Kind);
9697
EXPECT_EQ(pp_undef, Directives[1].Kind);
@@ -113,7 +114,8 @@ TEST(MinimizeSourceToDependencyDirectivesTest, AllTokens) {
113114
EXPECT_EQ(pp_pragma_include_alias, Directives[18].Kind);
114115
EXPECT_EQ(cxx_export_module_decl, Directives[19].Kind);
115116
EXPECT_EQ(cxx_import_decl, Directives[20].Kind);
116-
EXPECT_EQ(pp_eof, Directives[21].Kind);
117+
EXPECT_EQ(pp_pragma_system_header, Directives[21].Kind);
118+
EXPECT_EQ(pp_eof, Directives[22].Kind);
117119
}
118120

119121
TEST(MinimizeSourceToDependencyDirectivesTest, EmptyHash) {

0 commit comments

Comments
 (0)