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

Ted Kremenek kremenek at apple.com
Tue Oct 14 22:23:41 PDT 2008


Author: kremenek
Date: Wed Oct 15 00:23:41 2008
New Revision: 57554

URL: http://llvm.org/viewvc/llvm-project?rev=57554&view=rev
Log:
Enhance dead store checker to not flag preincrements to dead variables where the preincrement is a subexpression, e.g. foo(++x);  This can cause false negatives, but will remove a whole class of false positives.

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

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

==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Wed Oct 15 00:23:41 2008
@@ -149,6 +149,13 @@
     else if (UnaryOperator* U = dyn_cast<UnaryOperator>(S)) {
       if (!U->isIncrementOp())
         return;
+      
+      // Handle: ++x within a subexpression.  The solution is not warn
+      //  about preincrements to dead variables when the preincrement occurs
+      //  as a subexpression.  This can lead to false negatives, e.g. "(++x);"
+      //  A generalized dead code checker should find such issues.
+      if (U->isPrefix() && Parents.isSubExpr(U))
+        return;
 
       Expr *Ex = U->getSubExpr()->IgnoreParenCasts();
       

Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=57554&r1=57553&r2=57554&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Wed Oct 15 00:23:41 2008
@@ -74,9 +74,15 @@
 
 int f11() {
   int x = 4;
-  return ++x; // expected-warning{{never read}}
+  return x++; // expected-warning{{never read}}
 }
 
+int f11b() {
+  int x = 4;
+  return ++x; // no-warning
+}
+
+
 int f12a(int y) {
   int x = y;  // expected-warning{{never read}}
   return 1;





More information about the cfe-commits mailing list