Remove CodeDecl and CFG from GRExprEngine and GRStateManager.
Now AnalysisManager is the only place we can get CodeDecl.
This leads to an API change: GRState::bindExpr() now takes the CFG argument.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79980 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 17baca7..cfb9148 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -147,26 +147,20 @@
 }
 
 
-GRExprEngine::GRExprEngine(CFG &cfg, const Decl &CD, ASTContext &Ctx,
-                           LiveVariables &L, AnalysisManager &mgr,
-                           bool purgeDead, bool eagerlyAssume,
-                           StoreManagerCreator SMC,
-                           ConstraintManagerCreator CMC)
+GRExprEngine::GRExprEngine(AnalysisManager &mgr)
   : AMgr(mgr),
-    CoreEngine(Ctx, *this), 
+    CoreEngine(mgr.getASTContext(), *this), 
     G(CoreEngine.getGraph()),
-    Liveness(L),
     Builder(NULL),
-    StateMgr(G.getContext(), SMC, CMC, G.getAllocator(), cfg, CD, L),
+    StateMgr(G.getContext(), mgr.getStoreManagerCreator(), 
+             mgr.getConstraintManagerCreator(), G.getAllocator()),
     SymMgr(StateMgr.getSymbolManager()),
     ValMgr(StateMgr.getValueManager()),
     SVator(ValMgr.getSValuator()),
     CurrentStmt(NULL),
     NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL),
     RaiseSel(GetNullarySelector("raise", G.getContext())), 
-    PurgeDead(purgeDead),
-    BR(mgr, *this),
-    EagerlyAssume(eagerlyAssume) {}
+    BR(mgr, *this) {}
 
 GRExprEngine::~GRExprEngine() {    
   BR.FlushReports();
@@ -250,7 +244,7 @@
     Builder->setAuditor(BatchAuditor.get());
     
   // Create the cleaned state.  
-  SymbolReaper SymReaper(Liveness, SymMgr);  
+  SymbolReaper SymReaper(*AMgr.getLiveVariables(), SymMgr);  
   CleanedState = PurgeDead ? StateMgr.RemoveDeadBindings(EntryNode->getState(), 
                                                          CurrentStmt, SymReaper)
                            : EntryNode->getState();
@@ -347,11 +341,12 @@
       }
       else if (B->getOpcode() == BinaryOperator::Comma) {
         const GRState* state = GetState(Pred);
-        MakeNode(Dst, B, Pred, state->bindExpr(B, state->getSVal(B->getRHS())));
+        MakeNode(Dst, B, Pred, state->bindExpr(B, state->getSVal(B->getRHS()),
+                                               Pred->getCFG()));
         break;
       }
 
-      if (EagerlyAssume && (B->isRelationalOp() || B->isEqualityOp())) {
+      if (AMgr.shouldEagerlyAssume() && (B->isRelationalOp() || B->isEqualityOp())) {
         ExplodedNodeSet Tmp;
         VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Tmp);
         EvalEagerlyAssume(Dst, Tmp, cast<Expr>(S));        
@@ -463,7 +458,8 @@
                
       if (Expr* LastExpr = dyn_cast<Expr>(*SE->getSubStmt()->body_rbegin())) {
         const GRState* state = GetState(Pred);
-        MakeNode(Dst, SE, Pred, state->bindExpr(SE, state->getSVal(LastExpr)));
+        MakeNode(Dst, SE, Pred, state->bindExpr(SE, state->getSVal(LastExpr),
+                                                Pred->getCFG()));
       }
       else
         Dst.Add(Pred);
@@ -477,7 +473,7 @@
       
     case Stmt::UnaryOperatorClass: {
       UnaryOperator *U = cast<UnaryOperator>(S);
-      if (EagerlyAssume && (U->getOpcode() == UnaryOperator::LNot)) {
+      if (AMgr.shouldEagerlyAssume() && (U->getOpcode() == UnaryOperator::LNot)) {
         ExplodedNodeSet Tmp;
         VisitUnaryOperator(U, Pred, Tmp, false);
         EvalEagerlyAssume(Dst, Tmp, U);
@@ -545,7 +541,7 @@
     case Stmt::StringLiteralClass: {
       const GRState* state = GetState(Pred);
       SVal V = state->getLValue(cast<StringLiteral>(Ex));
-      MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V));
+      MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V, Pred->getCFG()));
       return;
     }
       
@@ -978,7 +974,7 @@
     SVal V = state->getLValue(VD, Pred->getLocationContext());
 
     if (asLValue)
-      MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V),
+      MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V, Pred->getCFG()),
                ProgramPoint::PostLValueKind);
     else
       EvalLoad(Dst, Ex, Pred, state, V);
@@ -988,13 +984,13 @@
     assert(!asLValue && "EnumConstantDecl does not have lvalue.");
 
     SVal V = ValMgr.makeIntVal(ED->getInitVal());
-    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V));
+    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V, Pred->getCFG()));
     return;
 
   } else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(D)) {
     assert(asLValue);
     SVal V = ValMgr.getFunctionPointer(FD);
-    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V),
+    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V, Pred->getCFG()),
              ProgramPoint::PostLValueKind);
     return;
   }
@@ -1032,7 +1028,7 @@
                                 state->getSVal(Idx));
 
       if (asLValue)
-        MakeNode(Dst, A, *I2, state->bindExpr(A, V),
+        MakeNode(Dst, A, *I2, state->bindExpr(A, V, Pred->getCFG()),
                  ProgramPoint::PostLValueKind);
       else
         EvalLoad(Dst, A, *I2, state, V);
@@ -1064,7 +1060,7 @@
     SVal L = state->getLValue(state->getSVal(Base), Field);
 
     if (asLValue)
-      MakeNode(Dst, M, *I, state->bindExpr(M, L),
+      MakeNode(Dst, M, *I, state->bindExpr(M, L, Pred->getCFG()),
                ProgramPoint::PostLValueKind);
     else
       EvalLoad(Dst, M, *I, state, L);
@@ -1148,7 +1144,8 @@
 
   if (location.isUnknown()) {
     // This is important.  We must nuke the old binding.
-    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, UnknownVal()), K, tag);
+    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, UnknownVal(), Pred->getCFG()),
+             K, tag);
   }
   else {
     SVal V = state->getSVal(cast<Loc>(location), Ex->getType());
@@ -1165,7 +1162,7 @@
     //  V = EvalCast(V, Ex->getType());
     //}
     
-    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V), K, tag);
+    MakeNode(Dst, Ex, Pred, state->bindExpr(Ex, V, Pred->getCFG()), K, tag);
   }
 }
 
@@ -1387,14 +1384,16 @@
         ExplodedNode *predNew = *I2;
         const GRState *stateNew = predNew->getState();
         SVal Res = Engine.getValueManager().makeTruthVal(true, CE->getType());
-        Engine.MakeNode(Dst, CE, predNew, stateNew->bindExpr(CE, Res));
+        Engine.MakeNode(Dst, CE, predNew, stateNew->bindExpr(CE, Res, 
+                                                             Pred->getCFG()));
       }
     }
     
     // Were they not equal?
     if (const GRState *stateNotEqual = stateLoad->assume(Cmp, false)) {
       SVal Res = Engine.getValueManager().makeTruthVal(false, CE->getType());
-      Engine.MakeNode(Dst, CE, N, stateNotEqual->bindExpr(CE, Res));
+      Engine.MakeNode(Dst, CE, N, stateNotEqual->bindExpr(CE, Res, 
+                                                          Pred->getCFG()));
     }
   }
       
@@ -1609,7 +1608,7 @@
             // For __builtin_expect, just return the value of the subexpression.
             assert (CE->arg_begin() != CE->arg_end());            
             SVal X = state->getSVal(*(CE->arg_begin()));
-            MakeNode(Dst, CE, *DI, state->bindExpr(CE, X));
+            MakeNode(Dst, CE, *DI, state->bindExpr(CE, X, Pred->getCFG()));
             continue;            
           }
             
@@ -1625,7 +1624,8 @@
             SVal Extent = state->getSVal(*(CE->arg_begin()));
             state = getStoreManager().setExtent(state, R, Extent);
 
-            MakeNode(Dst, CE, *DI, state->bindExpr(CE, loc::MemRegionVal(R)));
+            MakeNode(Dst, CE, *DI, state->bindExpr(CE, loc::MemRegionVal(R), 
+                                                   Pred->getCFG()));
             continue;            
           }
             
@@ -1698,7 +1698,8 @@
       // First assume that the condition is true.
       if (const GRState *stateTrue = state->assume(V, true)) {
         stateTrue = stateTrue->bindExpr(Ex, 
-                                        ValMgr.makeIntVal(1U, Ex->getType()));
+                                        ValMgr.makeIntVal(1U, Ex->getType()),
+                                        Pred->getCFG());
         Dst.Add(Builder->generateNode(PostStmtCustom(Ex, 
                                 &EagerlyAssumeTag, Pred->getLocationContext()),
                                       stateTrue, Pred));
@@ -1707,7 +1708,8 @@
       // Next, assume that the condition is false.
       if (const GRState *stateFalse = state->assume(V, false)) {
         stateFalse = stateFalse->bindExpr(Ex, 
-                                          ValMgr.makeIntVal(0U, Ex->getType()));
+                                          ValMgr.makeIntVal(0U, Ex->getType()),
+                                          Pred->getCFG());
         Dst.Add(Builder->generateNode(PostStmtCustom(Ex, &EagerlyAssumeTag,
                                                    Pred->getLocationContext()),
                                       stateFalse, Pred));
@@ -1736,7 +1738,7 @@
     SVal location = state->getLValue(Ex->getDecl(), BaseVal);
     
     if (asLValue)
-      MakeNode(Dst, Ex, *I, state->bindExpr(Ex, location));
+      MakeNode(Dst, Ex, *I, state->bindExpr(Ex, location, Pred->getCFG()));
     else
       EvalLoad(Dst, Ex, *I, state, location);
   }
@@ -1812,11 +1814,11 @@
 
   // Handle the case where the container still has elements.
   SVal TrueV = ValMgr.makeTruthVal(1);
-  const GRState *hasElems = state->bindExpr(S, TrueV);
+  const GRState *hasElems = state->bindExpr(S, TrueV, Pred->getCFG());
   
   // Handle the case where the container has no elements.
   SVal FalseV = ValMgr.makeTruthVal(0);
-  const GRState *noElems = state->bindExpr(S, FalseV);
+  const GRState *noElems = state->bindExpr(S, FalseV, Pred->getCFG());
   
   if (loc::MemRegionVal* MV = dyn_cast<loc::MemRegionVal>(&ElementV))
     if (const TypedRegion* R = dyn_cast<TypedRegion>(MV->getRegion())) {
@@ -1968,7 +1970,7 @@
               // of this case unless we have *a lot* more knowledge.
               //
               SVal V = ValMgr.makeZeroVal(ME->getType());
-              MakeNode(Dst, ME, Pred, StNull->bindExpr(ME, V));
+              MakeNode(Dst, ME, Pred, StNull->bindExpr(ME, V, Pred->getCFG()));
               return;
             }
           }
@@ -2105,13 +2107,14 @@
     const GRState* state = GetState(N);
     SVal V = state->getSVal(Ex);
     const SValuator::CastResult &Res = SVator.EvalCast(V, state, T, ExTy);
-    state = Res.getState()->bindExpr(CastE, Res.getSVal());
+    state = Res.getState()->bindExpr(CastE, Res.getSVal(), Pred->getCFG());
     MakeNode(Dst, CastE, N, state);
   }
 }
 
 void GRExprEngine::VisitCompoundLiteralExpr(CompoundLiteralExpr* CL,
-                                            ExplodedNode* Pred, ExplodedNodeSet& Dst, 
+                                            ExplodedNode* Pred, 
+                                            ExplodedNodeSet& Dst, 
                                             bool asLValue) {
   InitListExpr* ILE = cast<InitListExpr>(CL->getInitializer()->IgnoreParens());
   ExplodedNodeSet Tmp;
@@ -2123,9 +2126,10 @@
     state = state->bindCompoundLiteral(CL, ILV);
 
     if (asLValue)
-      MakeNode(Dst, CL, *I, state->bindExpr(CL, state->getLValue(CL)));
+      MakeNode(Dst, CL, *I, state->bindExpr(CL, state->getLValue(CL), 
+                                            Pred->getCFG()));
     else
-      MakeNode(Dst, CL, *I, state->bindExpr(CL, ILV));
+      MakeNode(Dst, CL, *I, state->bindExpr(CL, ILV, Pred->getCFG()));
   }
 }
 
@@ -2249,7 +2253,7 @@
     // e.g: static int* myArray[] = {};
     if (NumInitElements == 0) {
       SVal V = ValMgr.makeCompoundVal(T, StartVals);
-      MakeNode(Dst, E, Pred, state->bindExpr(E, V));
+      MakeNode(Dst, E, Pred, state->bindExpr(E, V, Pred->getCFG()));
       return;
     }      
     
@@ -2284,7 +2288,7 @@
           SVal V = ValMgr.makeCompoundVal(T, NewVals);
 
           // Make final state and node.
-          MakeNode(Dst, E, *NI, state->bindExpr(E, V));
+          MakeNode(Dst, E, *NI, state->bindExpr(E, V, (*NI)->getCFG()));
         }
         else {
           // Still some initializer values to go.  Push them onto the worklist.
@@ -2303,7 +2307,7 @@
     Visit(Init, Pred, Tmp);
     for (ExplodedNodeSet::iterator I = Tmp.begin(), EI = Tmp.end(); I != EI; ++I) {
       state = GetState(*I);
-      MakeNode(Dst, E, *I, state->bindExpr(E, state->getSVal(Init)));
+      MakeNode(Dst, E, *I, state->bindExpr(E, state->getSVal(Init), Pred->getCFG()));
     }
     return;
   }
@@ -2344,7 +2348,8 @@
     amt = getContext().getTypeAlign(T) / 8;
   
   MakeNode(Dst, Ex, Pred,
-           GetState(Pred)->bindExpr(Ex, ValMgr.makeIntVal(amt, Ex->getType())));
+           GetState(Pred)->bindExpr(Ex, ValMgr.makeIntVal(amt, Ex->getType()),
+                                    Pred->getCFG()));
 }
 
 
@@ -2368,7 +2373,7 @@
         SVal location = state->getSVal(Ex);
         
         if (asLValue)
-          MakeNode(Dst, U, *I, state->bindExpr(U, location),
+          MakeNode(Dst, U, *I, state->bindExpr(U, location, (*I)->getCFG()),
                    ProgramPoint::PostLValueKind);
         else
           EvalLoad(Dst, U, *I, state, location);
@@ -2395,7 +2400,7 @@
         // For all other types, UnaryOperator::Real is an identity operation.
         assert (U->getType() == Ex->getType());
         const GRState* state = GetState(*I);
-        MakeNode(Dst, U, *I, state->bindExpr(U, state->getSVal(Ex)));
+        MakeNode(Dst, U, *I, state->bindExpr(U, state->getSVal(Ex), (*I)->getCFG()));
       } 
       
       return;
@@ -2419,7 +2424,7 @@
         assert (Ex->getType()->isIntegerType());
         const GRState* state = GetState(*I);
         SVal X = ValMgr.makeZeroVal(Ex->getType());
-        MakeNode(Dst, U, *I, state->bindExpr(U, X));
+        MakeNode(Dst, U, *I, state->bindExpr(U, X, (*I)->getCFG()));
       }
       
       return;
@@ -2444,7 +2449,7 @@
       
       for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {        
         const GRState* state = GetState(*I);
-        MakeNode(Dst, U, *I, state->bindExpr(U, state->getSVal(Ex)));
+        MakeNode(Dst, U, *I, state->bindExpr(U, state->getSVal(Ex), (*I)->getCFG()));
       }
       
       return;
@@ -2460,7 +2465,7 @@
       for (ExplodedNodeSet::iterator I=Tmp.begin(), E=Tmp.end(); I!=E; ++I) {        
         const GRState* state = GetState(*I);
         SVal V = state->getSVal(Ex);
-        state = state->bindExpr(U, V);
+        state = state->bindExpr(U, V, (*I)->getCFG());
         MakeNode(Dst, U, *I, state);
       }
 
@@ -2483,7 +2488,7 @@
         SVal V = state->getSVal(Ex);
 
         if (V.isUnknownOrUndef()) {
-          MakeNode(Dst, U, *I, state->bindExpr(U, V));
+          MakeNode(Dst, U, *I, state->bindExpr(U, V, (*I)->getCFG()));
           continue;
         }
         
@@ -2505,12 +2510,13 @@
             
           case UnaryOperator::Not:
             // FIXME: Do we need to handle promotions?
-            state = state->bindExpr(U, EvalComplement(cast<NonLoc>(V)));
+            state = state->bindExpr(U, EvalComplement(cast<NonLoc>(V)), 
+                                    (*I)->getCFG());
             break;            
             
           case UnaryOperator::Minus:
             // FIXME: Do we need to handle promotions?
-            state = state->bindExpr(U, EvalMinus(cast<NonLoc>(V)));
+            state = state->bindExpr(U, EvalMinus(cast<NonLoc>(V)), (*I)->getCFG());
             break;   
             
           case UnaryOperator::LNot:   
@@ -2532,7 +2538,7 @@
                                  U->getType());
             }
             
-            state = state->bindExpr(U, Result);
+            state = state->bindExpr(U, Result, (*I)->getCFG());
             
             break;
         }
@@ -2567,7 +2573,7 @@
         
       // Propagate unknown and undefined values.      
       if (V2.isUnknownOrUndef()) {
-        MakeNode(Dst, U, *I2, state->bindExpr(U, V2));
+        MakeNode(Dst, U, *I2, state->bindExpr(U, V2, (*I2)->getCFG()));
         continue;
       }
       
@@ -2613,7 +2619,7 @@
         }        
       }
       
-      state = state->bindExpr(U, U->isPostfix() ? V2 : Result);
+      state = state->bindExpr(U, U->isPostfix() ? V2 : Result, (*I2)->getCFG());
 
       // Perform the store.      
       EvalStore(Dst, U, *I2, state, V1, Result);
@@ -2837,8 +2843,8 @@
           
           // Simulate the effects of a "store":  bind the value of the RHS
           // to the L-Value represented by the LHS.          
-          EvalStore(Dst, B, LHS, *I2, state->bindExpr(B, RightV), LeftV,
-                    RightV);
+          EvalStore(Dst, B, LHS, *I2, state->bindExpr(B, RightV, (*I2)->getCFG()), 
+                    LeftV, RightV);
           continue;
         }
           
@@ -2890,7 +2896,7 @@
           
           // Otherwise, create a new node.
           
-          MakeNode(Dst, B, *I2, state->bindExpr(B, Result));
+          MakeNode(Dst, B, *I2, state->bindExpr(B, Result, (*I2)->getCFG()));
           continue;
         }
       }
@@ -2938,14 +2944,15 @@
         
         // Propagate undefined values (left-side).          
         if (V.isUndef()) {
-          EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, V), location, V);
+          EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, V, (*I3)->getCFG()), 
+                    location, V);
           continue;
         }
         
         // Propagate unknown values (left and right-side).
         if (RightV.isUnknown() || V.isUnknown()) {
-          EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, UnknownVal()),
-                    location, UnknownVal());
+          EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, UnknownVal(), 
+                    (*I3)->getCFG()), location, UnknownVal());
           continue;
         }
 
@@ -2972,8 +2979,8 @@
         // Evaluate operands and promote to result type.                    
         if (RightV.isUndef()) {            
           // Propagate undefined values (right-side).          
-          EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, RightV), location,
-                    RightV);
+          EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, RightV, (*I3)->getCFG()), 
+                    location, RightV);
           continue;
         }
       
@@ -3018,8 +3025,8 @@
           llvm::tie(state, LHSVal) = SVator.EvalCast(Result, state, LTy, CTy);
         }
           
-        EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, Result), location,
-                  LHSVal);
+        EvalStore(Dst, B, LHS, *I3, state->bindExpr(B, Result, (*I3)->getCFG()), 
+                  location, LHSVal);
       }
     }
   }