diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/ParentMap.cpp | 9 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp | 11 |
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/AST/ParentMap.cpp b/lib/AST/ParentMap.cpp index 21847f2821..87f8f36e6e 100644 --- a/lib/AST/ParentMap.cpp +++ b/lib/AST/ParentMap.cpp @@ -57,6 +57,15 @@ Stmt *ParentMap::getParentIgnoreParens(Stmt *S) const { return S; } +Stmt *ParentMap::getParentIgnoreParenCasts(Stmt *S) const { + do { + S = getParent(S); + } + while (S && (isa<ParenExpr>(S) || isa<CastExpr>(S))); + + return S; +} + bool ParentMap::isConsumedExpr(Expr* E) const { Stmt *P = getParent(E); Stmt *DirectChild = E; 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(); |