namespace clang {
class EnvironmentManager;
-class BasicValueFactory;
+class ValueManager;
class LiveVariables;
class Environment {
return X ? *X : UnknownVal();
}
- SVal GetSVal(const Stmt* Ex, BasicValueFactory& BasicVals) const;
- SVal GetBlkExprSVal(const Stmt* Ex, BasicValueFactory& BasicVals) const;
+ SVal GetSVal(const Stmt* Ex, ValueManager& ValMgr) const;
+ SVal GetBlkExprSVal(const Stmt* Ex, ValueManager& ValMgr) const;
/// Profile - Profile the contents of an Environment object for use
/// in a FoldingSet.
return N == EntryNode ? CleanedState : N->getState();
}
-public:
- inline NonLoc MakeConstantVal(uint64_t X, Expr* Ex) {
- return NonLoc::MakeVal(getBasicVals(), X, Ex->getType());
- }
-
public:
NodeTy* MakeNode(NodeSet& Dst, Stmt* S, NodeTy* Pred, const GRState* St,
ProgramPoint::Kind K = ProgramPoint::PostStmtKind,
// Methods that query & manipulate the Environment.
SVal GetSVal(const GRState* St, const Stmt* Ex) {
- return St->getEnvironment().GetSVal(Ex, getBasicVals());
+ return St->getEnvironment().GetSVal(Ex, ValueMgr);
}
SVal GetSValAsScalarOrLoc(const GRState* state, const Stmt *S) {
}
SVal GetBlkExprSVal(const GRState* St, const Stmt* Ex) {
- return St->getEnvironment().GetBlkExprSVal(Ex, getBasicVals());
+ return St->getEnvironment().GetBlkExprSVal(Ex, ValueMgr);
}
const GRState* BindExpr(const GRState* St, const Stmt* Ex, SVal V,
class MemRegion;
class MemRegionManager;
class GRStateManager;
+class ValueManager;
class SVal {
public:
public:
void print(llvm::raw_ostream& Out) const;
- // Utility methods to create NonLocs.
-
- static NonLoc MakeIntVal(BasicValueFactory& BasicVals, uint64_t X,
- bool isUnsigned);
-
- static NonLoc MakeVal(BasicValueFactory& BasicVals, uint64_t X,
- unsigned BitWidth, bool isUnsigned);
-
- static NonLoc MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T);
-
- static NonLoc MakeVal(BasicValueFactory& BasicVals, const IntegerLiteral *I);
-
- static NonLoc MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I,
- bool isUnsigned);
-
- static NonLoc MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I);
-
- static NonLoc MakeIntTruthVal(BasicValueFactory& BasicVals, bool b);
-
- static NonLoc MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
- BasicValueFactory& BasicVals);
-
// Implement isa<T> support.
static inline bool classof(const SVal* V) {
return V->getBaseKind() == NonLocKind;
Loc(const Loc& X) : SVal(X.Data, true, X.getSubKind()) {}
Loc& operator=(const Loc& X) { memcpy(this, &X, sizeof(Loc)); return *this; }
- static Loc MakeVal(const MemRegion* R);
-
- static Loc MakeVal(const AddrLabelExpr* E);
-
- static Loc MakeNull(BasicValueFactory &BasicVals);
-
// Implement isa<T> support.
static inline bool classof(const SVal* V) {
return V->getBaseKind() == LocKind;
};
class LocAsInteger : public NonLoc {
+ friend class clang::ValueManager;
+
LocAsInteger(const std::pair<SVal, uintptr_t>& data) :
NonLoc(LocAsIntegerKind, &data) {
assert (isa<Loc>(data.first));
static inline bool classof(const NonLoc* V) {
return V->getSubKind() == LocAsIntegerKind;
}
-
- static LocAsInteger Make(BasicValueFactory& Vals, Loc V, unsigned Bits);
};
class CompoundVal : public NonLoc {
- friend class NonLoc;
+ friend class clang::ValueManager;
CompoundVal(const CompoundValData* D) : NonLoc(CompoundValKind, D) {}
return SymMgr.getConjuredSymbol(E, VisitCount, SymbolTag);
}
- // Aggregation methods that use multiple submanagers.
-
- Loc makeRegionVal(SymbolRef Sym) {
- return Loc::MakeVal(MemMgr.getSymbolicRegion(Sym));
- }
-
/// makeZeroVal - Construct an SVal representing '0' for the specified type.
SVal makeZeroVal(QualType T);
- /// makeZeroArrayIndex - Construct an SVal representing '0' index for array
- /// elements.
- SVal makeZeroArrayIndex();
/// GetRegionValueSymbolVal - make a unique symbol for value of R.
SVal getRegionValueSymbolVal(const MemRegion* R, QualType T = QualType());
SVal getConjuredSymbolVal(const Expr* E, QualType T, unsigned Count);
SVal getFunctionPointer(const FunctionDecl* FD);
-
- NonLoc makeNonLoc(SymbolRef sym);
- NonLoc makeIntVal(const llvm::APSInt& V);
-
+ NonLoc makeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals) {
+ return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
+ }
+
+ NonLoc makeZeroArrayIndex() {
+ return nonloc::ConcreteInt(BasicVals.getZeroWithPtrWidth(false));
+ }
+
+ NonLoc makeIntVal(const IntegerLiteral* I) {
+ return nonloc::ConcreteInt(BasicVals.getValue(I->getValue(),
+ I->getType()->isUnsignedIntegerType()));
+ }
+
+ NonLoc makeIntVal(const llvm::APSInt& V) {
+ return nonloc::ConcreteInt(BasicVals.getValue(V));
+ }
+
+ NonLoc makeIntVal(const llvm::APInt& V, bool isUnsigned) {
+ return nonloc::ConcreteInt(BasicVals.getValue(V, isUnsigned));
+ }
+
+ NonLoc makeIntVal(uint64_t X, QualType T) {
+ return nonloc::ConcreteInt(BasicVals.getValue(X, T));
+ }
+
+ NonLoc makeIntVal(uint64_t X, bool isUnsigned) {
+ return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
+ }
+
+ NonLoc makeIntVal(uint64_t X, unsigned BitWidth, bool isUnsigned) {
+ return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
+ }
+
+ NonLoc makeLocAsInteger(Loc V, unsigned Bits) {
+ return nonloc::LocAsInteger(BasicVals.getPersistentSValWithData(V, Bits));
+ }
+
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const llvm::APSInt& rhs, QualType T);
NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const SymExpr *rhs, QualType T);
- NonLoc makeTruthVal(bool b, QualType T);
+ NonLoc makeTruthVal(bool b, QualType T) {
+ return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T));
+ }
+
+ NonLoc makeTruthVal(bool b) {
+ return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
+ }
+
+ Loc makeNull() {
+ return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
+ }
+
+ Loc makeLoc(SymbolRef Sym) {
+ return loc::MemRegionVal(MemMgr.getSymbolicRegion(Sym));
+ }
+
+ Loc makeLoc(const MemRegion* R) {
+ return loc::MemRegionVal(R);
+ }
+
+ Loc makeLoc(const AddrLabelExpr* E) {
+ return loc::GotoLabel(E->getLabel());
+ }
+
+ Loc makeLoc(const llvm::APSInt& V) {
+ return loc::ConcreteInt(BasicVals.getValue(V));
+ }
};
} // end clang namespace
#endif
// FIXME: Investigate what is using this. This method should be removed.
virtual Loc getLoc(const VarDecl* VD) {
- return Loc::MakeVal(MRMgr.getVarRegion(VD));
+ return ValMgr.makeLoc(MRMgr.getVarRegion(VD));
}
const GRState *BindCompoundLiteral(const GRState *state,
}
SVal BasicStoreManager::getLValueVar(const GRState *state, const VarDecl* VD) {
- return Loc::MakeVal(MRMgr.getVarRegion(VD));
+ return ValMgr.makeLoc(MRMgr.getVarRegion(VD));
}
SVal BasicStoreManager::getLValueString(const GRState *state,
const StringLiteral* S) {
- return Loc::MakeVal(MRMgr.getStringRegion(S));
+ return ValMgr.makeLoc(MRMgr.getStringRegion(S));
}
SVal BasicStoreManager::getLValueCompoundLiteral(const GRState *state,
const CompoundLiteralExpr* CL){
- return Loc::MakeVal(MRMgr.getCompoundLiteralRegion(CL));
+ return ValMgr.makeLoc(MRMgr.getCompoundLiteralRegion(CL));
}
SVal BasicStoreManager::getLValueIvar(const GRState *state, const ObjCIvarDecl* D,
const MemRegion *BaseR = cast<loc::MemRegionVal>(BaseL).getRegion();
if (BaseR == SelfRegion)
- return loc::MemRegionVal(MRMgr.getObjCIvarRegion(D, BaseR));
+ return ValMgr.makeLoc(MRMgr.getObjCIvarRegion(D, BaseR));
}
return UnknownVal();
return Base;
}
- return Loc::MakeVal(MRMgr.getFieldRegion(D, BaseR));
+ return ValMgr.makeLoc(MRMgr.getFieldRegion(D, BaseR));
}
SVal BasicStoreManager::getLValueElement(const GRState *state,
}
if (BaseR)
- return Loc::MakeVal(MRMgr.getElementRegion(elementType, UnknownVal(),
- BaseR, getContext()));
+ return ValMgr.makeLoc(MRMgr.getElementRegion(elementType, UnknownVal(),
+ BaseR, getContext()));
else
return UnknownVal();
}
const MemRegion* R = I.getKey();
if (!Marked.count(R)) {
- store = Remove(store, Loc::MakeVal(R));
+ store = Remove(store, ValMgr.makeLoc(R));
SVal X = I.getData();
for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
const MemRegion *IVR = MRMgr.getObjCIvarRegion(IV->getDecl(),
SelfRegion);
SVal X = ValMgr.getRegionValueSymbolVal(IVR);
- St = BindInternal(St, Loc::MakeVal(IVR), X);
+ St = BindInternal(St, ValMgr.makeLoc(IVR), X);
}
}
}
SelfRegion = MRMgr.getObjCObjectRegion(MD->getClassInterface(),
MRMgr.getHeapRegion());
- St = BindInternal(St, Loc::MakeVal(MRMgr.getVarRegion(PD)),
- Loc::MakeVal(SelfRegion));
+ St = BindInternal(St, ValMgr.makeLoc(MRMgr.getVarRegion(PD)),
+ ValMgr.makeLoc(SelfRegion));
// Scan the method for ivar references. While this requires an
// entire AST scan, the cost should not be high in practice.
? ValMgr.getRegionValueSymbolVal(R)
: UndefinedVal();
- St = BindInternal(St, Loc::MakeVal(R), X);
+ St = BindInternal(St, ValMgr.makeLoc(R), X);
}
}
return St;
if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())){
ValueManager &ValMgr = Eng.getValueManager();
SVal V = ValMgr.getConjuredSymbolVal(*I, T, Count);
- state = state->bindLoc(Loc::MakeVal(R), V);
+ state = state->bindLoc(ValMgr.makeLoc(R), V);
}
else if (const RecordType *RT = T->getAsStructureType()) {
// Handle structs in a not so awesome way. Here we just
const FieldRegion* FR = MRMgr.getFieldRegion(FD, R);
SVal V = ValMgr.getConjuredSymbolVal(*I, FT, Count);
- state = state->bindLoc(Loc::MakeVal(FR), V);
+ state = state->bindLoc(ValMgr.makeLoc(FR), V);
}
}
} else if (const ArrayType *AT = Ctx.getAsArrayType(T)) {
QualType RetT = GetReturnType(Ex, ValMgr.getContext());
state = state->set<RefBindings>(Sym, RefVal::makeOwned(RE.getObjKind(),
RetT));
- state = state->bindExpr(Ex, ValMgr.makeRegionVal(Sym), false);
+ state = state->bindExpr(Ex, ValMgr.makeLoc(Sym), false);
// FIXME: Add a flag to the checker where allocations are assumed to
// *not fail.
QualType RetT = GetReturnType(Ex, ValMgr.getContext());
state = state->set<RefBindings>(Sym, RefVal::makeNotOwned(RE.getObjKind(),
RetT));
- state = state->bindExpr(Ex, ValMgr.makeRegionVal(Sym), false);
+ state = state->bindExpr(Ex, ValMgr.makeLoc(Sym), false);
break;
}
}
using namespace clang;
-SVal Environment::GetSVal(const Stmt *E, BasicValueFactory& BasicVals) const {
+SVal Environment::GetSVal(const Stmt *E, ValueManager& ValMgr) const {
for (;;) {
switch (E->getStmtClass()) {
case Stmt::AddrLabelExprClass:
- return Loc::MakeVal(cast<AddrLabelExpr>(E));
+ return ValMgr.makeLoc(cast<AddrLabelExpr>(E));
// ParenExprs are no-ops.
case Stmt::CharacterLiteralClass: {
const CharacterLiteral* C = cast<CharacterLiteral>(E);
- return NonLoc::MakeVal(BasicVals, C->getValue(), C->getType());
+ return ValMgr.makeIntVal(C->getValue(), C->getType());
}
case Stmt::IntegerLiteralClass: {
- return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
+ return ValMgr.makeIntVal(cast<IntegerLiteral>(E));
}
// Casts where the source and target type are the same
return LookupExpr(E);
}
-SVal Environment::GetBlkExprSVal(const Stmt *E,
- BasicValueFactory& BasicVals) const {
+SVal Environment::GetBlkExprSVal(const Stmt *E, ValueManager& ValMgr) const {
while (1) {
switch (E->getStmtClass()) {
case Stmt::CharacterLiteralClass: {
const CharacterLiteral* C = cast<CharacterLiteral>(E);
- return NonLoc::MakeVal(BasicVals, C->getValue(), C->getType());
+ return ValMgr.makeIntVal(C->getValue(), C->getType());
}
case Stmt::IntegerLiteralClass: {
- return NonLoc::MakeVal(BasicVals, cast<IntegerLiteral>(E));
+ return ValMgr.makeIntVal(cast<IntegerLiteral>(E));
}
default:
// this right now, and since most logical expressions are used for branches,
// the payoff is not likely to be large. Instead, we do eager evaluation.
if (const GRState *newState = state->assume(X, true))
- MakeNode(Dst, B, Pred, newState->bindBlkExpr(B, MakeConstantVal(1U, B)));
+ MakeNode(Dst, B, Pred,
+ newState->bindBlkExpr(B, ValMgr.makeIntVal(1U, B->getType())));
if (const GRState *newState = state->assume(X, false))
- MakeNode(Dst, B, Pred, newState->bindBlkExpr(B, MakeConstantVal(0U, B)));
+ MakeNode(Dst, B, Pred,
+ newState->bindBlkExpr(B, ValMgr.makeIntVal(0U, B->getType())));
}
else {
// We took the LHS expression. Depending on whether we are '&&' or
// '||' we know what the value of the expression is via properties of
// the short-circuiting.
- X = MakeConstantVal( B->getOpcode() == BinaryOperator::LAnd ? 0U : 1U, B);
+ X = ValMgr.makeIntVal(B->getOpcode() == BinaryOperator::LAnd ? 0U : 1U,
+ B->getType());
MakeNode(Dst, B, Pred, state->bindBlkExpr(B, X));
}
}
if (isa<nonloc::SymExprVal>(V)) {
// First assume that the condition is true.
if (const GRState *stateTrue = state->assume(V, true)) {
- stateTrue = stateTrue->bindExpr(Ex, MakeConstantVal(1U, Ex));
+ stateTrue = stateTrue->bindExpr(Ex,
+ ValMgr.makeIntVal(1U, Ex->getType()));
Dst.Add(Builder->generateNode(PostStmtCustom(Ex, &EagerlyAssumeTag),
stateTrue, Pred));
}
// Next, assume that the condition is false.
if (const GRState *stateFalse = state->assume(V, false)) {
- stateFalse = stateFalse->bindExpr(Ex, MakeConstantVal(0U, Ex));
+ stateFalse = stateFalse->bindExpr(Ex,
+ ValMgr.makeIntVal(0U, Ex->getType()));
Dst.Add(Builder->generateNode(PostStmtCustom(Ex, &EagerlyAssumeTag),
stateFalse, Pred));
}
const GRState *state = GetState(Pred);
// Handle the case where the container still has elements.
- QualType IntTy = getContext().IntTy;
- SVal TrueV = NonLoc::MakeVal(getBasicVals(), 1, IntTy);
+ SVal TrueV = ValMgr.makeTruthVal(1);
const GRState *hasElems = state->bindExpr(S, TrueV);
// Handle the case where the container has no elements.
- SVal FalseV = NonLoc::MakeVal(getBasicVals(), 0, IntTy);
+ SVal FalseV = ValMgr.makeTruthVal(0);
const GRState *noElems = state->bindExpr(S, FalseV);
if (loc::MemRegionVal* MV = dyn_cast<loc::MemRegionVal>(&ElementV))
assert (Loc::IsLocType(T));
unsigned Count = Builder->getCurrentBlockCount();
SymbolRef Sym = SymMgr.getConjuredSymbol(elem, T, Count);
- SVal V = Loc::MakeVal(getStoreManager().getRegionManager().getSymbolicRegion(Sym));
+ SVal V = ValMgr.makeLoc(Sym);
hasElems = hasElems->bindLoc(ElementV, V);
// Bind the location to 'nil' on the false branch.
- SVal nilV = loc::ConcreteInt(getBasicVals().getValue(0, T));
+ SVal nilV = ValMgr.makeIntVal(0, T);
noElems = noElems->bindLoc(ElementV, nilV);
}
// Handle base case where the initializer has no elements.
// e.g: static int* myArray[] = {};
if (NumInitElements == 0) {
- SVal V = NonLoc::MakeCompoundVal(T, StartVals, getBasicVals());
+ SVal V = ValMgr.makeCompoundVal(T, StartVals);
MakeNode(Dst, E, Pred, state->bindExpr(E, V));
return;
}
if (NewItr == ItrEnd) {
// Now we have a list holding all init values. Make CompoundValData.
- SVal V = NonLoc::MakeCompoundVal(T, NewVals, getBasicVals());
+ SVal V = ValMgr.makeCompoundVal(T, NewVals);
// Make final state and node.
MakeNode(Dst, E, *NI, state->bindExpr(E, V));
amt = getContext().getTypeAlign(T) / 8;
MakeNode(Dst, Ex, Pred,
- GetState(Pred)->bindExpr(Ex, NonLoc::MakeVal(getBasicVals(), amt,
- Ex->getType())));
+ GetState(Pred)->bindExpr(Ex, ValMgr.makeIntVal(amt, Ex->getType())));
}
// For all other types, UnaryOperator::Float returns 0.
assert (Ex->getType()->isIntegerType());
const GRState* state = GetState(*I);
- SVal X = NonLoc::MakeVal(getBasicVals(), 0, Ex->getType());
+ SVal X = ValMgr.makeZeroVal(Ex->getType());
MakeNode(Dst, U, *I, state->bindExpr(U, X));
}
// transfer functions as "0 == E".
if (isa<Loc>(V)) {
- Loc X = Loc::MakeNull(getBasicVals());
+ Loc X = ValMgr.makeNull();
SVal Result = EvalBinOp(state,BinaryOperator::EQ, cast<Loc>(V), X,
U->getType());
state = state->bindExpr(U, Result);
BinaryOperator::Opcode Op = U->isIncrementOp() ? BinaryOperator::Add
: BinaryOperator::Sub;
- SVal Result = EvalBinOp(state, Op, V2, MakeConstantVal(1U, U),
+ SVal Result = EvalBinOp(state, Op, V2, ValMgr.makeIntVal(1U,U->getType()),
U->getType());
// Conjure a new symbol if necessary to recover precision.
unsigned BitWidth = Eng.getContext().getTypeSize(T);
if (!isa<loc::ConcreteInt>(X))
- return nonloc::LocAsInteger::Make(BasicVals, X, BitWidth);
+ return Eng.getValueManager().makeLocAsInteger(X, BitWidth);
llvm::APSInt V = cast<loc::ConcreteInt>(X).getValue();
V.setIsUnsigned(T->isUnsignedIntegerType() || Loc::IsLocType(T));
BinaryOperator::Opcode Op,
NonLoc L, NonLoc R,
QualType T) {
-
BasicValueFactory& BasicVals = Eng.getBasicVals();
+ ValueManager& ValMgr = Eng.getValueManager();
unsigned subkind = L.getSubKind();
while (1) {
llvm::APSInt V = cast<nonloc::ConcreteInt>(R).getValue();
V.setIsUnsigned(true);
V.extOrTrunc(Ctx.getTypeSize(Ctx.VoidPtrTy));
- return EvalBinOp(Eng, Op, LL,
- loc::ConcreteInt(BasicVals.getValue(V)));
+ return EvalBinOp(Eng, Op, LL, ValMgr.makeLoc(V));
}
default:
switch (Op) {
case BinaryOperator::EQ:
- return NonLoc::MakeIntTruthVal(BasicVals, false);
+ return ValMgr.makeTruthVal(false);
case BinaryOperator::NE:
- return NonLoc::MakeIntTruthVal(BasicVals, true);
+ return ValMgr.makeTruthVal(true);
default:
// This case also handles pointer arithmetic.
return UnknownVal();
SVal GRSimpleVals::EvalEquality(GRExprEngine& Eng, Loc L, Loc R, bool isEqual) {
- BasicValueFactory& BasicVals = Eng.getBasicVals();
+ ValueManager& ValMgr = Eng.getValueManager();
switch (L.getSubKind()) {
if (!isEqual)
b = !b;
- return NonLoc::MakeIntTruthVal(BasicVals, b);
+ return ValMgr.makeTruthVal(b);
}
else if (SymbolRef Sym = R.getAsSymbol()) {
const SymIntExpr * SE =
// Fall-through.
case loc::GotoLabelKind:
- return NonLoc::MakeIntTruthVal(BasicVals, isEqual ? L == R : L != R);
+ return ValMgr.makeTruthVal(isEqual ? L == R : L != R);
}
- return NonLoc::MakeIntTruthVal(BasicVals, isEqual ? false : true);
+ return ValMgr.makeTruthVal(isEqual ? false : true);
}
//===----------------------------------------------------------------------===//
if (OffI.isUnsigned()) {
llvm::APSInt Tmp = OffI;
Tmp.setIsSigned(true);
- Offset = NonLoc::MakeVal(getBasicVals(), Tmp);
+ Offset = ValMgr.makeIntVal(Tmp);
}
}
return loc::MemRegionVal(MRMgr.getElementRegion(elementType, Offset,
Tmp.setIsSigned(true);
Tmp += BaseIdxI; // Compute the new offset.
- NewIdx = NonLoc::MakeVal(getBasicVals(), Tmp);
+ NewIdx = ValMgr.makeIntVal(Tmp);
}
else
NewIdx = nonloc::ConcreteInt(getBasicVals().getValue(BaseIdxI + OffI));
if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T)) {
// return the size as signed integer.
- return NonLoc::MakeVal(getBasicVals(), CAT->getSize(), false);
+ return ValMgr.makeIntVal(CAT->getSize(), false);
}
const QualType* CastTy = state->get<RegionCasts>(VR);
uint64_t EleSize = getContext().getTypeSize(EleTy);
uint64_t VarSize = getContext().getTypeSize(VarTy);
assert(VarSize != 0);
- return NonLoc::MakeIntVal(getBasicVals(), VarSize / EleSize, false);
+ return ValMgr.makeIntVal(VarSize/EleSize, false);
}
// Clients can use ordinary variables as if they were arrays. These
// essentially are arrays of size 1.
- return NonLoc::MakeIntVal(getBasicVals(), 1, false);
+ return ValMgr.makeIntVal(1, false);
}
if (const StringRegion* SR = dyn_cast<StringRegion>(R)) {
const StringLiteral* Str = SR->getStringLiteral();
// We intentionally made the size value signed because it participates in
// operations with signed indices.
- return NonLoc::MakeIntVal(getBasicVals(), Str->getByteLength()+1, false);
+ return ValMgr.makeIntVal(Str->getByteLength()+1, false);
}
if (const FieldRegion* FR = dyn_cast<FieldRegion>(R)) {
const MemRegion* NewER =
MRMgr.getElementRegion(ER->getElementType(), NewIdx,ER->getSuperRegion(),
getContext());
- return Loc::MakeVal(NewER);
+ return ValMgr.makeLoc(NewER);
}
StructVal = getBasicVals().consVals(FieldValue, StructVal);
}
- return NonLoc::MakeCompoundVal(T, StructVal, getBasicVals());
+ return ValMgr.makeCompoundVal(T, StructVal);
}
SVal RegionStoreManager::RetrieveArray(const GRState *state,
llvm::APSInt i = getBasicVals().getZeroWithPtrWidth(false);
for (; i < Size; ++i) {
- SVal Idx = NonLoc::MakeVal(getBasicVals(), i);
+ SVal Idx = ValMgr.makeIntVal(i);
ElementRegion* ER = MRMgr.getElementRegion(CAT->getElementType(), Idx, R,
getContext());
QualType ETy = ER->getElementType();
ArrayVal = getBasicVals().consVals(ElementVal, ArrayVal);
}
- return NonLoc::MakeCompoundVal(T, ArrayVal, getBasicVals());
+ return ValMgr.makeCompoundVal(T, ArrayVal);
}
//===----------------------------------------------------------------------===//
if (T->isStructureType())
return BindStruct(state, VR, InitVal);
- return Bind(state, Loc::MakeVal(VR), InitVal);
+ return Bind(state, ValMgr.makeLoc(VR), InitVal);
}
// FIXME: this method should be merged into Bind().
SVal Idx = ValMgr.makeIntVal(i);
ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx,R,getContext());
- SVal V = NonLoc::MakeVal(getBasicVals(), str[j], sizeof(char)*8, true);
+ SVal V = ValMgr.makeIntVal(str[j], sizeof(char)*8, true);
state = Bind(state, loc::MemRegionVal(ER), V);
}
if (CAT->getElementType()->isStructureType())
state = BindStruct(state, ER, *VI);
else
- state = Bind(state, Loc::MakeVal(ER), *VI);
+ state = Bind(state, ValMgr.makeLoc(ER), *VI);
}
// If the init list is shorter than the array length, bind the rest elements
SVal Idx = ValMgr.makeIntVal(i);
ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx,R,getContext());
SVal V = ValMgr.makeZeroVal(ElementTy);
- state = Bind(state, Loc::MakeVal(ER), V);
+ state = Bind(state, ValMgr.makeLoc(ER), V);
++i;
}
}
FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
if (Loc::IsLocType(FTy) || FTy->isIntegerType())
- state = Bind(state, Loc::MakeVal(FR), *VI);
+ state = Bind(state, ValMgr.makeLoc(FR), *VI);
else if (FTy->isArrayType())
state = BindArray(state, FR, *VI);
else if (FTy->isStructureType())
QualType FTy = (*FI)->getType();
if (FTy->isIntegerType()) {
FieldRegion* FR = MRMgr.getFieldRegion(*FI, R);
- state = Bind(state, Loc::MakeVal(FR), ValMgr.makeZeroVal(FTy));
+ state = Bind(state, ValMgr.makeLoc(FR), ValMgr.makeZeroVal(FTy));
}
++FI;
const MemRegion* R = I.getKey();
if (const SubRegion* subRegion = dyn_cast<SubRegion>(R))
if (subRegion->isSubRegionOf(R))
- store = Remove(store, Loc::MakeVal(subRegion));
+ store = Remove(store, ValMgr.makeLoc(subRegion));
// FIXME: Maybe we should also remove the bindings for the "views" of the
// subregions.
}
continue;
// Remove this dead region from the store.
- store = Remove(store, Loc::MakeVal(R));
+ store = Remove(store, ValMgr.makeLoc(R));
// Mark all non-live symbols that this region references as dead.
if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(R))
return UndefinedVal();
}
-
-NonLoc NonLoc::MakeIntVal(BasicValueFactory& BasicVals, uint64_t X,
- bool isUnsigned) {
- return nonloc::ConcreteInt(BasicVals.getIntValue(X, isUnsigned));
-}
-
-NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X,
- unsigned BitWidth, bool isUnsigned) {
- return nonloc::ConcreteInt(BasicVals.getValue(X, BitWidth, isUnsigned));
-}
-
-NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, uint64_t X, QualType T) {
- return nonloc::ConcreteInt(BasicVals.getValue(X, T));
-}
-
-NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const IntegerLiteral* I) {
-
- return nonloc::ConcreteInt(BasicVals.getValue(APSInt(I->getValue(),
- I->getType()->isUnsignedIntegerType())));
-}
-
-NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APInt& I,
- bool isUnsigned) {
- return nonloc::ConcreteInt(BasicVals.getValue(I, isUnsigned));
-}
-
-NonLoc NonLoc::MakeVal(BasicValueFactory& BasicVals, const llvm::APSInt& I) {
- return nonloc::ConcreteInt(BasicVals.getValue(I));
-}
-
-NonLoc NonLoc::MakeIntTruthVal(BasicValueFactory& BasicVals, bool b) {
- return nonloc::ConcreteInt(BasicVals.getTruthValue(b));
-}
-
-
-NonLoc NonLoc::MakeCompoundVal(QualType T, llvm::ImmutableList<SVal> Vals,
- BasicValueFactory& BasicVals) {
- return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
-}
-
-nonloc::LocAsInteger nonloc::LocAsInteger::Make(BasicValueFactory& Vals, Loc V,
- unsigned Bits) {
- return LocAsInteger(Vals.getPersistentSValWithData(V, Bits));
-}
-
-//===----------------------------------------------------------------------===//
-// Utility methods for constructing Locs.
-//===----------------------------------------------------------------------===//
-
-Loc Loc::MakeVal(const MemRegion* R) { return loc::MemRegionVal(R); }
-
-Loc Loc::MakeVal(const AddrLabelExpr *E) {
- return loc::GotoLabel(E->getLabel());
-}
-
-Loc Loc::MakeNull(BasicValueFactory &BasicVals) {
- return loc::ConcreteInt(BasicVals.getZeroWithPtrWidth());
-}
-
//===----------------------------------------------------------------------===//
// Pretty-Printing.
//===----------------------------------------------------------------------===//
SVal ValueManager::makeZeroVal(QualType T) {
if (Loc::IsLocType(T))
- return Loc::MakeNull(BasicVals);
+ return makeNull();
if (T->isIntegerType())
- return NonLoc::MakeVal(BasicVals, 0, T);
+ return makeIntVal(0, T);
// FIXME: Handle floats.
// FIXME: Handle structs.
return UnknownVal();
}
-SVal ValueManager::makeZeroArrayIndex() {
- return nonloc::ConcreteInt(BasicVals.getZeroWithPtrWidth(false));
-}
-
//===----------------------------------------------------------------------===//
// Utility methods for constructing Non-Locs.
//===----------------------------------------------------------------------===//
-NonLoc ValueManager::makeNonLoc(SymbolRef sym) {
- return nonloc::SymbolVal(sym);
-}
-
-NonLoc ValueManager::makeIntVal(const APSInt& V) {
- return nonloc::ConcreteInt(BasicVals.getValue(V));
-}
-
NonLoc ValueManager::makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op,
const APSInt& v, QualType T) {
// The Environment ensures we always get a persistent APSInt in
return nonloc::SymExprVal(SymMgr.getSymSymExpr(lhs, op, rhs, T));
}
-NonLoc ValueManager::makeTruthVal(bool b, QualType T) {
- return nonloc::ConcreteInt(BasicVals.getTruthValue(b, T));
-}
SVal ValueManager::getRegionValueSymbolVal(const MemRegion* R, QualType T) {
SymbolRef sym = SymMgr.getRegionValueSymbol(R, T);
// If T is of function pointer type, create a CodeTextRegion wrapping a
// symbol.
if (T->isFunctionPointerType()) {
- return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
+ return loc::MemRegionVal(MemMgr.getCodeTextRegion(sym, T));
}
if (Loc::IsLocType(T))
- return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
+ return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
// Only handle integers for now.
if (T->isIntegerType() && T->isScalarType())
- return makeNonLoc(sym);
+ return nonloc::SymbolVal(sym);
}
return UnknownVal();
// If T is of function pointer type, create a CodeTextRegion wrapping a
// symbol.
if (T->isFunctionPointerType()) {
- return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
+ return loc::MemRegionVal(MemMgr.getCodeTextRegion(sym, T));
}
if (Loc::IsLocType(T))
- return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
+ return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
if (T->isIntegerType() && T->isScalarType())
- return makeNonLoc(sym);
+ return nonloc::SymbolVal(sym);
return UnknownVal();
}
// If T is of function pointer type, create a CodeTextRegion wrapping a
// symbol.
if (T->isFunctionPointerType()) {
- return Loc::MakeVal(MemMgr.getCodeTextRegion(sym, T));
+ return loc::MemRegionVal(MemMgr.getCodeTextRegion(sym, T));
}
if (Loc::IsLocType(T))
- return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
+ return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym));
if (T->isIntegerType() && T->isScalarType())
- return makeNonLoc(sym);
+ return nonloc::SymbolVal(sym);
return UnknownVal();
}
= MemMgr.getCodeTextRegion(FD, Context.getPointerType(FD->getType()));
return loc::MemRegionVal(R);
}
-