[PATCH] D149777: [clang][deps] Teach dep directive scanner about #pragma clang system_header
Ben Langmuir via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 3 12:24:03 PDT 2023
benlangmuir created this revision.
benlangmuir added a reviewer: akyrtzi.
Herald added a project: All.
benlangmuir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149777
Files:
clang/include/clang/Lex/DependencyDirectivesScanner.h
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/lib/Lex/Lexer.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===================================================================
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -90,7 +90,8 @@
"#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);
@@ -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) {
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ 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:
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===================================================================
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ 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))
Index: clang/include/clang/Lex/DependencyDirectivesScanner.h
===================================================================
--- clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ 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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149777.519203.patch
Type: text/x-patch
Size: 2835 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230503/4e68b909/attachment.bin>
More information about the cfe-commits
mailing list