Index: include/clang/CrossTU/CrossTranslationUnit.h =================================================================== --- include/clang/CrossTU/CrossTranslationUnit.h +++ include/clang/CrossTU/CrossTranslationUnit.h @@ -130,8 +130,9 @@ /// \p IndexName. In case the declaration is found in the index the /// corresponding AST file will be loaded. /// - /// \return Returns an ASTUnit that contains the definition of the looked up - /// function. + /// \return Returns a pointer to the ASTUnit that contains the definition of + /// the looked up function or an Error. + /// The returned pointer is never a nullptr. /// /// Note that the AST files should also be in the \p CrossTUDir. llvm::Expected loadExternalAST(StringRef LookupName, Index: lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- lib/CrossTU/CrossTranslationUnit.cpp +++ lib/CrossTU/CrossTranslationUnit.cpp @@ -208,9 +208,6 @@ if (!ASTUnitOrError) return ASTUnitOrError.takeError(); ASTUnit *Unit = *ASTUnitOrError; - if (!Unit) - return llvm::make_error( - index_error_code::failed_to_get_external_ast); assert(&Unit->getFileManager() == &Unit->getASTContext().getSourceManager().getFileManager()); @@ -324,6 +321,9 @@ } else { Unit = FnUnitCacheEntry->second; } + if (!Unit) + return llvm::make_error( + index_error_code::failed_to_get_external_ast); return Unit; }