Skip to content

Commit 097782e

Browse files
authored
Merge pull request #8990 from Bigcheese/dev/module-kw-scan-6.0
[clang][deps] Don't treat ObjC method args as module directives
2 parents d85bebe + 9e41631 commit 097782e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clang/lib/Lex/DependencyDirectivesScanner.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,18 @@ bool Scanner::lexModule(const char *&First, const char *const End) {
661661
// an import.
662662

663663
switch (*First) {
664-
case ':':
664+
case ':': {
665+
// `module :` is never the start of a valid module declaration.
666+
if (Id == "module") {
667+
skipLine(First, End);
668+
return false;
669+
}
670+
// `import:(type)name` is a valid ObjC method decl, so check one more token.
671+
(void)lexToken(First, End);
672+
if (!tryLexIdentifierOrSkipLine(First, End))
673+
return false;
674+
break;
675+
}
665676
case '<':
666677
case '"':
667678
break;

clang/unittests/Lex/DependencyDirectivesScannerTest.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,23 @@ ort \
968968
EXPECT_EQ(Directives[1].Kind, cxx_export_module_decl);
969969
}
970970

971+
TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) {
972+
SmallVector<char, 128> Out;
973+
974+
StringRef Source = R"(
975+
@interface SomeObjcClass
976+
- (void)func:(int)otherData
977+
module:(int)module
978+
import:(int)import;
979+
@end
980+
)";
981+
982+
ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
983+
// `module :` and `import :` not followed by an identifier are not treated as
984+
// directive lines because they can be method argument decls.
985+
EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
986+
}
987+
971988
TEST(MinimizeSourceToDependencyDirectivesTest, TokensBeforeEOF) {
972989
SmallString<128> Out;
973990

0 commit comments

Comments
 (0)