r373904 - AST - silence static analyzer getAs<> null dereference warnings. NFCI.
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 06:58:05 PDT 2019
Author: rksimon
Date: Mon Oct 7 06:58:05 2019
New Revision: 373904
URL: http://llvm.org/viewvc/llvm-project?rev=373904&view=rev
Log:
AST - 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/ExprCXX.cpp
cfe/trunk/lib/AST/Interp/Program.cpp
cfe/trunk/lib/AST/Mangle.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/TemplateBase.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=373904&r1=373903&r2=373904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Mon Oct 7 06:58:05 2019
@@ -251,7 +251,7 @@ QualType CXXDeleteExpr::getDestroyedType
if (ArgType->isDependentType() && !ArgType->isPointerType())
return QualType();
- return ArgType->getAs<PointerType>()->getPointeeType();
+ return ArgType->castAs<PointerType>()->getPointeeType();
}
// CXXPseudoDestructorExpr
@@ -1512,11 +1512,8 @@ CXXRecordDecl *UnresolvedMemberExpr::get
// Otherwise the naming class must have been the base class.
else {
QualType BaseType = getBaseType().getNonReferenceType();
- if (isArrow()) {
- const auto *PT = BaseType->getAs<PointerType>();
- assert(PT && "base of arrow member access is not pointer");
- BaseType = PT->getPointeeType();
- }
+ if (isArrow())
+ BaseType = BaseType->castAs<PointerType>()->getPointeeType();
Record = BaseType->getAsCXXRecordDecl();
assert(Record && "base of member expression does not name record");
Modified: cfe/trunk/lib/AST/Interp/Program.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Interp/Program.cpp?rev=373904&r1=373903&r2=373904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Interp/Program.cpp (original)
+++ cfe/trunk/lib/AST/Interp/Program.cpp Mon Oct 7 06:58:05 2019
@@ -123,7 +123,7 @@ llvm::Optional<unsigned> Program::getOrC
auto &ASTCtx = Ctx.getASTContext();
// Create a pointer to an incomplete array of the specified elements.
- QualType ElemTy = PD->getType()->getAs<PointerType>()->getPointeeType();
+ QualType ElemTy = PD->getType()->castAs<PointerType>()->getPointeeType();
QualType Ty = ASTCtx.getIncompleteArrayType(ElemTy, ArrayType::Normal, 0);
// Dedup blocks since they are immutable and pointers cannot be compared.
Modified: cfe/trunk/lib/AST/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Mangle.cpp?rev=373904&r1=373903&r2=373904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Mangle.cpp (original)
+++ cfe/trunk/lib/AST/Mangle.cpp Mon Oct 7 06:58:05 2019
@@ -386,7 +386,7 @@ public:
auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
/*IsCXXMethod=*/true);
- auto CC = MD->getType()->getAs<FunctionProtoType>()->getCallConv();
+ auto CC = MD->getType()->castAs<FunctionProtoType>()->getCallConv();
return CC == DefaultCC;
};
Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=373904&r1=373903&r2=373904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/lib/AST/StmtPrinter.cpp Mon Oct 7 06:58:05 2019
@@ -1102,7 +1102,7 @@ void StmtPrinter::VisitIntegerLiteral(In
OS << Node->getValue().toString(10, isSigned);
// Emit suffixes. Integer literals are always a builtin integer type.
- switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
+ switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
default: llvm_unreachable("Unexpected type for integer literal!");
case BuiltinType::Char_S:
case BuiltinType::Char_U: OS << "i8"; break;
@@ -1123,7 +1123,7 @@ void StmtPrinter::VisitFixedPointLiteral
return;
OS << Node->getValueAsString(/*Radix=*/10);
- switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
+ switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
default: llvm_unreachable("Unexpected type for fixed point literal!");
case BuiltinType::ShortFract: OS << "hr"; break;
case BuiltinType::ShortAccum: OS << "hk"; break;
@@ -1152,7 +1152,7 @@ static void PrintFloatingLiteral(raw_ost
return;
// Emit suffixes. Float literals are always a builtin float type.
- switch (Node->getType()->getAs<BuiltinType>()->getKind()) {
+ switch (Node->getType()->castAs<BuiltinType>()->getKind()) {
default: llvm_unreachable("Unexpected type for float literal!");
case BuiltinType::Half: break; // FIXME: suffix?
case BuiltinType::Double: break; // no suffix.
@@ -1952,7 +1952,7 @@ void StmtPrinter::VisitLambdaExpr(Lambda
if (Node->isMutable())
OS << " mutable";
- auto *Proto = Method->getType()->getAs<FunctionProtoType>();
+ auto *Proto = Method->getType()->castAs<FunctionProtoType>();
Proto->printExceptionSpecification(OS, Policy);
// FIXME: Attributes
Modified: cfe/trunk/lib/AST/TemplateBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TemplateBase.cpp?rev=373904&r1=373903&r2=373904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TemplateBase.cpp (original)
+++ cfe/trunk/lib/AST/TemplateBase.cpp Mon Oct 7 06:58:05 2019
@@ -370,7 +370,7 @@ TemplateArgument TemplateArgument::getPa
switch (getKind()) {
case Type:
- return getAsType()->getAs<PackExpansionType>()->getPattern();
+ return getAsType()->castAs<PackExpansionType>()->getPattern();
case Expression:
return cast<PackExpansionExpr>(getAsExpr())->getPattern();
Modified: cfe/trunk/lib/AST/TypePrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TypePrinter.cpp?rev=373904&r1=373903&r2=373904&view=diff
==============================================================================
--- cfe/trunk/lib/AST/TypePrinter.cpp (original)
+++ cfe/trunk/lib/AST/TypePrinter.cpp Mon Oct 7 06:58:05 2019
@@ -1537,7 +1537,7 @@ void TypePrinter::printAttributedAfter(c
QualType t = T->getEquivalentType();
while (!t->isFunctionType())
t = t->getPointeeType();
- OS << (t->getAs<FunctionType>()->getCallConv() == CC_AAPCS ?
+ OS << (t->castAs<FunctionType>()->getCallConv() == CC_AAPCS ?
"\"aapcs\"" : "\"aapcs-vfp\"");
OS << ')';
break;
More information about the cfe-commits
mailing list