summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabor Marton <martongabesz@gmail.com>2019-01-07 14:05:19 +0000
committerGabor Marton <martongabesz@gmail.com>2019-01-07 14:05:19 +0000
commit3081690c84a185ed308013dc421e4e44cfd20c78 (patch)
tree0565e6c1ac18fc36539b4c832cee7b258cfcf6c7
parent90f4b94da3bc48c6645fa15d8060f72d9a443449 (diff)
downloadbcm5719-llvm-3081690c84a185ed308013dc421e4e44cfd20c78.tar.gz
bcm5719-llvm-3081690c84a185ed308013dc421e4e44cfd20c78.zip
[CTU] Make loadExternalAST return with non nullptr on success
Summary: In loadExternalAST we return with either an error or with a valid ASTUnit pointer which should not be a nullptr. This prevents in the call site any superfluous check for being a nullptr. Reviewers: xazax.hun, a_sidorin, Szelethus, balazske Subscribers: rnkovacs, dkrupp, gamesh411, cfe-commits Differential Revision: https://reviews.llvm.org/D55280 llvm-svn: 350521
-rw-r--r--clang/include/clang/CrossTU/CrossTranslationUnit.h5
-rw-r--r--clang/lib/CrossTU/CrossTranslationUnit.cpp6
2 files changed, 6 insertions, 5 deletions
diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index a5cec7e05ee..9b36fe653b2 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -130,8 +130,9 @@ public:
/// \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<ASTUnit *> loadExternalAST(StringRef LookupName,
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index 6ee329c2b54..915b5246c9e 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -208,9 +208,6 @@ CrossTranslationUnitContext::getCrossTUDefinition(const FunctionDecl *FD,
if (!ASTUnitOrError)
return ASTUnitOrError.takeError();
ASTUnit *Unit = *ASTUnitOrError;
- if (!Unit)
- return llvm::make_error<IndexError>(
- index_error_code::failed_to_get_external_ast);
assert(&Unit->getFileManager() ==
&Unit->getASTContext().getSourceManager().getFileManager());
@@ -324,6 +321,9 @@ llvm::Expected<ASTUnit *> CrossTranslationUnitContext::loadExternalAST(
} else {
Unit = FnUnitCacheEntry->second;
}
+ if (!Unit)
+ return llvm::make_error<IndexError>(
+ index_error_code::failed_to_get_external_ast);
return Unit;
}
OpenPOWER on IntegriCloud