Skip to content

[clang][deps] Don't treat ObjC method args as module directives #97654

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 18, 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
13 changes: 12 additions & 1 deletion clang/lib/Lex/DependencyDirectivesScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,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 @@ -970,6 +970,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
Loading