Skip to content

[clang/Lex/DependencyDirectivesScanner] Ignore import/include directives with missing filenames without failing the scan #100126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions clang/lib/Lex/DependencyDirectivesScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 22 additions & 6 deletions clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading