diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-08-09 00:05:14 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-08-09 00:05:14 +0000 |
commit | e12691c2a2109016df12b2cbf54d51a921e6b618 (patch) | |
tree | 30809e7b7f522e0a521ea0132de26ff85634f820 /lib/Analysis/CheckDeadStores.cpp | |
parent | 9a993d9c30e8a260cd64c7f3387ca73befdeee00 (diff) |
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
Diffstat (limited to 'lib/Analysis/CheckDeadStores.cpp')
-rw-r--r-- | lib/Analysis/CheckDeadStores.cpp | 22 |
1 files 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<DeclRefExpr>(B->getLHS())) if (VarDecl *VD = dyn_cast<VarDecl>(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<IntegerLiteral>(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<UnaryOperator>(S)) { |