]> granicus.if.org Git - clang/commitdiff
[CTU] Make loadExternalAST return with non nullptr on success
authorGabor Marton <martongabesz@gmail.com>
Mon, 7 Jan 2019 14:05:19 +0000 (14:05 +0000)
committerGabor Marton <martongabesz@gmail.com>
Mon, 7 Jan 2019 14:05:19 +0000 (14:05 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@350521 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/CrossTU/CrossTranslationUnit.h
lib/CrossTU/CrossTranslationUnit.cpp

index a5cec7e05eed5af848fc03821b7caa30a5696815..9b36fe653b2e24914c02d09798672e81fe005a8d 100644 (file)
@@ -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,
index 6ee329c2b54c30f4f26d12e879029225dcc6b9ad..915b5246c9e0b7b1f24d006d1b9947ebc9774273 100644 (file)
@@ -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;
 }