Skip to content

Commit 992172f

Browse files
author
git apple-llvm automerger
committed
Merge commit '5444a4a33c7f' from swift/release/6.2 into stable/20240723
2 parents 421bc9f + 5444a4a commit 992172f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,15 @@ bool Scanner::lexModuleDirectiveBody(DirectiveKind Kind, const char *&First,
496496
const char *const End) {
497497
const char *DirectiveLoc = Input.data() + CurDirToks.front().Offset;
498498
for (;;) {
499+
// Keep a copy of the First char incase it needs to be reset.
500+
const char *Previous = First;
499501
const dependency_directives_scan::Token &Tok = lexToken(First, End);
502+
if ((Tok.is(tok::hash) || Tok.is(tok::at)) &&
503+
(Tok.Flags & clang::Token::StartOfLine)) {
504+
CurDirToks.pop_back();
505+
First = Previous;
506+
return false;
507+
}
500508
if (Tok.is(tok::eof))
501509
return reportError(
502510
DirectiveLoc,
@@ -846,6 +854,7 @@ bool Scanner::lexPPLine(const char *&First, const char *const End) {
846854
if (*First == '@')
847855
return lexAt(First, End);
848856

857+
// Handle module directives for C++20 modules.
849858
if (*First == 'i' || *First == 'e' || *First == 'm')
850859
return lexModule(First, End);
851860

clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,28 @@ TEST(MinimizeSourceToDependencyDirectivesTest, EmptyIncludesAndImports) {
661661
Out));
662662
}
663663

664-
TEST(MinimizeSourceToDependencyDirectivesTest, AtImportFailures) {
664+
TEST(MinimizeSourceToDependencyDirectivesTest, ImportFailures) {
665665
SmallVector<char, 128> Out;
666666

667667
ASSERT_TRUE(minimizeSourceToDependencyDirectives("@import A\n", Out));
668668
ASSERT_FALSE(
669669
minimizeSourceToDependencyDirectives("@import MACRO(A);\n", Out));
670670
ASSERT_FALSE(minimizeSourceToDependencyDirectives("@import \" \";\n", Out));
671+
672+
ASSERT_FALSE(minimizeSourceToDependencyDirectives("import <Foo.h>\n"
673+
"@import Foo;",
674+
Out));
675+
EXPECT_STREQ("@import Foo;\n", Out.data());
676+
677+
ASSERT_FALSE(
678+
minimizeSourceToDependencyDirectives("import <Foo.h>\n"
679+
"#import <Foo.h>\n"
680+
"@;\n"
681+
"#pragma clang module import Foo",
682+
Out));
683+
EXPECT_STREQ("#import <Foo.h>\n"
684+
"#pragma clang module import Foo\n",
685+
Out.data());
671686
}
672687

673688
TEST(MinimizeSourceToDependencyDirectivesTest, RawStringLiteral) {

0 commit comments

Comments
 (0)