diff options
author | Ted Kremenek <kremenek@apple.com> | 2012-07-26 22:23:41 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2012-07-26 22:23:41 +0000 |
commit | 313c2ff37599b72ea8b7b259b789ea200cbd517b (patch) | |
tree | a276778713a4b21435c99be4b9db31564f9c6f55 /clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | |
parent | 75d17b0577d3e8ae4dabaa666d65fc4dc995c06a (diff) | |
download | bcm5719-llvm-313c2ff37599b72ea8b7b259b789ea200cbd517b.tar.gz bcm5719-llvm-313c2ff37599b72ea8b7b259b789ea200cbd517b.zip |
Look at the preceding CFGBlock for the expression to load from in ExprEngine::VisitGuardedExpr
instead of walking to the preceding PostStmt node. There are cases where the last evaluated
expression does not appear in the ExplodedGraph.
Fixes PR 13466.
llvm-svn: 160819
Diffstat (limited to 'clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp')
-rw-r--r-- | clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp index fd467c2b7aa..7ec151ef6d7 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp @@ -593,22 +593,36 @@ void ExprEngine::VisitGuardedExpr(const Expr *Ex, StmtNodeBuilder B(Pred, Dst, *currentBuilderContext); ProgramStateRef state = Pred->getState(); const LocationContext *LCtx = Pred->getLocationContext(); + const CFGBlock *SrcBlock = 0; - // Assume that the last CFGElement visited is the value of - // the guarded expression. - ExplodedNode *N = Pred; + for (const ExplodedNode *N = Pred ; N ; N = *N->pred_begin()) { + ProgramPoint PP = N->getLocation(); + if (isa<PreStmtPurgeDeadSymbols>(PP) || isa<BlockEntrance>(PP)) { + assert(N->pred_size() == 1); + continue; + } + SrcBlock = cast<BlockEdge>(&PP)->getSrc(); + break; + } + + // Find the last expression in the predecessor block. That is the + // expression that is used for the value of the ternary expression. + bool hasValue = false; SVal V; - while (N) { - ProgramPoint P = N->getLocation(); - if (const PostStmt *PS = dyn_cast<PostStmt>(&P)) { - const Expr *Ex = cast<Expr>(PS->getStmt()); - V = state->getSVal(Ex, LCtx); + + for (CFGBlock::const_reverse_iterator I = SrcBlock->rbegin(), + E = SrcBlock->rend(); I != E; ++I) { + CFGElement CE = *I; + if (CFGStmt *CS = dyn_cast<CFGStmt>(&CE)) { + const Expr *ValEx = cast<Expr>(CS->getStmt()); + hasValue = true; + V = state->getSVal(ValEx, LCtx); break; } - assert(N->pred_size() == 1); - N = *N->pred_begin(); } - assert(N); + + assert(hasValue); + (void) hasValue; // Generate a new node with the binding from the appropriate path. B.generateNode(Ex, Pred, state->BindExpr(Ex, LCtx, V, true)); |