Skip to content

Commit 65189ef

Browse files
committed
[Index] Don't generate a unit file when building implicit modules
When compiling a file that requires a module to be compiled, we cloned the compiler instance for the module compile. This means that the cloned compiler instance still had the index store path and index unit output path of the original file. We were thus generating a unit file with the original file name for the compiled module. This unit file would ultimately get overwritten when the original source file was compiled, so there was no correctness issue per se but this means we were doing unnecessary work. Disable emitting an index store for module compiles to fix this.
1 parent 9db20e6 commit 65189ef

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,8 @@ std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompileImpl(
13571357
HSOpts.ModulesHashContent = true;
13581358
FrontendOpts.Inputs = {Input};
13591359
FrontendOpts.MayEmitDiagnosticsAfterProcessingSourceFiles = false;
1360+
FrontendOpts.IndexStorePath = "";
1361+
FrontendOpts.IndexUnitOutputPath = "";
13601362

13611363
// Don't free the remapped file buffers; they are owned by our caller.
13621364
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)