@@ -787,12 +787,15 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
787787 StringRef ModuleName, DependencyConsumer &Consumer,
788788 DependencyActionController &Controller) {
789789 auto &CI = *CIPtr;
790- CompilerInvocation Inv (*OriginalInvocation);
791790
792791 CI.clearDependencyCollectors ();
793792 auto MDC = initializeScanInstanceDependencyCollector (
794793 CI, std::make_unique<DependencyOutputOptions>(*OutputOpts), CWD, Consumer,
795- Worker.Service , Inv, Controller, PrebuiltModuleASTMap, StableDirs);
794+ Worker.Service ,
795+ /* The MDC's constructor makes a copy of the OriginalInvocation, so
796+ we can pass it in without worrying that it might be changed across
797+ invocations of computeDependencies. */
798+ *OriginalInvocation, Controller, PrebuiltModuleASTMap, StableDirs);
796799
797800 if (!SrcLocOffset) {
798801 // When SrcLocOffset is zero, we are at the beginning of the fake source
@@ -839,13 +842,20 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
839842 auto DCs = CI.getDependencyCollectors ();
840843 for (auto &DC : DCs) {
841844 auto *CB = DC->getPPCallbacks ();
842- assert (CB && " DC must have dependency collector callback" );
843- CB->moduleImport (SourceLocation (), Path, ModResult);
844- CB->EndOfMainFile ();
845+ if (CB) {
846+ CB->moduleImport (SourceLocation (), Path, ModResult);
847+
848+ // Note that we are calling the CB's EndOfMainFile function, which
849+ // forwards the results to the dependency consumer.
850+ // It does not indicate the end of processing the fake file.
851+ CB->EndOfMainFile ();
852+ }
845853 }
846854
847- MDC->applyDiscoveredDependencies (Inv);
848- Consumer.handleBuildCommand ({CommandLine[0 ], Inv.getCC1CommandLine ()});
855+ CompilerInvocation ModuleInvocation (*OriginalInvocation);
856+ MDC->applyDiscoveredDependencies (ModuleInvocation);
857+ Consumer.handleBuildCommand (
858+ {CommandLine[0 ], ModuleInvocation.getCC1CommandLine ()});
849859
850860 // Remove the PPCallbacks since they are going out of scope.
851861 CI.getPreprocessor ().removePPCallbacks ();
0 commit comments