diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h --- a/clang/include/clang/CrossTU/CrossTranslationUnit.h +++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h @@ -167,6 +167,9 @@ llvm::Error lazyInitCTUIndex(StringRef CrossTUDir, StringRef IndexName); ASTUnit *getCachedASTUnitForName(StringRef LookupName) const; std::unique_ptr loadFromASTFile(StringRef ASTFileName) const; + llvm::Expected + getASTFileNameForLookup(StringRef LookupName) const; + void lazyInitImporterSharedSt(TranslationUnitDecl *ToTU); ASTImporter &getOrCreateASTImporter(ASTContext &From); template diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp --- a/clang/lib/CrossTU/CrossTranslationUnit.cpp +++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -395,6 +395,18 @@ ASTUnit::LoadEverything, Diags, CI.getFileSystemOpts()); } +llvm::Expected +CrossTranslationUnitContext::getASTFileNameForLookup( + StringRef LookupName) const { + auto NameFileMapEntry = NameFileMap.find(LookupName); + if (NameFileMapEntry != NameFileMap.end()) { + return NameFileMapEntry->second; + } else { + ++NumNotInOtherTU; + return llvm::make_error(index_error_code::missing_definition); + } +} + llvm::Expected CrossTranslationUnitContext::loadExternalAST( StringRef LookupName, StringRef CrossTUDir, StringRef IndexName, bool DisplayCTUProgress) { @@ -418,21 +430,19 @@ if (llvm::Error InitFailed = lazyInitCTUIndex(CrossTUDir, IndexName)) return std::move(InitFailed); - auto It = NameFileMap.find(LookupName); - if (It == NameFileMap.end()) { - ++NumNotInOtherTU; - return llvm::make_error(index_error_code::missing_definition); - } - StringRef ASTFileName = It->second; - auto ASTCacheEntry = FileASTUnitMap.find(ASTFileName); + llvm::Expected ASTFileName = getASTFileNameForLookup(LookupName); + if (!ASTFileName) + return ASTFileName.takeError(); + + auto ASTCacheEntry = FileASTUnitMap.find(*ASTFileName); if (ASTCacheEntry == FileASTUnitMap.end()) { // Load the ASTUnit from the pre-dumped AST file specified by ASTFileName. - std::unique_ptr LoadedUnit = loadFromASTFile(ASTFileName); + std::unique_ptr LoadedUnit = loadFromASTFile(*ASTFileName); Unit = LoadedUnit.get(); - FileASTUnitMap[ASTFileName] = std::move(LoadedUnit); + FileASTUnitMap[*ASTFileName] = std::move(LoadedUnit); ++NumASTLoaded; if (DisplayCTUProgress) { - llvm::errs() << "CTU loaded AST file: " << ASTFileName << "\n"; + llvm::errs() << "CTU loaded AST file: " << *ASTFileName << "\n"; } } else { Unit = ASTCacheEntry->second.get();