diff options
| author | Ted Kremenek <kremenek@apple.com> | 2011-02-12 00:17:19 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2011-02-12 00:17:19 +0000 |
| commit | b1c392aa56225c5b8dc82ee5af502f58c7fbafce (patch) | |
| tree | e1915a1e55eba3a8cebf4a434656527fa8954f61 /clang/lib/StaticAnalyzer/Checkers | |
| parent | a222c0458897b5b54a3cb5a59b6cbbb2a45aca2c (diff) | |
| download | bcm5719-llvm-b1c392aa56225c5b8dc82ee5af502f58c7fbafce.tar.gz bcm5719-llvm-b1c392aa56225c5b8dc82ee5af502f58c7fbafce.zip | |
Don't emit a dead store for '++' operations unless it occurs with a return statement. We've never seen any other cases that were real bugs.
Fixes <rdar://problem/6962292>.
llvm-svn: 125419
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers')
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp index 442e1b3af78..a6c0ea3154e 100644 --- a/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp @@ -191,6 +191,8 @@ public: if (S->getLocStart().isMacroID()) return; + // Only cover dead stores from regular assignments. ++/-- dead stores + // have never flagged a real bug. if (BinaryOperator* B = dyn_cast<BinaryOperator>(S)) { if (!B->isAssignmentOp()) return; // Skip non-assignments. @@ -221,14 +223,11 @@ public: } } else if (UnaryOperator* U = dyn_cast<UnaryOperator>(S)) { - if (!U->isIncrementOp()) + if (!U->isIncrementOp() || U->isPrefix()) 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.isConsumedExpr(U)) + Stmt *parent = Parents.getParentIgnoreParenCasts(U); + if (!parent || !isa<ReturnStmt>(parent)) return; Expr *Ex = U->getSubExpr()->IgnoreParenCasts(); |

