]> granicus.if.org Git - clang/commitdiff
Enhance dead store checker to not flag preincrements to dead variables where the...
authorTed Kremenek <kremenek@apple.com>
Wed, 15 Oct 2008 05:23:41 +0000 (05:23 +0000)
committerTed Kremenek <kremenek@apple.com>
Wed, 15 Oct 2008 05:23:41 +0000 (05:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57554 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CheckDeadStores.cpp
test/Analysis/dead-stores.c

index d87bfb1964ecd7a31957200f226c3980635b6a1e..2afc7e0235fe8b790338c8c1ef62e5a6f9da17ab 100644 (file)
@@ -149,6 +149,13 @@ public:
     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();
       
index 2a67afd0b0f56c4e3e301a53dafbcb3e092cc784..71c4e3b28bf0e34368c25dd91e859d7abc618abc 100644 (file)
@@ -74,9 +74,15 @@ int f10() {
 
 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;