Skip to content

[Index] Don't generate a unit file when building implicit modules #10848

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
Jun 20, 2025
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
9 changes: 9 additions & 0 deletions clang/lib/Frontend/CompilerInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,15 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
HSOpts.ModulesHashContent = true;
FrontendOpts.Inputs = {Input};
FrontendOpts.MayEmitDiagnosticsAfterProcessingSourceFiles = false;
// Clear `IndexUnitOutputPath`. Otherwise the unit for the pcm will be named
// after the primary source file, and will be overwritten when that file's
// unit is finally written.
FrontendOpts.IndexUnitOutputPath = "";
if (FrontendOpts.IndexIgnorePcms) {
// If we shouldn't index pcms, disable indexing by clearing the index store
// path.
FrontendOpts.IndexStorePath = "";
}

// Don't free the remapped file buffers; they are owned by our caller.
PPOpts.RetainRemappedFileBuffers = true;
Expand Down
11 changes: 8 additions & 3 deletions clang/lib/Index/IndexingAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,12 +682,17 @@ class WrappingIndexRecordAction : public WrapperFrontendAction,
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
StringRef InFile) override {
auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
if (!OtherConsumer)
return nullptr;

if (CI.getFrontendOpts().IndexStorePath.empty()) {
// We are not generating an index store. Nothing to do.
return OtherConsumer;
}

CreatedASTConsumer = true;
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
Consumers.push_back(std::move(OtherConsumer));
if (OtherConsumer) {
Consumers.push_back(std::move(OtherConsumer));
}
Consumers.push_back(createIndexASTConsumer(CI));
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
}
Expand Down