@@ -814,26 +814,24 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
814814 FileID MainFileID = SM.getMainFileID ();
815815 SourceLocation FileStart = SM.getLocForStartOfFile (MainFileID);
816816 SourceLocation IDLocation = FileStart.getLocWithOffset (SrcLocOffset);
817+ PPCallbacks *CB = nullptr ;
817818 if (!SrcLocOffset) {
818819 // We need to call EnterSourceFile when SrcLocOffset is zero to initialize
819820 // the preprocessor.
820821 PP.EnterSourceFile (MainFileID, nullptr , SourceLocation ());
822+ CB = MDC->getPPCallbacks ();
821823 } else {
822824 // When SrcLocOffset is non-zero, the preprocessor has already been
823825 // initialized through a previous call of computeDependencies. We want to
824826 // preserve the PP's state, hence we do not call EnterSourceFile again.
825- auto DCs = CI.getDependencyCollectors ();
826- for (auto &DC : DCs) {
827- DC->attachToPreprocessor (PP);
828- auto *CB = DC->getPPCallbacks ();
829-
830- FileID PrevFID;
831- SrcMgr::CharacteristicKind FileType =
832- SM.getFileCharacteristic (IDLocation);
833- CB->LexedFileChanged (MainFileID,
834- PPChainedCallbacks::LexedFileChangeReason::EnterFile,
835- FileType, PrevFID, IDLocation);
836- }
827+ MDC->attachToPreprocessor (PP);
828+ CB = MDC->getPPCallbacks ();
829+
830+ FileID PrevFID;
831+ SrcMgr::CharacteristicKind FileType = SM.getFileCharacteristic (IDLocation);
832+ CB->LexedFileChanged (MainFileID,
833+ PPChainedCallbacks::LexedFileChangeReason::EnterFile,
834+ FileType, PrevFID, IDLocation);
837835 }
838836
839837 SrcLocOffset++;
@@ -842,18 +840,12 @@ llvm::Error CompilerInstanceWithContext::computeDependencies(
842840 Path.emplace_back (IDLocation, ModuleID);
843841 auto ModResult = CI.loadModule (IDLocation, Path, Module::Hidden, false );
844842
845- auto DCs = CI.getDependencyCollectors ();
846- for (auto &DC : DCs) {
847- auto *CB = DC->getPPCallbacks ();
848- if (CB) {
849- CB->moduleImport (SourceLocation (), Path, ModResult);
850-
851- // Note that we are calling the CB's EndOfMainFile function, which
852- // forwards the results to the dependency consumer.
853- // It does not indicate the end of processing the fake file.
854- CB->EndOfMainFile ();
855- }
856- }
843+ assert (CB && " Must have PPCallbacks after module loading" );
844+ CB->moduleImport (SourceLocation (), Path, ModResult);
845+ // Note that we are calling the CB's EndOfMainFile function, which
846+ // forwards the results to the dependency consumer.
847+ // It does not indicate the end of processing the fake file.
848+ CB->EndOfMainFile ();
857849
858850 CompilerInvocation ModuleInvocation (*OriginalInvocation);
859851 MDC->applyDiscoveredDependencies (ModuleInvocation);
0 commit comments