aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-10-15 05:23:41 +0000
committerTed Kremenek <kremenek@apple.com>2008-10-15 05:23:41 +0000
commit380277e46ec1d2d9abedcddf357ceea935cbe576 (patch)
tree3dce376ff58cb800880d8d589b1923917f8fb7ca
parent35bc0821c4f80041724cd4c5c4889b2581546a41 (diff)
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57554 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/CheckDeadStores.cpp7
-rw-r--r--test/Analysis/dead-stores.c8
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp
index d87bfb1964..2afc7e0235 100644
--- a/lib/Analysis/CheckDeadStores.cpp
+++ b/lib/Analysis/CheckDeadStores.cpp
@@ -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();
diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c
index 2a67afd0b0..71c4e3b28b 100644
--- a/test/Analysis/dead-stores.c
+++ b/test/Analysis/dead-stores.c
@@ -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;