Skip to content

Commit

Permalink
[clang][deps] Teach dep directive scanner about #pragma clang system_…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
benlangmuir committed May 3, 2023
1 parent bf6ff4f commit 7b492d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/Lex/DependencyDirectivesScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum DirectiveKind : uint8_t {
pp_pragma_push_macro,
pp_pragma_pop_macro,
pp_pragma_include_alias,
pp_pragma_system_header,
pp_include_next,
pp_if,
pp_ifdef,
Expand Down
17 changes: 15 additions & 2 deletions clang/lib/Lex/DependencyDirectivesScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,22 @@ bool Scanner::lexPragma(const char *&First, const char *const End) {
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))
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Lex/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,7 @@ bool Lexer::LexDependencyDirectiveTokenWhileSkipping(Token &Result) {
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:
Expand Down
6 changes: 4 additions & 2 deletions clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ TEST(MinimizeSourceToDependencyDirectivesTest, AllTokens) {
"#pragma pop_macro(A)\n"
"#pragma include_alias(<A>, <B>)\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);
Expand All @@ -113,7 +114,8 @@ TEST(MinimizeSourceToDependencyDirectivesTest, AllTokens) {
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) {
Expand Down

0 comments on commit 7b492d1

Please sign in to comment.