diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-04-01 06:52:48 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-04-01 06:52:48 +0000 |
commit | b930d7adb7cb7642c9c49b39df04ebd5cbfa713a (patch) | |
tree | 403e393ad9683ef16b8154dca8a1f0da89fa4228 /lib/Analysis/CheckDeadStores.cpp | |
parent | 03d9f34a96ea28eaa698cc779462a1ce1dc79105 (diff) |
Fix: <rdar://problem/6740387>. Sending nil to an object that returns a struct
should only be an error if that value is consumed. This fix was largely
accomplished by moving 'isConsumedExpr' back to ParentMap.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68195 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CheckDeadStores.cpp')
-rw-r--r-- | lib/Analysis/CheckDeadStores.cpp | 46 |
1 files changed, 3 insertions, 43 deletions
diff --git a/lib/Analysis/CheckDeadStores.cpp b/lib/Analysis/CheckDeadStores.cpp index 504de3c97d..d1b3be511a 100644 --- a/lib/Analysis/CheckDeadStores.cpp +++ b/lib/Analysis/CheckDeadStores.cpp @@ -38,10 +38,7 @@ public: : Ctx(ctx), BR(br), Parents(parents) {} virtual ~DeadStoreObs() {} - - bool isConsumedExpr(Expr* E) const; - - + void Report(VarDecl* V, DeadStoreKind dsk, SourceLocation L, SourceRange R) { std::string name = V->getNameAsString(); @@ -148,7 +145,7 @@ public: return; // Otherwise, issue a warning. - DeadStoreKind dsk = isConsumedExpr(B) + DeadStoreKind dsk = Parents.isConsumedExpr(B) ? Enclosing : (isIncrement(VD,B) ? DeadIncrement : Standard); @@ -163,7 +160,7 @@ public: // 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() && isConsumedExpr(U)) + if (U->isPrefix() && Parents.isConsumedExpr(U)) return; Expr *Ex = U->getSubExpr()->IgnoreParenCasts(); @@ -218,43 +215,6 @@ public: } // end anonymous namespace -bool DeadStoreObs::isConsumedExpr(Expr* E) const { - Stmt *P = Parents.getParent(E); - Stmt *DirectChild = E; - - // Ignore parents that are parentheses or casts. - while (P && (isa<ParenExpr>(E) || isa<CastExpr>(E))) { - DirectChild = P; - P = Parents.getParent(P); - } - - if (!P) - return false; - - switch (P->getStmtClass()) { - default: - return isa<Expr>(P); - case Stmt::BinaryOperatorClass: { - BinaryOperator *BE = cast<BinaryOperator>(P); - return BE->getOpcode()==BinaryOperator::Comma && DirectChild==BE->getLHS(); - } - case Stmt::ForStmtClass: - return DirectChild == cast<ForStmt>(P)->getCond(); - case Stmt::WhileStmtClass: - return DirectChild == cast<WhileStmt>(P)->getCond(); - case Stmt::DoStmtClass: - return DirectChild == cast<DoStmt>(P)->getCond(); - case Stmt::IfStmtClass: - return DirectChild == cast<IfStmt>(P)->getCond(); - case Stmt::IndirectGotoStmtClass: - return DirectChild == cast<IndirectGotoStmt>(P)->getTarget(); - case Stmt::SwitchStmtClass: - return DirectChild == cast<SwitchStmt>(P)->getCond(); - case Stmt::ReturnStmtClass: - return true; - } -} - //===----------------------------------------------------------------------===// // Driver function to invoke the Dead-Stores checker on a CFG. //===----------------------------------------------------------------------===// |