Merge ValueManager into SValBuilder.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120696 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Checker/SimpleSValBuilder.cpp b/lib/Checker/SimpleSValBuilder.cpp
index 4203875..49d5535 100644
--- a/lib/Checker/SimpleSValBuilder.cpp
+++ b/lib/Checker/SimpleSValBuilder.cpp
@@ -23,7 +23,9 @@
   virtual SVal evalCastL(Loc val, QualType castTy);
 
 public:
-  SimpleSValBuilder(ValueManager &valMgr) : SValBuilder(valMgr) {}
+  SimpleSValBuilder(llvm::BumpPtrAllocator &alloc, ASTContext &context,
+                    GRStateManager &stateMgr)
+                    : SValBuilder(alloc, context, stateMgr) {}
   virtual ~SimpleSValBuilder() {}
 
   virtual SVal evalMinus(NonLoc val);
@@ -44,8 +46,10 @@
 };
 } // end anonymous namespace
 
-SValBuilder *clang::createSimpleSValBuilder(ValueManager &valMgr) {
-  return new SimpleSValBuilder(valMgr);
+SValBuilder *clang::createSimpleSValBuilder(llvm::BumpPtrAllocator &alloc,
+                                            ASTContext &context,
+                                            GRStateManager &stateMgr) {
+  return new SimpleSValBuilder(alloc, context, stateMgr);
 }
 
 //===----------------------------------------------------------------------===//
@@ -61,18 +65,15 @@
       return LI->getLoc();
 
     // FIXME: Correctly support promotions/truncations.
-    ASTContext &Ctx = ValMgr.getContext();
-    unsigned castSize = Ctx.getTypeSize(castTy);
+    unsigned castSize = Context.getTypeSize(castTy);
     if (castSize == LI->getNumBits())
       return val;
-
-    return ValMgr.makeLocAsInteger(LI->getLoc(), castSize);
+    return makeLocAsInteger(LI->getLoc(), castSize);
   }
 
   if (const SymExpr *se = val.getAsSymbolicExpression()) {
-    ASTContext &Ctx = ValMgr.getContext();
-    QualType T = Ctx.getCanonicalType(se->getType(Ctx));
-    if (T == Ctx.getCanonicalType(castTy))
+    QualType T = Context.getCanonicalType(se->getType(Context));
+    if (T == Context.getCanonicalType(castTy))
       return val;
     
     // FIXME: Remove this hack when we support symbolic truncation/extension.
@@ -96,12 +97,12 @@
 
   llvm::APSInt i = cast<nonloc::ConcreteInt>(val).getValue();
   i.setIsUnsigned(castTy->isUnsignedIntegerType() || Loc::IsLocType(castTy));
-  i.extOrTrunc(ValMgr.getContext().getTypeSize(castTy));
+  i.extOrTrunc(Context.getTypeSize(castTy));
 
   if (isLocType)
-    return ValMgr.makeIntLocVal(i);
+    return makeIntLocVal(i);
   else
-    return ValMgr.makeIntVal(i);
+    return makeIntVal(i);
 }
 
 SVal SimpleSValBuilder::evalCastL(Loc val, QualType castTy) {
@@ -121,15 +122,15 @@
     return UnknownVal();
 
   if (castTy->isIntegerType()) {
-    unsigned BitWidth = ValMgr.getContext().getTypeSize(castTy);
+    unsigned BitWidth = Context.getTypeSize(castTy);
 
     if (!isa<loc::ConcreteInt>(val))
-      return ValMgr.makeLocAsInteger(val, BitWidth);
+      return makeLocAsInteger(val, BitWidth);
 
     llvm::APSInt i = cast<loc::ConcreteInt>(val).getValue();
     i.setIsUnsigned(castTy->isUnsignedIntegerType() || Loc::IsLocType(castTy));
     i.extOrTrunc(BitWidth);
-    return ValMgr.makeIntVal(i);
+    return makeIntVal(i);
   }
 
   // All other cases: return 'UnknownVal'.  This includes casting pointers
@@ -145,7 +146,7 @@
 SVal SimpleSValBuilder::evalMinus(NonLoc val) {
   switch (val.getSubKind()) {
   case nonloc::ConcreteIntKind:
-    return cast<nonloc::ConcreteInt>(val).evalMinus(ValMgr);
+    return cast<nonloc::ConcreteInt>(val).evalMinus(*this);
   default:
     return UnknownVal();
   }
@@ -154,7 +155,7 @@
 SVal SimpleSValBuilder::evalComplement(NonLoc X) {
   switch (X.getSubKind()) {
   case nonloc::ConcreteIntKind:
-    return cast<nonloc::ConcreteInt>(X).evalComplement(ValMgr);
+    return cast<nonloc::ConcreteInt>(X).evalComplement(*this);
   default:
     return UnknownVal();
   }
@@ -205,7 +206,7 @@
   case BO_Mul:
     // a*0 and a*1
     if (RHS == 0)
-      return ValMgr.makeIntVal(0, resultTy);
+      return makeIntVal(0, resultTy);
     else if (RHS == 1)
       isIdempotent = true;
     break;
@@ -223,7 +224,7 @@
       // This is also handled elsewhere.
       return UndefinedVal();
     else if (RHS == 1)
-      return ValMgr.makeIntVal(0, resultTy);
+      return makeIntVal(0, resultTy);
     break;
   case BO_Add:
   case BO_Sub:
@@ -237,7 +238,7 @@
   case BO_And:
     // a&0 and a&(~0)
     if (RHS == 0)
-      return ValMgr.makeIntVal(0, resultTy);
+      return makeIntVal(0, resultTy);
     else if (RHS.isAllOnesValue())
       isIdempotent = true;
     break;
@@ -246,8 +247,7 @@
     if (RHS == 0)
       isIdempotent = true;
     else if (RHS.isAllOnesValue()) {
-      BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
-      const llvm::APSInt &Result = BVF.Convert(resultTy, RHS);
+      const llvm::APSInt &Result = BasicVals.Convert(resultTy, RHS);
       return nonloc::ConcreteInt(Result);
     }
     break;
@@ -263,7 +263,7 @@
 
   // If we reach this point, the expression cannot be simplified.
   // Make a SymExprVal for the entire thing.
-  return ValMgr.makeNonLoc(LHS, op, RHS, resultTy);
+  return makeNonLoc(LHS, op, RHS, resultTy);
 }
 
 SVal SimpleSValBuilder::evalBinOpNN(const GRState *state,
@@ -278,14 +278,14 @@
       case BO_EQ:
       case BO_LE:
       case BO_GE:
-        return ValMgr.makeTruthVal(true, resultTy);
+        return makeTruthVal(true, resultTy);
       case BO_LT:
       case BO_GT:
       case BO_NE:
-        return ValMgr.makeTruthVal(false, resultTy);
+        return makeTruthVal(false, resultTy);
       case BO_Xor:
       case BO_Sub:
-        return ValMgr.makeIntVal(0, resultTy);
+        return makeIntVal(0, resultTy);
       case BO_Or:
       case BO_And:
         return evalCastNL(lhs, resultTy);
@@ -304,18 +304,17 @@
                              resultTy);
         case nonloc::ConcreteIntKind: {
           // Transform the integer into a location and compare.
-          ASTContext& Ctx = ValMgr.getContext();
           llvm::APSInt i = cast<nonloc::ConcreteInt>(rhs).getValue();
           i.setIsUnsigned(true);
-          i.extOrTrunc(Ctx.getTypeSize(Ctx.VoidPtrTy));
-          return evalBinOpLL(state, op, lhsL, ValMgr.makeLoc(i), resultTy);
+          i.extOrTrunc(Context.getTypeSize(Context.VoidPtrTy));
+          return evalBinOpLL(state, op, lhsL, makeLoc(i), resultTy);
         }
         default:
           switch (op) {
             case BO_EQ:
-              return ValMgr.makeTruthVal(false, resultTy);
+              return makeTruthVal(false, resultTy);
             case BO_NE:
-              return ValMgr.makeTruthVal(true, resultTy);
+              return makeTruthVal(true, resultTy);
             default:
               // This case also handles pointer arithmetic.
               return UnknownVal();
@@ -372,8 +371,8 @@
         case BO_NE:
           // Negate the comparison and make a value.
           opc = NegateComparison(opc);
-          assert(symIntExpr->getType(ValMgr.getContext()) == resultTy);
-          return ValMgr.makeNonLoc(symIntExpr->getLHS(), opc,
+          assert(symIntExpr->getType(Context) == resultTy);
+          return makeNonLoc(symIntExpr->getLHS(), opc,
                                    symIntExpr->getRHS(), resultTy);
         }
       }
@@ -388,23 +387,20 @@
       if (BinaryOperator::isAdditiveOp(op)) {
         BinaryOperator::Opcode lop = symIntExpr->getOpcode();
         if (BinaryOperator::isAdditiveOp(lop)) {
-          BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
-
           // resultTy may not be the best type to convert to, but it's
           // probably the best choice in expressions with mixed type
           // (such as x+1U+2LL). The rules for implicit conversions should
           // choose a reasonable type to preserve the expression, and will
           // at least match how the value is going to be used.
           const llvm::APSInt &first =
-            BVF.Convert(resultTy, symIntExpr->getRHS());
+            BasicVals.Convert(resultTy, symIntExpr->getRHS());
           const llvm::APSInt &second =
-            BVF.Convert(resultTy, rhsInt->getValue());
-
+            BasicVals.Convert(resultTy, rhsInt->getValue());
           const llvm::APSInt *newRHS;
           if (lop == op)
-            newRHS = BVF.evalAPSInt(BO_Add, first, second);
+            newRHS = BasicVals.evalAPSInt(BO_Add, first, second);
           else
-            newRHS = BVF.evalAPSInt(BO_Sub, first, second);
+            newRHS = BasicVals.evalAPSInt(BO_Sub, first, second);
           return MakeSymIntVal(symIntExpr->getLHS(), lop, *newRHS, resultTy);
         }
       }
@@ -416,7 +412,7 @@
       const nonloc::ConcreteInt& lhsInt = cast<nonloc::ConcreteInt>(lhs);
 
       if (isa<nonloc::ConcreteInt>(rhs)) {
-        return lhsInt.evalBinOp(ValMgr, op, cast<nonloc::ConcreteInt>(rhs));
+        return lhsInt.evalBinOp(*this, op, cast<nonloc::ConcreteInt>(rhs));
       } else {
         const llvm::APSInt& lhsValue = lhsInt.getValue();
         
@@ -461,17 +457,13 @@
     case nonloc::SymbolValKind: {
       nonloc::SymbolVal *slhs = cast<nonloc::SymbolVal>(&lhs);
       SymbolRef Sym = slhs->getSymbol();
-
-      ASTContext& Ctx = ValMgr.getContext();
-
       // Does the symbol simplify to a constant?  If so, "fold" the constant
       // by setting 'lhs' to a ConcreteInt and try again.
-      if (Sym->getType(Ctx)->isIntegerType())
+      if (Sym->getType(Context)->isIntegerType())
         if (const llvm::APSInt *Constant = state->getSymVal(Sym)) {
           // The symbol evaluates to a constant. If necessary, promote the
           // folded constant (LHS) to the result type.
-          BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
-          const llvm::APSInt &lhs_I = BVF.Convert(resultTy, *Constant);
+          const llvm::APSInt &lhs_I = BasicVals.Convert(resultTy, *Constant);
           lhs = nonloc::ConcreteInt(lhs_I);
           
           // Also promote the RHS (if necessary).
@@ -483,7 +475,8 @@
           // Other operators: do an implicit conversion.  This shouldn't be
           // necessary once we support truncation/extension of symbolic values.
           if (nonloc::ConcreteInt *rhs_I = dyn_cast<nonloc::ConcreteInt>(&rhs)){
-            rhs = nonloc::ConcreteInt(BVF.Convert(resultTy, rhs_I->getValue()));
+            rhs = nonloc::ConcreteInt(BasicVals.Convert(resultTy,
+                                                        rhs_I->getValue()));
           }
           
           continue;
@@ -492,11 +485,10 @@
       // Is the RHS a symbol we can simplify?
       if (const nonloc::SymbolVal *srhs = dyn_cast<nonloc::SymbolVal>(&rhs)) {
         SymbolRef RSym = srhs->getSymbol();
-        if (RSym->getType(Ctx)->isIntegerType()) {
+        if (RSym->getType(Context)->isIntegerType()) {
           if (const llvm::APSInt *Constant = state->getSymVal(RSym)) {
             // The symbol evaluates to a constant.
-            BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
-            const llvm::APSInt &rhs_I = BVF.Convert(resultTy, *Constant);
+            const llvm::APSInt &rhs_I = BasicVals.Convert(resultTy, *Constant);
             rhs = nonloc::ConcreteInt(rhs_I);
           }
         }
@@ -535,15 +527,15 @@
       assert(false && "Unimplemented operation for two identical values");
       return UnknownVal();
     case BO_Sub:
-      return ValMgr.makeZeroVal(resultTy);
+      return makeZeroVal(resultTy);
     case BO_EQ:
     case BO_LE:
     case BO_GE:
-      return ValMgr.makeTruthVal(true, resultTy);
+      return makeTruthVal(true, resultTy);
     case BO_NE:
     case BO_LT:
     case BO_GT:
-      return ValMgr.makeTruthVal(false, resultTy);
+      return makeTruthVal(false, resultTy);
     }
   }
 
@@ -563,11 +555,11 @@
       case BO_EQ:
       case BO_LE:
       case BO_LT:
-        return ValMgr.makeTruthVal(false, resultTy);
+        return makeTruthVal(false, resultTy);
       case BO_NE:
       case BO_GT:
       case BO_GE:
-        return ValMgr.makeTruthVal(true, resultTy);
+        return makeTruthVal(true, resultTy);
       }
     }
     // There may be two labels for the same location, and a function region may
@@ -587,13 +579,13 @@
         return UnknownVal();
 
       const llvm::APSInt &lVal = cast<loc::ConcreteInt>(lhs).getValue();
-      return ValMgr.makeNonLoc(rSym, ReverseComparison(op), lVal, resultTy);
+      return makeNonLoc(rSym, ReverseComparison(op), lVal, resultTy);
     }
 
     // If both operands are constants, just perform the operation.
     if (loc::ConcreteInt *rInt = dyn_cast<loc::ConcreteInt>(&rhs)) {
-      BasicValueFactory &BVF = ValMgr.getBasicValueFactory();
-      SVal ResultVal = cast<loc::ConcreteInt>(lhs).evalBinOp(BVF, op, *rInt);
+      SVal ResultVal = cast<loc::ConcreteInt>(lhs).evalBinOp(BasicVals, op,
+                                                             *rInt);
       if (Loc *Result = dyn_cast<Loc>(&ResultVal))
         return evalCastL(*Result, resultTy);
       else
@@ -612,11 +604,11 @@
       case BO_EQ:
       case BO_GT:
       case BO_GE:
-        return ValMgr.makeTruthVal(false, resultTy);
+        return makeTruthVal(false, resultTy);
       case BO_NE:
       case BO_LT:
       case BO_LE:
-        return ValMgr.makeTruthVal(true, resultTy);
+        return makeTruthVal(true, resultTy);
       }
     }
 
@@ -644,11 +636,11 @@
         case BO_EQ:
         case BO_LT:
         case BO_LE:
-          return ValMgr.makeTruthVal(false, resultTy);
+          return makeTruthVal(false, resultTy);
         case BO_NE:
         case BO_GT:
         case BO_GE:
-          return ValMgr.makeTruthVal(true, resultTy);
+          return makeTruthVal(true, resultTy);
         }
       }
 
@@ -676,9 +668,9 @@
       default:
         return UnknownVal();
       case BO_EQ:
-        return ValMgr.makeTruthVal(false, resultTy);
+        return makeTruthVal(false, resultTy);
       case BO_NE:
-        return ValMgr.makeTruthVal(true, resultTy);
+        return makeTruthVal(true, resultTy);
       }
     }
 
@@ -738,17 +730,17 @@
         default:
           return UnknownVal();
         case BO_LT:
-          return ValMgr.makeTruthVal(left < right, resultTy);
+          return makeTruthVal(left < right, resultTy);
         case BO_GT:
-          return ValMgr.makeTruthVal(left > right, resultTy);
+          return makeTruthVal(left > right, resultTy);
         case BO_LE:
-          return ValMgr.makeTruthVal(left <= right, resultTy);
+          return makeTruthVal(left <= right, resultTy);
         case BO_GE:
-          return ValMgr.makeTruthVal(left >= right, resultTy);
+          return makeTruthVal(left >= right, resultTy);
         case BO_EQ:
-          return ValMgr.makeTruthVal(left == right, resultTy);
+          return makeTruthVal(left == right, resultTy);
         case BO_NE:
-          return ValMgr.makeTruthVal(left != right, resultTy);
+          return makeTruthVal(left != right, resultTy);
         }
       }
 
@@ -786,9 +778,9 @@
       // We know for sure that the two fields are not the same, since that
       // would have given us the same SVal.
       if (op == BO_EQ)
-        return ValMgr.makeTruthVal(false, resultTy);
+        return makeTruthVal(false, resultTy);
       if (op == BO_NE)
-        return ValMgr.makeTruthVal(true, resultTy);
+        return makeTruthVal(true, resultTy);
 
       // Iterate through the fields and see which one comes first.
       // [C99 6.7.2.1.13] "Within a structure object, the non-bit-field
@@ -798,9 +790,9 @@
       for (RecordDecl::field_iterator I = RD->field_begin(),
            E = RD->field_end(); I!=E; ++I) {
         if (*I == LeftFD)
-          return ValMgr.makeTruthVal(leftFirst, resultTy);
+          return makeTruthVal(leftFirst, resultTy);
         if (*I == RightFD)
-          return ValMgr.makeTruthVal(!leftFirst, resultTy);
+          return makeTruthVal(!leftFirst, resultTy);
       }
 
       assert(false && "Fields not found in parent record's definition");
@@ -823,11 +815,11 @@
   if (BinaryOperator::isComparisonOp(op)) {
     if (nonloc::ConcreteInt *rhsInt = dyn_cast<nonloc::ConcreteInt>(&rhs)) {
       const llvm::APSInt *x = &rhsInt->getValue();
-      ASTContext &ctx = ValMgr.getContext();
+      ASTContext &ctx = Context;
       if (ctx.getTypeSize(ctx.VoidPtrTy) == x->getBitWidth()) {
         // Convert the signedness of the integer (if necessary).
         if (x->isSigned())
-          x = &ValMgr.getBasicValueFactory().getValue(*x, true);
+          x = &getBasicValueFactory().getValue(*x, true);
 
         return evalBinOpLL(state, op, lhs, loc::ConcreteInt(*x), resultTy);
       }
@@ -862,7 +854,7 @@
         default:
           llvm_unreachable("Invalid pointer arithmetic operation");
       }
-      return loc::ConcreteInt(ValMgr.getBasicValueFactory().getValue(rightI));
+      return loc::ConcreteInt(getBasicValueFactory().getValue(rightI));
     }
   }