Skip to content

Commit 330b557

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. If that compiler instance had an index unit output path set, we would use that name for the unit file of the pcm, which would get overwritten as soon as the unit for that source file is written at the end of that compilation process. Fix this issue by clearning the index unit output path for the PCM compilation process. Also respect `IndexIgnorePcms` and don’t generate an index for the PCMs by clearning the `IndexStorePath` to disable indexing of the PCMs
1 parent 9db20e6 commit 330b557

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 = {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)