Skip to content

Commit 91c0899

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 19e6fd0 commit 91c0899

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
@@ -1352,6 +1352,15 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
13521352
HSOpts.ModulesHashContent = true;
13531353
FrontendOpts.Inputs = {Input};
13541354
FrontendOpts.MayEmitDiagnosticsAfterProcessingSourceFiles = false;
1355+
// Clear `IndexUnitOutputPath`. Otherwise the unit for the pcm will be named
1356+
// after the primary source file, and will be overwritten when that file's
1357+
// unit is finally written.
1358+
FrontendOpts.IndexUnitOutputPath = "";
1359+
if (FrontendOpts.IndexIgnorePcms) {
1360+
// If we shouldn't index pcms, disable indexing by clearing the index store
1361+
// path.
1362+
FrontendOpts.IndexStorePath = "";
1363+
}
13551364

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

clang/lib/Index/IndexingAction.cpp

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

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

0 commit comments

Comments
 (0)