diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp @@ -84,33 +84,18 @@ PrebuiltModuleFilesT &ModuleFiles, llvm::StringSet<> &InputFiles, bool VisitInputFiles) { - // Maps the names of modules that weren't yet visited to their PCM path. - llvm::StringMap ModuleFilesWorklist; - // Contains PCM paths of all visited modules. - llvm::StringSet<> VisitedModuleFiles; - - PrebuiltModuleListener Listener(ModuleFilesWorklist, InputFiles, - VisitInputFiles); - - auto GatherModuleFileInfo = [&](StringRef ASTFile) { - ASTReader::readASTFileControlBlock( - ASTFile, CI.getFileManager(), CI.getPCHContainerReader(), - /*FindModuleFileExtensions=*/false, Listener, - /*ValidateDiagnosticOptions=*/false); - }; - - GatherModuleFileInfo(PrebuiltModuleFilename); - while (!ModuleFilesWorklist.empty()) { - auto WorklistItemIt = ModuleFilesWorklist.begin(); - - if (!VisitedModuleFiles.contains(WorklistItemIt->getValue())) { - VisitedModuleFiles.insert(WorklistItemIt->getValue()); - GatherModuleFileInfo(WorklistItemIt->getValue()); - ModuleFiles[WorklistItemIt->getKey().str()] = WorklistItemIt->getValue(); - } - - ModuleFilesWorklist.erase(WorklistItemIt); - } + // Maps the names of imported modules to their PCM paths. + llvm::StringMap Imports; + PrebuiltModuleListener Listener(Imports, InputFiles, VisitInputFiles); + ASTReader::readASTFileControlBlock( + PrebuiltModuleFilename, CI.getFileManager(), CI.getPCHContainerReader(), + /*FindModuleFileExtensions=*/false, Listener, + /*ValidateDiagnosticOptions=*/false); + + for (const auto &Import : Imports) + if (ModuleFiles.insert({Import.getKey().str(), Import.getValue()}).second) + visitPrebuiltModule(Import.getValue(), CI, ModuleFiles, InputFiles, + VisitInputFiles); } /// Transform arbitrary file name into an object-like file name.