]> granicus.if.org Git - clang/commitdiff
Add a heuristic to the dead stores checker to prune dead stores for variables annotat...
authorTed Kremenek <kremenek@apple.com>
Thu, 3 Dec 2009 00:46:16 +0000 (00:46 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 3 Dec 2009 00:46:16 +0000 (00:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90364 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ad63eb4122b09e7760eb3283b1ef533f3f954a10..ec13328447a6acf8485cc5106e719a7c3e1822cd 100644 (file)
@@ -84,7 +84,8 @@ public:
                     const LiveVariables::AnalysisDataTy& AD,
                     const LiveVariables::ValTy& Live) {
 
-    if (VD->hasLocalStorage() && !Live(VD, AD) && !VD->getAttr<UnusedAttr>())
+    if (VD->hasLocalStorage() && !Live(VD, AD) && 
+        !(VD->getAttr<UnusedAttr>() || VD->getAttr<BlocksAttr>()))
       Report(VD, dsk, Ex->getSourceRange().getBegin(),
              Val->getSourceRange());
   }
index ae5e3e36735409f31b72b7c81841609549e2b69c..7cf8c31cd2234c138dcebc43511bffe15653f400 100644 (file)
@@ -406,3 +406,24 @@ int f24_D(int y) {
   return x;
 }
 
+// This example shows that writing to a variable captured by a block means that it might
+// not be dead.
+int f25(int y) {
+  __block int x = (y > 2);
+  __block int z = 0;
+  void (^foo)() = ^{ z = x + y; };
+  x = 4; // no-warning
+  foo();
+  return z; 
+}
+
+// This test is mostly the same as 'f25', but shows that the heuristic of pruning out dead
+// stores for variables that are just marked '__block' is overly conservative.
+int f25_b(int y) {
+  // FIXME: we should eventually report a dead store here.
+  __block int x = (y > 2);
+  __block int z = 0;
+  x = 4; // no-warning
+  return z; 
+}
+