]> granicus.if.org Git - clang/commitdiff
DeclBase/DeclCXX/DeclTemplate - silence static analyzer getAs<> null dereference...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 3 Oct 2019 16:58:01 +0000 (16:58 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 3 Oct 2019 16:58:01 +0000 (16:58 +0000)
The static analyzer is warning about potential null dereferences, but in these cases we should be able to use castAs<> directly and if not assert will fire for us.

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

lib/AST/DeclBase.cpp
lib/AST/DeclCXX.cpp
lib/AST/DeclTemplate.cpp

index 10537efebfc76e54db4d5291db3aeeeb17fee56e..77a3a4c679a1a5ea7db4ded42c8a20c5c1bccdb7 100644 (file)
@@ -959,11 +959,11 @@ const FunctionType *Decl::getFunctionType(bool BlocksToo) const {
     return nullptr;
 
   if (Ty->isFunctionPointerType())
-    Ty = Ty->getAs<PointerType>()->getPointeeType();
+    Ty = Ty->castAs<PointerType>()->getPointeeType();
   else if (Ty->isFunctionReferenceType())
-    Ty = Ty->getAs<ReferenceType>()->getPointeeType();
+    Ty = Ty->castAs<ReferenceType>()->getPointeeType();
   else if (BlocksToo && Ty->isBlockPointerType())
-    Ty = Ty->getAs<BlockPointerType>()->getPointeeType();
+    Ty = Ty->castAs<BlockPointerType>()->getPointeeType();
 
   return Ty->getAs<FunctionType>();
 }
index 3602f1189e97be558b1c35385a2aa5c83dddb4d4..a085941e68c5945c44528293c9056b559e437a07 100644 (file)
@@ -2566,7 +2566,7 @@ bool CXXConstructorDecl::isConvertingConstructor(bool AllowExplicit) const {
     return false;
 
   return (getNumParams() == 0 &&
-          getType()->getAs<FunctionProtoType>()->isVariadic()) ||
+          getType()->castAs<FunctionProtoType>()->isVariadic()) ||
          (getNumParams() == 1) ||
          (getNumParams() > 1 &&
           (getParamDecl(1)->hasDefaultArg() ||
index c03ae22fb5d89d0e2c7eddfaee12018c06d9ddc9..ccfc292e4c6cd3e063a8813ff369102e06bfc0c9 100644 (file)
@@ -519,15 +519,15 @@ SourceRange TemplateTypeParmDecl::getSourceRange() const {
 }
 
 unsigned TemplateTypeParmDecl::getDepth() const {
-  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getDepth();
+  return getTypeForDecl()->castAs<TemplateTypeParmType>()->getDepth();
 }
 
 unsigned TemplateTypeParmDecl::getIndex() const {
-  return getTypeForDecl()->getAs<TemplateTypeParmType>()->getIndex();
+  return getTypeForDecl()->castAs<TemplateTypeParmType>()->getIndex();
 }
 
 bool TemplateTypeParmDecl::isParameterPack() const {
-  return getTypeForDecl()->getAs<TemplateTypeParmType>()->isParameterPack();
+  return getTypeForDecl()->castAs<TemplateTypeParmType>()->isParameterPack();
 }
 
 //===----------------------------------------------------------------------===//