]> granicus.if.org Git - clang/commitdiff
Don't use Expr::isIntegerConstantExpr just to check if a pointer value is initialize...
authorTed Kremenek <kremenek@apple.com>
Sat, 9 Aug 2008 00:05:14 +0000 (00:05 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 9 Aug 2008 00:05:14 +0000 (00:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54563 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CheckDeadStores.cpp

index 63de9adb8fc5cb3bd4a51b96dc9550f221c16cd0..9d9e68d2ef81c5ef4f9b8fb74db03f2a7fc1ab09 100644 (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)) {