Author: rksimon Date: Thu Oct 3 09:58:01 2019 New Revision: 373626 URL: http://llvm.org/viewvc/llvm-project?rev=373626&view=rev Log: DeclBase/DeclCXX/DeclTemplate - silence static analyzer getAs<> null dereference warnings. NFCI.
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. Modified: cfe/trunk/lib/AST/DeclBase.cpp cfe/trunk/lib/AST/DeclCXX.cpp cfe/trunk/lib/AST/DeclTemplate.cpp Modified: cfe/trunk/lib/AST/DeclBase.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=373626&r1=373625&r2=373626&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclBase.cpp (original) +++ cfe/trunk/lib/AST/DeclBase.cpp Thu Oct 3 09:58:01 2019 @@ -959,11 +959,11 @@ const FunctionType *Decl::getFunctionTyp 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>(); } Modified: cfe/trunk/lib/AST/DeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=373626&r1=373625&r2=373626&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclCXX.cpp (original) +++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Oct 3 09:58:01 2019 @@ -2566,7 +2566,7 @@ bool CXXConstructorDecl::isConvertingCon return false; return (getNumParams() == 0 && - getType()->getAs<FunctionProtoType>()->isVariadic()) || + getType()->castAs<FunctionProtoType>()->isVariadic()) || (getNumParams() == 1) || (getNumParams() > 1 && (getParamDecl(1)->hasDefaultArg() || Modified: cfe/trunk/lib/AST/DeclTemplate.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclTemplate.cpp?rev=373626&r1=373625&r2=373626&view=diff ============================================================================== --- cfe/trunk/lib/AST/DeclTemplate.cpp (original) +++ cfe/trunk/lib/AST/DeclTemplate.cpp Thu Oct 3 09:58:01 2019 @@ -519,15 +519,15 @@ SourceRange TemplateTypeParmDecl::getSou } 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(); } //===----------------------------------------------------------------------===// _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits