[cfe-commits] r90364 - in /cfe/trunk: lib/Analysis/CheckDeadStores.cpp test/Analysis/dead-stores.c
Ted Kremenek
kremenek at apple.com
Wed Dec 2 16:46:16 PST 2009
Author: kremenek
Date: Wed Dec 2 18:46:16 2009
New Revision: 90364
URL: http://llvm.org/viewvc/llvm-project?rev=90364&view=rev
Log:
Add a heuristic to the dead stores checker to prune dead stores for variables annotated with '__block'. This is overly conservative, but now the analyzer doesn't report dead stores for variables that can be updated by a block call.
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=90364&r1=90363&r2=90364&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Wed Dec 2 18:46:16 2009
@@ -84,7 +84,8 @@
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());
}
Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=90364&r1=90363&r2=90364&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Wed Dec 2 18:46:16 2009
@@ -406,3 +406,24 @@
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;
+}
+
More information about the cfe-commits
mailing list