[clang] d19e71d - [clang/Lex/DependencyDirectivesScanner] Ignore import/include directives with missing filenames without failing the scan (#100126)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 23 13:00:03 PDT 2024
Author: Argyrios Kyrtzidis
Date: 2024-07-23T12:59:59-07:00
New Revision: d19e71db8a3de65de5da5d5bc4e1f9c1020c574c
URL: https://github.com/llvm/llvm-project/commit/d19e71db8a3de65de5da5d5bc4e1f9c1020c574c
DIFF: https://github.com/llvm/llvm-project/commit/d19e71db8a3de65de5da5d5bc4e1f9c1020c574c.diff
LOG: [clang/Lex/DependencyDirectivesScanner] Ignore import/include directives with missing filenames without failing the scan (#100126)
Follow-up to `34ab855826b8cb0c3b46c770b83390bd1fe95c64`:
* Don't fail the scan with an include with missing filename, it may be
inside a skipped preprocessor block. Let the compilation provide any
related error.
* Fix an issue where the lexer was skipping through the next directive,
after ignoring the include with missing filename.
Added:
Modified:
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 31a4c0f52b465..088d1cc96e3a2 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -914,8 +914,7 @@ bool Scanner::lexPPLine(const char *&First, const char *const End) {
case pp_import:
// Ignore missing filenames in include or import directives.
if (lexIncludeFilename(First, End).is(tok::eod)) {
- skipDirective(Id, First, End);
- return true;
+ return false;
}
break;
default:
diff --git a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
index 513e184be09ec..bdb5e23510118 100644
--- a/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ b/clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -653,12 +653,28 @@ TEST(MinimizeSourceToDependencyDirectivesTest, AtImport) {
TEST(MinimizeSourceToDependencyDirectivesTest, EmptyIncludesAndImports) {
SmallVector<char, 128> Out;
- ASSERT_TRUE(minimizeSourceToDependencyDirectives("#import\n", Out));
- ASSERT_TRUE(minimizeSourceToDependencyDirectives("#include\n", Out));
- ASSERT_TRUE(minimizeSourceToDependencyDirectives("#ifdef A\n"
- "#import \n"
- "#endif\n",
- Out));
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives("#import\n", Out));
+ EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
+
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives("#include\n", Out));
+ EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
+
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives("#ifdef A\n"
+ "#import \n"
+ "#endif\n",
+ Out));
+ // The ifdef block is removed because it's "empty".
+ EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
+
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives("#ifdef A\n"
+ "#import \n"
+ "#define B\n"
+ "#endif\n",
+ Out));
+ EXPECT_STREQ("#ifdef A\n"
+ "#define B\n"
+ "#endif\n",
+ Out.data());
}
TEST(MinimizeSourceToDependencyDirectivesTest, AtImportFailures) {
More information about the cfe-commits
mailing list