[cfe-commits] r54563 - /cfe/trunk/lib/Analysis/CheckDeadStores.cpp

Ted Kremenek kremenek at apple.com
Fri Aug 8 17:05:14 PDT 2008


Author: kremenek
Date: Fri Aug  8 19:05:14 2008
New Revision: 54563

URL: http://llvm.org/viewvc/llvm-project?rev=54563&view=rev
Log:
Don't use Expr::isIntegerConstantExpr just to check if a pointer value is initialize to NULL.

Modified:
    cfe/trunk/lib/Analysis/CheckDeadStores.cpp

Modified: cfe/trunk/lib/Analysis/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckDeadStores.cpp?rev=54563&r1=54562&r2=54563&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Fri Aug  8 19:05:14 2008
@@ -128,25 +128,21 @@
       
       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)) {





More information about the cfe-commits mailing list