martong created this revision.
martong added reviewers: xazax.hun, a_sidorin, Szelethus, balazske.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, rnkovacs.

In loadExternalAST we normally return with either an error or with a valid
ASTUnit pointer which should not be a nullptr.
However, in the call site we did a superfluous check for being a nullptr.


Repository:
  rC Clang

https://reviews.llvm.org/D55280

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


Index: lib/CrossTU/CrossTranslationUnit.cpp
===================================================================
--- lib/CrossTU/CrossTranslationUnit.cpp
+++ lib/CrossTU/CrossTranslationUnit.cpp
@@ -51,8 +51,6 @@
       return "Missing definition from the index file.";
     case index_error_code::failed_import:
       return "Failed to import the definition.";
-    case index_error_code::failed_to_get_external_ast:
-      return "Failed to load external AST source.";
     case index_error_code::failed_to_generate_usr:
       return "Failed to generate USR.";
     }
@@ -160,9 +158,6 @@
   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());
 
@@ -240,6 +235,7 @@
   } else {
     Unit = FnUnitCacheEntry->second;
   }
+  assert(Unit);
   return Unit;
 }
 
Index: include/clang/CrossTU/CrossTranslationUnit.h
===================================================================
--- include/clang/CrossTU/CrossTranslationUnit.h
+++ include/clang/CrossTU/CrossTranslationUnit.h
@@ -40,7 +40,6 @@
   multiple_definitions,
   missing_definition,
   failed_import,
-  failed_to_get_external_ast,
   failed_to_generate_usr
 };
 
@@ -118,8 +117,8 @@
   /// \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. The pointer should not be a nullptr.
   ///
   /// Note that the AST files should also be in the \p CrossTUDir.
   llvm::Expected<ASTUnit *> loadExternalAST(StringRef LookupName,


Index: lib/CrossTU/CrossTranslationUnit.cpp
===================================================================
--- lib/CrossTU/CrossTranslationUnit.cpp
+++ lib/CrossTU/CrossTranslationUnit.cpp
@@ -51,8 +51,6 @@
       return "Missing definition from the index file.";
     case index_error_code::failed_import:
       return "Failed to import the definition.";
-    case index_error_code::failed_to_get_external_ast:
-      return "Failed to load external AST source.";
     case index_error_code::failed_to_generate_usr:
       return "Failed to generate USR.";
     }
@@ -160,9 +158,6 @@
   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());
 
@@ -240,6 +235,7 @@
   } else {
     Unit = FnUnitCacheEntry->second;
   }
+  assert(Unit);
   return Unit;
 }
 
Index: include/clang/CrossTU/CrossTranslationUnit.h
===================================================================
--- include/clang/CrossTU/CrossTranslationUnit.h
+++ include/clang/CrossTU/CrossTranslationUnit.h
@@ -40,7 +40,6 @@
   multiple_definitions,
   missing_definition,
   failed_import,
-  failed_to_get_external_ast,
   failed_to_generate_usr
 };
 
@@ -118,8 +117,8 @@
   /// \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. The pointer should not be a nullptr.
   ///
   /// Note that the AST files should also be in the \p CrossTUDir.
   llvm::Expected<ASTUnit *> loadExternalAST(StringRef LookupName,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to