[cfe-commits] r123394 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp test/Analysis/dead-stores.c

Ted Kremenek kremenek at apple.com
Thu Jan 13 12:58:56 PST 2011


Author: kremenek
Date: Thu Jan 13 14:58:56 2011
New Revision: 123394

URL: http://llvm.org/viewvc/llvm-project?rev=123394&view=rev
Log:
Remove warning in dead stores checker for
dead stores within nested assignments.  I have
never seen an actual bug found by this specific
warning, and it can lead to many false positives.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp
    cfe/trunk/test/Analysis/dead-stores.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp?rev=123394&r1=123393&r2=123394&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp Thu Jan 13 14:58:56 2011
@@ -1,4 +1,4 @@
-//==- DeadStores.cpp - Check for stores to dead variables --------*- C++ -*-==//
+//==- DeadStoresChecker.cpp - Check for stores to dead variables -*- C++ -*-==//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -70,11 +70,10 @@
         break;
 
       case Enclosing:
-        BugType = "Dead nested assignment";
-        msg = "Although the value stored to '" + name +
-          "' is used in the enclosing expression, the value is never actually"
-          " read from '" + name + "'";
-        break;
+        // Don't report issues in this case, e.g.: "if (x = foo())",
+        // where 'x' is unused later.  We have yet to see a case where 
+        // this is a real bug.
+        return;
     }
 
     BR.EmitBasicReport(BugType, "Dead store", msg, L, R);

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=123394&r1=123393&r2=123394&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Thu Jan 13 14:58:56 2011
@@ -75,9 +75,11 @@
   return 1;
 }
 
+// Don't warn for dead stores in nested expressions.  We have yet
+// to see a real bug in this scenario.
 int f8(int *p) {
   extern int *baz();
-  if ((p = baz())) // expected-warning{{Although the value}}
+  if ((p = baz())) // no-warning
     return 1;
   return 0;
 }
@@ -148,9 +150,11 @@
   int z[count]; // expected-warning{{unused variable 'z'}}
 }
 
+// Don't warn for dead stores in nested expressions.  We have yet
+// to see a real bug in this scenario.
 int f16(int x) {
   x = x * 2;
-  x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{Although the value stored to 'x' is used}} expected-warning{{The left operand to '*' is always 1}} expected-warning{{The left operand to '+' is always 0}}
+  x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{The left operand to '+' is always 0}} expected-warning{{The left operand to '*' is always 1}}
       ? 5 : 8;
   return x;
 }
@@ -175,7 +179,9 @@
       x = 10;   // expected-warning{{Value stored to 'x' is never read}}
    while (1);
 
-   return (x = 10); // expected-warning{{Although the value stored to 'x' is used in the enclosing expression, the value is never actually read from 'x'}}
+   // Don't warn for dead stores in nested expressions.  We have yet
+   // to see a real bug in this scenario.
+   return (x = 10); // no-warning
 }
 
 // PR 3514: false positive `dead initialization` warning for init to global





More information about the cfe-commits mailing list