Skip to content

Commit 7b492d1

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
1 parent bf6ff4f commit 7b492d1

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
@@ -652,9 +652,22 @@ bool Scanner::lexPragma(const char *&First, const char *const End) {
652652
return false;
653653
}
654654

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

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

clang/lib/Lex/Lexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4480,6 +4480,7 @@ bool Lexer::LexDependencyDirectiveTokenWhileSkipping(Token &Result) {
44804480
case pp_pragma_push_macro:
44814481
case pp_pragma_pop_macro:
44824482
case pp_pragma_include_alias:
4483+
case pp_pragma_system_header:
44834484
case pp_include_next:
44844485
case decl_at_import:
44854486
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)