Skip to content

Commit

Permalink
ExprConstant - silence static analyzer getAs<> null dereference warni…
Browse files Browse the repository at this point in the history
…ngs. 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@373612 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
RKSimon committed Oct 3, 2019
1 parent 4d78de1 commit 01df4c0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6435,9 +6435,8 @@ class BufferToAPValueConverter {
QualType RepresentationType = Ty->getDecl()->getIntegerType();
assert(!RepresentationType.isNull() &&
"enum forward decl should be caught by Sema");
const BuiltinType *AsBuiltin =
RepresentationType.getCanonicalType()->getAs<BuiltinType>();
assert(AsBuiltin && "non-integral enum underlying type?");
const auto *AsBuiltin =
RepresentationType.getCanonicalType()->castAs<BuiltinType>();
// Recurse into the underlying type. Treat std::byte transparently as
// unsigned char.
return visit(AsBuiltin, Offset, /*EnumTy=*/Ty);
Expand Down Expand Up @@ -9360,7 +9359,7 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) {

bool
VectorExprEvaluator::ZeroInitialization(const Expr *E) {
const VectorType *VT = E->getType()->getAs<VectorType>();
const auto *VT = E->getType()->castAs<VectorType>();
QualType EltTy = VT->getElementType();
APValue ZeroElement;
if (EltTy->isIntegerType())
Expand Down Expand Up @@ -11836,7 +11835,7 @@ bool IntExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
Info.CCEDiag(E, diag::note_constexpr_pointer_subtraction_not_same_array);

QualType Type = E->getLHS()->getType();
QualType ElementType = Type->getAs<PointerType>()->getPointeeType();
QualType ElementType = Type->castAs<PointerType>()->getPointeeType();

CharUnits ElementSize;
if (!HandleSizeof(Info, E->getExprLoc(), ElementType, ElementSize))
Expand Down Expand Up @@ -12733,9 +12732,9 @@ bool ComplexExprEvaluator::VisitCastExpr(const CastExpr *E) {
if (!Visit(E->getSubExpr()))
return false;

QualType To = E->getType()->getAs<ComplexType>()->getElementType();
QualType To = E->getType()->castAs<ComplexType>()->getElementType();
QualType From
= E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType();
= E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType();

return HandleFloatToFloatCast(Info, E, From, To, Result.FloatReal) &&
HandleFloatToFloatCast(Info, E, From, To, Result.FloatImag);
Expand All @@ -12745,9 +12744,9 @@ bool ComplexExprEvaluator::VisitCastExpr(const CastExpr *E) {
if (!Visit(E->getSubExpr()))
return false;

QualType To = E->getType()->getAs<ComplexType>()->getElementType();
QualType To = E->getType()->castAs<ComplexType>()->getElementType();
QualType From
= E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType();
= E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType();
Result.makeComplexInt();
return HandleFloatToIntCast(Info, E, From, Result.FloatReal,
To, Result.IntReal) &&
Expand All @@ -12769,9 +12768,9 @@ bool ComplexExprEvaluator::VisitCastExpr(const CastExpr *E) {
if (!Visit(E->getSubExpr()))
return false;

QualType To = E->getType()->getAs<ComplexType>()->getElementType();
QualType To = E->getType()->castAs<ComplexType>()->getElementType();
QualType From
= E->getSubExpr()->getType()->getAs<ComplexType>()->getElementType();
= E->getSubExpr()->getType()->castAs<ComplexType>()->getElementType();

Result.IntReal = HandleIntToIntCast(Info, E, To, From, Result.IntReal);
Result.IntImag = HandleIntToIntCast(Info, E, To, From, Result.IntImag);
Expand Down

0 comments on commit 01df4c0

Please sign in to comment.