[clang] e3e8799 - [AST] ASTContext::mergeTypes - pull out repeated getAs<> calls. NFC.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 6 08:05:07 PST 2022


Author: Simon Pilgrim
Date: 2022-01-06T16:04:36Z
New Revision: e3e8799bebd0e624de21b9e93e358b9396bf4ace

URL: https://github.com/llvm/llvm-project/commit/e3e8799bebd0e624de21b9e93e358b9396bf4ace
DIFF: https://github.com/llvm/llvm-project/commit/e3e8799bebd0e624de21b9e93e358b9396bf4ace.diff

LOG: [AST] ASTContext::mergeTypes - pull out repeated getAs<> calls. NFC.

Avoids static-analyzer null dereference warnings.

Added: 
    

Modified: 
    clang/lib/AST/ASTContext.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ac6f98e91f755..3ecbdc1eb77b0 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -9819,12 +9819,13 @@ QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,
   // designates the object or function denoted by the reference, and the
   // expression is an lvalue unless the reference is an rvalue reference and
   // the expression is a function call (possibly inside parentheses).
-  if (LangOpts.OpenMP && LHS->getAs<ReferenceType>() &&
-      RHS->getAs<ReferenceType>() && LHS->getTypeClass() == RHS->getTypeClass())
-    return mergeTypes(LHS->getAs<ReferenceType>()->getPointeeType(),
-                      RHS->getAs<ReferenceType>()->getPointeeType(),
+  auto *LHSRefTy = LHS->getAs<ReferenceType>();
+  auto *RHSRefTy = RHS->getAs<ReferenceType>();
+  if (LangOpts.OpenMP && LHSRefTy && RHSRefTy &&
+      LHS->getTypeClass() == RHS->getTypeClass())
+    return mergeTypes(LHSRefTy->getPointeeType(), RHSRefTy->getPointeeType(),
                       OfBlockPointer, Unqualified, BlockReturnType);
-  if (LHS->getAs<ReferenceType>() || RHS->getAs<ReferenceType>())
+  if (LHSRefTy || RHSRefTy)
     return {};
 
   if (Unqualified) {


        


More information about the cfe-commits mailing list