Skip to content

Commit

Permalink
Merge pull request llvm#8990 from Bigcheese/dev/module-kw-scan-6.0
Browse files Browse the repository at this point in the history
[clang][deps] Don't treat ObjC method args as module directives
  • Loading branch information
fredriss authored Aug 1, 2024
2 parents d85bebe + 9e41631 commit 097782e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 12 additions & 1 deletion clang/lib/Lex/DependencyDirectivesScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,18 @@ bool Scanner::lexModule(const char *&First, const char *const End) {
// an import.

switch (*First) {
case ':':
case ':': {
// `module :` is never the start of a valid module declaration.
if (Id == "module") {
skipLine(First, End);
return false;
}
// `import:(type)name` is a valid ObjC method decl, so check one more token.
(void)lexToken(First, End);
if (!tryLexIdentifierOrSkipLine(First, End))
return false;
break;
}
case '<':
case '"':
break;
Expand Down
17 changes: 17 additions & 0 deletions clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,23 @@ ort \
EXPECT_EQ(Directives[1].Kind, cxx_export_module_decl);
}

TEST(MinimizeSourceToDependencyDirectivesTest, ObjCMethodArgs) {
SmallVector<char, 128> Out;

StringRef Source = R"(
@interface SomeObjcClass
- (void)func:(int)otherData
module:(int)module
import:(int)import;
@end
)";

ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
// `module :` and `import :` not followed by an identifier are not treated as
// directive lines because they can be method argument decls.
EXPECT_STREQ("<TokBeforeEOF>\n", Out.data());
}

TEST(MinimizeSourceToDependencyDirectivesTest, TokensBeforeEOF) {
SmallString<128> Out;

Expand Down

0 comments on commit 097782e

Please sign in to comment.