diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-01-13 20:58:56 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-01-13 20:58:56 +0000 |
commit | 56b1f71156db11b9c8234ca621c29213a73218e0 (patch) | |
tree | 9fc3973b62a289fb34d90a8439ee441bf5b63d21 | |
parent | ec8051276e5ba5eb3f8dcb0ebb96e17495cbc2bf (diff) |
Remove warning in dead stores checker for
dead stores within nested assignments. I have
never seen an actual bug found by this specific
warning, and it can lead to many false positives.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123394 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp | 11 | ||||
-rw-r--r-- | test/Analysis/dead-stores.c | 12 |
2 files changed, 14 insertions, 9 deletions
diff --git a/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp b/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp index 1fe40c56e8..96c0dd426c 100644 --- a/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp +++ b/lib/StaticAnalyzer/Checkers/CheckDeadStores.cpp @@ -1,4 +1,4 @@ -//==- DeadStores.cpp - Check for stores to dead variables --------*- C++ -*-==// +//==- DeadStoresChecker.cpp - Check for stores to dead variables -*- C++ -*-==// // // The LLVM Compiler Infrastructure // @@ -70,11 +70,10 @@ public: break; case Enclosing: - BugType = "Dead nested assignment"; - msg = "Although the value stored to '" + name + - "' is used in the enclosing expression, the value is never actually" - " read from '" + name + "'"; - break; + // Don't report issues in this case, e.g.: "if (x = foo())", + // where 'x' is unused later. We have yet to see a case where + // this is a real bug. + return; } BR.EmitBasicReport(BugType, "Dead store", msg, L, R); diff --git a/test/Analysis/dead-stores.c b/test/Analysis/dead-stores.c index c150fa088d..a07138e50d 100644 --- a/test/Analysis/dead-stores.c +++ b/test/Analysis/dead-stores.c @@ -75,9 +75,11 @@ int f7d(int *p) { return 1; } +// Don't warn for dead stores in nested expressions. We have yet +// to see a real bug in this scenario. int f8(int *p) { extern int *baz(); - if ((p = baz())) // expected-warning{{Although the value}} + if ((p = baz())) // no-warning return 1; return 0; } @@ -148,9 +150,11 @@ void f15(unsigned x, unsigned y) { int z[count]; // expected-warning{{unused variable 'z'}} } +// Don't warn for dead stores in nested expressions. We have yet +// to see a real bug in this scenario. int f16(int x) { x = x * 2; - x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{Although the value stored to 'x' is used}} expected-warning{{The left operand to '*' is always 1}} expected-warning{{The left operand to '+' is always 0}} + x = sizeof(int [x = (x || x + 1) * 2]) // expected-warning{{The left operand to '+' is always 0}} expected-warning{{The left operand to '*' is always 1}} ? 5 : 8; return x; } @@ -175,7 +179,9 @@ int f18() { x = 10; // expected-warning{{Value stored to 'x' is never read}} while (1); - return (x = 10); // expected-warning{{Although the value stored to 'x' is used in the enclosing expression, the value is never actually read from 'x'}} + // Don't warn for dead stores in nested expressions. We have yet + // to see a real bug in this scenario. + return (x = 10); // no-warning } // PR 3514: false positive `dead initialization` warning for init to global |