Skip to content

Commit

Permalink
DeclBase/DeclCXX/DeclTemplate - silence static analyzer getAs<> null …
Browse files Browse the repository at this point in the history
…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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373626 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
RKSimon committed Oct 3, 2019
1 parent 2734b15 commit f294fc0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/AST/DeclBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/DeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ||
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/DeclTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit f294fc0

Please sign in to comment.