Hey,

This patch changes CheckDeadStores to use Expr::isNullPointerConstant,
which will correctly determine whether an expression is a null pointer
constant.

-- 
Best regards,
Kovarththanan Rajaratnam
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp
index d5cb7ca..dd70ed7 100644
--- a/lib/Analysis/CheckDeadStores.cpp
+++ b/lib/Analysis/CheckDeadStores.cpp
@@ -134,16 +134,15 @@ public:
 
       if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(B->getLHS()))
         if (VarDecl *VD = dyn_cast<VarDecl>(DR->getDecl())) {
-          Expr* RHS = B->getRHS()->IgnoreParenCasts();
-
           // 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>(RHS))
-              // FIXME: Probably should have an Expr::isNullPointerConstant.
-              if (L->getValue() == 0)
-                return;
+            if (B->getRHS()->isNullPointerConstant(Ctx,
+                                              Expr::NPC_ValueDependentIsNull))
+              return;
           }
+
+          Expr* RHS = B->getRHS()->IgnoreParenCasts();
           // Special case: self-assignments.  These are often used to shut up
           //  "unused variable" compiler warnings.
           if (DeclRefExpr* RhsDR = dyn_cast<DeclRefExpr>(RHS))
diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c
index 811ac81..f684133 100644
--- a/test/Analysis/dead-stores.c
+++ b/test/Analysis/dead-stores.c
@@ -55,6 +55,24 @@ int f7(int *p) {
   return 1;
 }
 
+int f7b(int *p) {  
+  // This is allowed for defensive programming.
+  p = (0); // no-warning  
+  return 1;
+}
+
+int f7c(int *p) {  
+  // This is allowed for defensive programming.
+  p = (void*) 0; // no-warning  
+  return 1;
+}
+
+int f7d(int *p) {  
+  // This is allowed for defensive programming.
+  p = (void*) (0); // no-warning  
+  return 1;
+}
+
 int f8(int *p) {
   extern int *baz();
   if ((p = baz())) // expected-warning{{Although the value}}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to