[clang] ce2b36e - [clang] CheckSizelessVectorOperands - use castAs<> instead of getAs<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 25 03:23:40 PDT 2022


Author: Simon Pilgrim
Date: 2022-03-25T10:23:30Z
New Revision: ce2b36e123e7b5312016b09c1b2971c9d80416e7

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

LOG: [clang] CheckSizelessVectorOperands - use castAs<> instead of getAs<> to avoid dereference of nullptr

Move the only uses of the cast to where they are dereferenced.

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index ae48db03e06c9..1547a34b5c730 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10490,12 +10490,10 @@ QualType Sema::CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
   QualType LHSType = LHS.get()->getType().getUnqualifiedType();
   QualType RHSType = RHS.get()->getType().getUnqualifiedType();
 
-  const BuiltinType *LHSVecType = LHSType->getAs<BuiltinType>();
-  const BuiltinType *RHSVecType = RHSType->getAs<BuiltinType>();
-
   unsigned DiagID = diag::err_typecheck_invalid_operands;
   if ((OperationKind == ACK_Arithmetic) &&
-      (LHSVecType->isSVEBool() || RHSVecType->isSVEBool())) {
+      (LHSType->castAs<BuiltinType>()->isSVEBool() ||
+       RHSType->castAs<BuiltinType>()->isSVEBool())) {
     Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange()
                       << RHS.get()->getSourceRange();
     return QualType();


        


More information about the cfe-commits mailing list