From e12691c2a2109016df12b2cbf54d51a921e6b618 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sat, 9 Aug 2008 00:05:14 +0000 Subject: [PATCH] Don't use Expr::isIntegerConstantExpr just to check if a pointer value is initialize to NULL. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54563 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CheckDeadStores.cpp | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index 63de9adb8f..9d9e68d2ef 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/lib/Analysis/CheckDeadStores.cpp @@ -128,25 +128,21 @@ public: if (DeclRefExpr* DR = dyn_cast(B->getLHS())) if (VarDecl *VD = dyn_cast(DR->getDecl())) { - - // Special case: check for assigning null to a pointer. This - // is a common form of defensive programming. - // FIXME: Make this optional? - - Expr* Val = B->getRHS(); - llvm::APSInt Result(Ctx.getTypeSize(Val->getType())); - - if (VD->getType()->isPointerType() && - Val->IgnoreParenCasts()->isIntegerConstantExpr(Result, Ctx, 0)) - if (Result == 0) - return; + // Special case: check for assigning null to a pointer. + // This is a common form of defensive programming. + if (VD->getType()->isPointerType()) { + if (IntegerLiteral* L = + dyn_cast(B->getRHS()->IgnoreParenCasts())) + if (L->getValue() == 0) + return; + } DeadStoreKind dsk = Parents.isSubExpr(B) ? Enclosing : (isIncrement(VD,B) ? DeadIncrement : Standard); - CheckVarDecl(VD, DR, Val, dsk, AD, Live); + CheckVarDecl(VD, DR, B->getRHS(), dsk, AD, Live); } } else if (UnaryOperator* U = dyn_cast(S)) { -- 2.50.1