]> granicus.if.org Git - clang/commitdiff
Fix LiveVariables analysis bug with MaterializeTemporaryExpr and fix handling in...
authorTed Kremenek <kremenek@apple.com>
Sun, 2 Oct 2011 00:54:48 +0000 (00:54 +0000)
committerTed Kremenek <kremenek@apple.com>
Sun, 2 Oct 2011 00:54:48 +0000 (00:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140956 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/LiveVariables.cpp
lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
test/Analysis/stack-addr-ps.cpp

index 66211d9f09f45df7e09145ceac0a764daa5f4cfb..055b58ca81a5fb951e9f67dad11b8758e4c76115 100644 (file)
@@ -372,10 +372,6 @@ void TransferFunctions::Visit(Stmt *S) {
       S = cast<CXXBindTemporaryExpr>(S)->getSubExpr();
       break;
     }
-    case Stmt::MaterializeTemporaryExprClass: {
-      S = cast<MaterializeTemporaryExpr>(S)->GetTemporaryExpr();
-      break;
-    }
     case Stmt::UnaryExprOrTypeTraitExprClass: {
       // No need to unconditionally visit subexpressions.
       return;
index 7622eab9310f0239a65f55102041ca3f519ad4f2..acb007490ee19d986d60b095119617c27dab2e06 100644 (file)
@@ -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, 
index d6140002fda0713e9ba11da598a4f9a089df3732..b09e435608309de4a92b437b0771cd44edc3fa16 100644 (file)
@@ -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() {