]> granicus.if.org Git - clang/commitdiff
Silence static analyzer getAs<VectorType> null dereference warnings. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 2 Oct 2019 15:31:25 +0000 (15:31 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 2 Oct 2019 15:31:25 +0000 (15:31 +0000)
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<VectorType> directly and if not assert will fire for us.

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

lib/AST/APValue.cpp
lib/CodeGen/CGAtomic.cpp
lib/CodeGen/CGExprScalar.cpp
lib/Sema/SemaChecking.cpp

index b44ab9837b3547b18f677d539824faf52778c402..f29d6f5554c54d47ce544fbef05189a42b6865ed 100644 (file)
@@ -493,7 +493,7 @@ void APValue::printPretty(raw_ostream &Out, const ASTContext &Ctx,
     return;
   case APValue::Vector: {
     Out << '{';
-    QualType ElemTy = Ty->getAs<VectorType>()->getElementType();
+    QualType ElemTy = Ty->castAs<VectorType>()->getElementType();
     getVectorElt(0).printPretty(Out, Ctx, ElemTy);
     for (unsigned i = 1; i != getVectorLength(); ++i) {
       Out << ", ";
index a95cd12c2d648e555937b2141078c2194fad4821..f9915a1a8f5f07a2ba631559e2900f6cd04c5a4d 100644 (file)
@@ -107,7 +107,7 @@ namespace {
         }
         AtomicAlign = ValueAlign = lvalue.getAlignment();
       } else if (lvalue.isVectorElt()) {
-        ValueTy = lvalue.getType()->getAs<VectorType>()->getElementType();
+        ValueTy = lvalue.getType()->castAs<VectorType>()->getElementType();
         ValueSizeInBits = C.getTypeSize(ValueTy);
         AtomicTy = lvalue.getType();
         AtomicSizeInBits = C.getTypeSize(AtomicTy);
index 77ec54d6cb9dd1b8140ae548de72593f758207e6..4676be40768f5ce8cfde4f808fec2dcfb86749f5 100644 (file)
@@ -1657,8 +1657,8 @@ Value *ScalarExprEmitter::VisitConvertVectorExpr(ConvertVectorExpr *E) {
   if (SrcTy == DstTy)
     return Src;
 
-  QualType SrcEltType = SrcType->getAs<VectorType>()->getElementType(),
-           DstEltType = DstType->getAs<VectorType>()->getElementType();
+  QualType SrcEltType = SrcType->castAs<VectorType>()->getElementType(),
+           DstEltType = DstType->castAs<VectorType>()->getElementType();
 
   assert(SrcTy->isVectorTy() &&
          "ConvertVector source IR type must be a vector");
@@ -3745,7 +3745,7 @@ Value *ScalarExprEmitter::EmitCompare(const BinaryOperator *E,
       Value *FirstVecArg = LHS,
             *SecondVecArg = RHS;
 
-      QualType ElTy = LHSTy->getAs<VectorType>()->getElementType();
+      QualType ElTy = LHSTy->castAs<VectorType>()->getElementType();
       const BuiltinType *BTy = ElTy->getAs<BuiltinType>();
       BuiltinType::Kind ElementKind = BTy->getKind();
 
index 7c37932058ef7760de87145b7600edefcad850e5..f2ab27fedd40326b87b12fae4a2daf6c4d6ca03b 100644 (file)
@@ -5843,7 +5843,7 @@ ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
           << SourceRange(TheCall->getArg(0)->getBeginLoc(),
                          TheCall->getArg(1)->getEndLoc()));
 
-    numElements = LHSType->getAs<VectorType>()->getNumElements();
+    numElements = LHSType->castAs<VectorType>()->getNumElements();
     unsigned numResElements = TheCall->getNumArgs() - 2;
 
     // Check to see if we have a call with 2 vector arguments, the unary shuffle
@@ -5851,7 +5851,7 @@ ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
     // same number of elts as lhs.
     if (TheCall->getNumArgs() == 2) {
       if (!RHSType->hasIntegerRepresentation() ||
-          RHSType->getAs<VectorType>()->getNumElements() != numElements)
+          RHSType->castAs<VectorType>()->getNumElements() != numElements)
         return ExprError(Diag(TheCall->getBeginLoc(),
                               diag::err_vec_builtin_incompatible_vector)
                          << TheCall->getDirectCallee()
@@ -5864,7 +5864,7 @@ ExprResult Sema::SemaBuiltinShuffleVector(CallExpr *TheCall) {
                        << SourceRange(TheCall->getArg(0)->getBeginLoc(),
                                       TheCall->getArg(1)->getEndLoc()));
     } else if (numElements != numResElements) {
-      QualType eltType = LHSType->getAs<VectorType>()->getElementType();
+      QualType eltType = LHSType->castAs<VectorType>()->getElementType();
       resType = Context.getVectorType(eltType, numResElements,
                                       VectorType::GenericVector);
     }
@@ -5921,8 +5921,8 @@ ExprResult Sema::SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
                           diag::err_convertvector_non_vector_type));
 
   if (!SrcTy->isDependentType() && !DstTy->isDependentType()) {
-    unsigned SrcElts = SrcTy->getAs<VectorType>()->getNumElements();
-    unsigned DstElts = DstTy->getAs<VectorType>()->getNumElements();
+    unsigned SrcElts = SrcTy->castAs<VectorType>()->getNumElements();
+    unsigned DstElts = DstTy->castAs<VectorType>()->getNumElements();
     if (SrcElts != DstElts)
       return ExprError(Diag(BuiltinLoc,
                             diag::err_convertvector_incompatible_vector)