Skip to content

Commit 911046b

Browse files
authored
Merge pull request #10848 from ahoppen/dont-index-implicit-modules
[Index] Don't generate a unit file when building implicit modules
2 parents 7098e11 + 330b557 commit 911046b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,15 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
13571357
HSOpts.ModulesHashContent = true;
13581358
FrontendOpts.Inputs = {std::move(Input)};
13591359
FrontendOpts.MayEmitDiagnosticsAfterProcessingSourceFiles = false;
1360+
// Clear `IndexUnitOutputPath`. Otherwise the unit for the pcm will be named
1361+
// after the primary source file, and will be overwritten when that file's
1362+
// unit is finally written.
1363+
FrontendOpts.IndexUnitOutputPath = "";
1364+
if (FrontendOpts.IndexIgnorePcms) {
1365+
// If we shouldn't index pcms, disable indexing by clearing the index store
1366+
// path.
1367+
FrontendOpts.IndexStorePath = "";
1368+
}
13601369

13611370
// Don't free the remapped file buffers; they are owned by our caller.
13621371
PPOpts.RetainRemappedFileBuffers = true;

clang/lib/Index/IndexingAction.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,12 +682,17 @@ class WrappingIndexRecordAction : public WrapperFrontendAction,
682682
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
683683
StringRef InFile) override {
684684
auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
685-
if (!OtherConsumer)
686-
return nullptr;
685+
686+
if (CI.getFrontendOpts().IndexStorePath.empty()) {
687+
// We are not generating an index store. Nothing to do.
688+
return OtherConsumer;
689+
}
687690

688691
CreatedASTConsumer = true;
689692
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
690-
Consumers.push_back(std::move(OtherConsumer));
693+
if (OtherConsumer) {
694+
Consumers.push_back(std::move(OtherConsumer));
695+
}
691696
Consumers.push_back(createIndexASTConsumer(CI));
692697
return std::make_unique<MultiplexConsumer>(std::move(Consumers));
693698
}

0 commit comments

Comments
 (0)