Don't use Expr::isIntegerConstantExpr just to check if a pointer value is initialize to NULL.

llvm-svn: 54563
This commit is contained in:
Ted Kremenek 2008-08-09 00:05:14 +00:00
parent 1a02630b63
commit 0216b83d94
1 changed files with 9 additions and 13 deletions

View File

@ -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)) {