Skip to content

[clang][deps] Properly capture the global module and '\n' for all module directives #148685

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
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions clang/lib/Lex/Preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,8 @@ void Preprocessor::Lex(Token &Result) {
case tok::period:
ModuleDeclState.handlePeriod();
break;
case tok::eod:
break;
case tok::identifier:
// Check "import" and "module" when there is no open bracket. The two
// identifiers are not meaningful with open brackets.
Expand Down
11 changes: 11 additions & 0 deletions clang/lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2361,6 +2361,8 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
// Parse a global-module-fragment, if present.
if (getLangOpts().CPlusPlusModules && Tok.is(tok::semi)) {
SourceLocation SemiLoc = ConsumeToken();
// Note: Not required to pass CI
TryConsumeToken(tok::eod);
Copy link
Contributor Author

@naveen-seth naveen-seth Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patch passes the test-suite without the additional (commented) TryConsumeToken(tok::eod) calls added here, but since this patch adds a tok::eod at the end of every module directive, it also makes sense to consume it.

The next/newest commit (0bc7245) includes only the minimal needed changes and leaves out the unnecessary TryConsumeToken(tok::eod) calls.

I split this out into its own commit so I could get you feedback on this.

if (!Introducer.isFirstPPToken()) {
Diag(StartLoc, diag::err_global_module_introducer_not_at_start)
<< SourceRange(StartLoc, SemiLoc);
Expand All @@ -2385,6 +2387,8 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
SourceLocation PrivateLoc = ConsumeToken();
DiagnoseAndSkipCXX11Attributes();
ExpectAndConsumeSemi(diag::err_private_module_fragment_expected_semi);
// Note: Not required to pass CI
TryConsumeToken(tok::eod);
ImportState = ImportState == Sema::ModuleImportState::ImportAllowed
? Sema::ModuleImportState::PrivateFragmentImportAllowed
: Sema::ModuleImportState::PrivateFragmentImportFinished;
Expand Down Expand Up @@ -2416,6 +2420,8 @@ Parser::ParseModuleDecl(Sema::ModuleImportState &ImportState) {
/*WarnOnUnknownAttrs=*/true);

ExpectAndConsumeSemi(diag::err_module_expected_semi);
// Note: Not required to pass CI
TryConsumeToken(tok::eod);

return Actions.ActOnModuleDecl(StartLoc, ModuleLoc, MDK, Path, Partition,
ImportState, Introducer.isFirstPPToken());
Expand Down Expand Up @@ -2519,6 +2525,7 @@ Decl *Parser::ParseModuleImport(SourceLocation AtLoc,
break;
}
ExpectAndConsumeSemi(diag::err_module_expected_semi);
TryConsumeToken(tok::eod);

if (SeenError)
return nullptr;
Expand Down Expand Up @@ -2560,6 +2567,8 @@ bool Parser::ParseModuleName(SourceLocation UseLoc,

Diag(Tok, diag::err_module_expected_ident) << IsImport;
SkipUntil(tok::semi);
// Note: Not required to pass CI
TryConsumeToken(tok::eod);
return true;
}

Expand All @@ -2571,6 +2580,8 @@ bool Parser::ParseModuleName(SourceLocation UseLoc,
return false;

ConsumeToken();
// Note: Not required to pass CI
TryConsumeToken(tok::eod);
}
}

Expand Down