From 2a14c695eb02777f93882f55a632de053614bca7 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Sun, 2 Oct 2011 00:54:48 +0000 Subject: [PATCH] Fix LiveVariables analysis bug with MaterializeTemporaryExpr and fix handling in ExprEngine. Fixes . llvm-svn: 140956 --- clang/lib/Analysis/LiveVariables.cpp | 4 ---- .../lib/StaticAnalyzer/Core/ExprEngineCXX.cpp | 23 ++++++++----------- clang/test/Analysis/stack-addr-ps.cpp | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp index 66211d9f09f4..055b58ca81a5 100644 --- a/clang/lib/Analysis/LiveVariables.cpp +++ b/clang/lib/Analysis/LiveVariables.cpp @@ -372,10 +372,6 @@ void TransferFunctions::Visit(Stmt *S) { S = cast(S)->getSubExpr(); break; } - case Stmt::MaterializeTemporaryExprClass: { - S = cast(S)->GetTemporaryExpr(); - break; - } case Stmt::UnaryExprOrTypeTraitExprClass: { // No need to unconditionally visit subexpressions. return; diff --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp index 7622eab9310f..acb007490ee1 100644 --- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -107,22 +107,19 @@ const CXXThisRegion *ExprEngine::getCXXThisRegion(const CXXMethodDecl *decl, void ExprEngine::CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, ExplodedNodeSet &Dst) { - ExplodedNodeSet Tmp; - Visit(ME->GetTemporaryExpr(), Pred, Tmp); - for (ExplodedNodeSet::iterator I = Tmp.begin(), E = Tmp.end(); I != E; ++I) { - const ProgramState *state = (*I)->getState(); + const Expr *tempExpr = ME->GetTemporaryExpr()->IgnoreParens(); + const ProgramState *state = Pred->getState(); - // Bind the temporary object to the value of the expression. Then bind - // the expression to the location of the object. - SVal V = state->getSVal(ME->GetTemporaryExpr()); + // Bind the temporary object to the value of the expression. Then bind + // the expression to the location of the object. + SVal V = state->getSVal(tempExpr); - const MemRegion *R = - svalBuilder.getRegionManager().getCXXTempObjectRegion(ME, - Pred->getLocationContext()); + const MemRegion *R = + svalBuilder.getRegionManager().getCXXTempObjectRegion(ME, + Pred->getLocationContext()); - state = state->bindLoc(loc::MemRegionVal(R), V); - MakeNode(Dst, ME, Pred, state->BindExpr(ME, loc::MemRegionVal(R))); - } + state = state->bindLoc(loc::MemRegionVal(R), V); + MakeNode(Dst, ME, Pred, state->BindExpr(ME, loc::MemRegionVal(R))); } void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *E, diff --git a/clang/test/Analysis/stack-addr-ps.cpp b/clang/test/Analysis/stack-addr-ps.cpp index d6140002fda0..b09e43560830 100644 --- a/clang/test/Analysis/stack-addr-ps.cpp +++ b/clang/test/Analysis/stack-addr-ps.cpp @@ -50,7 +50,7 @@ int *f2() { int *f3() { int x1; int *const &x2 = &x1; // expected-note {{binding reference variable 'x2' here}} - return x2; // expected-warning {{address of stack memory associated with local variable 'x1' returned}} + return x2; // expected-warning {{address of stack memory associated with local variable 'x1' returned}} expected-warning {{Address of stack memory associated with local variable 'x1' returned to caller}} } const int *f4() {