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 | f4e532b5a1683a9f6c842f361c7415bf3474315f (patch) | |
tree | 64a235fb732ad821ee73e7a4dfbd3c75cc0710da /lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp | |
parent | 0a86d44703fc5cd3cd38ea1708176f5b44321ed8 (diff) |
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>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125419 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp b/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp index 442e1b3af7..a6c0ea3154 100644 --- a/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp +++ b/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(); |