Liveness(L) {
StoreMgr.reset((*CreateStoreManager)(*this));
ConstraintMgr.reset((*CreateConstraintManager)(*this));
-
- // FIXME: Have ValueMgr own the MemRegionManager, not StoreManager.
- ValueMgr.setRegionManager(StoreMgr->getRegionManager());
}
~GRStateManager();
return !(*this == R);
}
- /// GetRValueSymbolVal - make a unique symbol for value of R.
- static SVal GetRValueSymbolVal(SymbolManager& SymMgr, MemRegionManager& MRMgr,
- const MemRegion* R);
-
- static SVal GetConjuredSymbolVal(SymbolManager& SymMgr, MemRegionManager&,
- const Expr *E, unsigned Count);
- static SVal GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager&,
- const Expr* E, QualType T, unsigned Count);
-
inline bool isUnknown() const {
return getRawKind() == UnknownKind;
}
#include "clang/Analysis/PathSensitive/SVals.h"
#include "clang/Analysis/PathSensitive/MemRegion.h"
+#include "clang/Analysis/PathSensitive/ValueManager.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/DenseSet.h"
class StoreManager {
protected:
+ ValueManager &ValMgr;
+
/// MRMgr - Manages region objects associated with this StoreManager.
- MemRegionManager MRMgr;
+ MemRegionManager &MRMgr;
- StoreManager(llvm::BumpPtrAllocator& Alloc) : MRMgr(Alloc) {}
+ StoreManager(ValueManager &valMgr)
+ : ValMgr(valMgr), MRMgr(ValMgr.getRegionManager()) {}
public:
virtual ~StoreManager() {}
#include "clang/Analysis/PathSensitive/SymbolManager.h"
namespace llvm { class BumpPtrAllocator; }
-namespace clang { class GRStateManager; }
namespace clang {
class ValueManager {
- friend class GRStateManager;
ASTContext &Context;
BasicValueFactory BasicVals;
/// SymMgr - Object that manages the symbol information.
SymbolManager SymMgr;
- // FIXME: Eventually ValueManager will own this object.
- MemRegionManager *MemMgr;
- void setRegionManager(MemRegionManager& mm) { MemMgr = &mm; }
+ MemRegionManager MemMgr;
public:
ValueManager(llvm::BumpPtrAllocator &alloc, ASTContext &context)
: Context(context), BasicVals(Context, alloc),
SymMgr(Context, BasicVals, alloc),
- MemMgr(0) {}
+ MemMgr(alloc) {}
// Accessors to submanagers.
SymbolManager &getSymbolManager() { return SymMgr; }
const SymbolManager &getSymbolManager() const { return SymMgr; }
- MemRegionManager &getRegionManager() { return *MemMgr; }
- const MemRegionManager &getRegionManager() const { return *MemMgr; }
+ MemRegionManager &getRegionManager() { return MemMgr; }
+ const MemRegionManager &getRegionManager() const { return MemMgr; }
// Forwarding methods to SymbolManager.
// Aggregation methods that use multiple submanagers.
Loc makeRegionVal(SymbolRef Sym) {
- return Loc::MakeVal(MemMgr->getSymbolicRegion(Sym));
+ return Loc::MakeVal(MemMgr.getSymbolicRegion(Sym));
}
/// makeZeroVal - Construct an SVal representing '0' for the specified type.
SVal makeZeroVal(QualType T);
+
+ /// GetRValueSymbolVal - make a unique symbol for value of R.
+ SVal getRValueSymbolVal(const MemRegion* R);
+
+ SVal getConjuredSymbolVal(const Expr *E, unsigned Count);
+ SVal getConjuredSymbolVal(const Expr* E, QualType T, unsigned Count);
};
} // end clang namespace
#endif
public:
BasicStoreManager(GRStateManager& mgr)
- : StoreManager(mgr.getAllocator()),
+ : StoreManager(mgr.getValueManager()),
VBFactory(mgr.getAllocator()),
StateMgr(mgr),
SelfRegion(0) {}
if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Base)) {
if (DR->getDecl() == SelfDecl) {
const MemRegion *IVR = MRMgr.getObjCIvarRegion(IV->getDecl(),
- SelfRegion);
-
- SVal X = SVal::GetRValueSymbolVal(StateMgr.getSymbolManager(),
- MRMgr, IVR);
-
+ SelfRegion);
+ SVal X = ValMgr.getRValueSymbolVal(IVR);
St = BindInternal(St, Loc::MakeVal(IVR), X);
}
}
const MemRegion *R = StateMgr.getRegion(VD);
SVal X = (VD->hasGlobalStorage() || isa<ParmVarDecl>(VD) ||
isa<ImplicitParamDecl>(VD))
- ? SVal::GetRValueSymbolVal(StateMgr.getSymbolManager(), MRMgr,R)
+ ? ValMgr.getRValueSymbolVal(R)
: UndefinedVal();
St = BindInternal(St, Loc::MakeVal(R), X);
QualType T = R->getRValueType(Ctx);
if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())){
- SVal V = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
- Eng.getStoreManager().getRegionManager(), *I, T, Count);
+ ValueManager &ValMgr = Eng.getValueManager();
+ SVal V = ValMgr.getConjuredSymbolVal(*I, T, Count);
state = state.BindLoc(Loc::MakeVal(R), V);
}
else if (const RecordType *RT = T->getAsStructureType()) {
QualType FT = FD->getType();
if (Loc::IsLocType(FT) ||
- (FT->isIntegerType() && FT->isScalarType())) {
-
+ (FT->isIntegerType() && FT->isScalarType())) {
const FieldRegion* FR = MRMgr.getFieldRegion(FD, R);
-
- SVal V = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
- Eng.getStoreManager().getRegionManager(), *I, FT, Count);
-
+ ValueManager &ValMgr = Eng.getValueManager();
+ SVal V = ValMgr.getConjuredSymbolVal(*I, FT, Count);
state = state.BindLoc(Loc::MakeVal(FR), V);
}
}
if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) {
unsigned Count = Builder.getCurrentBlockCount();
- SVal X = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
- Eng.getStoreManager().getRegionManager(), Ex, T, Count);
+ ValueManager &ValMgr = Eng.getValueManager();
+ SVal X = ValMgr.getConjuredSymbolVal(Ex, T, Count);
state = state.BindExpr(Ex, X, false);
}
// UnknownVal.
if (InitVal.isUnknown() ||
!getConstraintManager().canReasonAbout(InitVal)) {
- InitVal = SVal::GetConjuredSymbolVal(SymMgr,
- getStoreManager().getRegionManager(), InitEx, Count);
+ InitVal = ValMgr.getConjuredSymbolVal(InitEx, Count);
}
state = StateMgr.BindDecl(state, VD, InitVal);
// Conjure a new symbol if necessary to recover precision.
if (Result.isUnknown() || !getConstraintManager().canReasonAbout(Result))
- Result = SVal::GetConjuredSymbolVal(SymMgr,
- getStoreManager().getRegionManager(),Ex,
- Builder->getCurrentBlockCount());
+ Result = ValMgr.getConjuredSymbolVal(Ex,
+ Builder->getCurrentBlockCount());
state = BindExpr(state, U, U->isPostfix() ? V2 : Result);
!getConstraintManager().canReasonAbout(RightV))
&& (Loc::IsLocType(T) ||
(T->isScalarType() && T->isIntegerType()))) {
- unsigned Count = Builder->getCurrentBlockCount();
-
- RightV = SVal::GetConjuredSymbolVal(SymMgr,
- getStoreManager().getRegionManager(), B->getRHS(), Count);
+ unsigned Count = Builder->getCurrentBlockCount();
+ RightV = ValMgr.getConjuredSymbolVal(B->getRHS(), Count);
}
// Simulate the effects of a "store": bind the value of the RHS
// The symbolic value is actually for the type of the left-hand side
// expression, not the computation type, as this is the value the
// LValue on the LHS will bind to.
- LHSVal = SVal::GetConjuredSymbolVal(SymMgr,
- getStoreManager().getRegionManager(), B->getRHS(), LTy, Count);
+ LHSVal = ValMgr.getConjuredSymbolVal(B->getRHS(), LTy, Count);
// However, we need to convert the symbol to the computation type.
Result = (LTy == CTy) ? LHSVal : EvalCast(LHSVal,CTy);
QualType T = CE->getType();
if (Loc::IsLocType(T) || (T->isIntegerType() && T->isScalarType())) {
unsigned Count = Builder.getCurrentBlockCount();
-
- SVal X = SVal::GetConjuredSymbolVal(Eng.getSymbolManager(),
- Eng.getStoreManager().getRegionManager(), CE, Count);
-
+ SVal X = Eng.getValueManager().getConjuredSymbolVal(CE, Count);
St = StateMgr.BindExpr(St, CE, X, Eng.getCFG().isBlkExpr(CE), false);
}
public:
RegionStoreManager(GRStateManager& mgr)
- : StoreManager(mgr.getAllocator()),
+ : StoreManager(mgr.getValueManager()),
RBFactory(mgr.getAllocator()),
RVFactory(mgr.getAllocator()),
StateMgr(mgr), SelfRegion(0), SelfDecl(0) {
virtual ~RegionStoreManager() {}
- MemRegionManager& getRegionManager() { return MRMgr; }
-
SubRegionMap* getSubRegionMap(const GRState *state);
const GRState* BindCompoundLiteral(const GRState* St,
if (SR == SelfRegion) {
// FIXME: Do we need to handle the case where the super region
// has a view? We want to canonicalize the bindings.
- return SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, R);
+ return ValMgr.getRValueSymbolVal(R);
}
// Otherwise, we need a new symbol. For now return Unknown.
VD->hasGlobalStorage()) {
QualType VTy = VD->getType();
if (Loc::IsLocType(VTy) || VTy->isIntegerType())
- return SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, VR);
+ return ValMgr.getRValueSymbolVal(VR);
else
return UnknownVal();
}
// All other integer values are symbolic.
if (Loc::IsLocType(RTy) || RTy->isIntegerType())
- return SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, R);
+ return ValMgr.getRValueSymbolVal(R);
else
return UnknownVal();
}
if (MRMgr.onStack(FR) || MRMgr.onHeap(FR))
FieldValue = UndefinedVal();
else
- FieldValue = SVal::GetRValueSymbolVal(getSymbolManager(), MRMgr, FR);
+ FieldValue = ValMgr.getRValueSymbolVal(FR);
}
StructVal = getBasicVals().consVals(FieldValue, StructVal);
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
}
-SVal SVal::GetRValueSymbolVal(SymbolManager& SymMgr, MemRegionManager& MRMgr,
- const MemRegion* R) {
+SVal ValueManager::getRValueSymbolVal(const MemRegion* R) {
SymbolRef sym = SymMgr.getRegionRValueSymbol(R);
if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) {
QualType T = TR->getRValueType(SymMgr.getContext());
if (Loc::IsLocType(T))
- return Loc::MakeVal(MRMgr.getSymbolicRegion(sym));
+ return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
// Only handle integers for now.
if (T->isIntegerType() && T->isScalarType())
return UnknownVal();
}
-SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager& MRMgr,
- const Expr* E, unsigned Count) {
+SVal ValueManager::getConjuredSymbolVal(const Expr* E, unsigned Count) {
QualType T = E->getType();
SymbolRef sym = SymMgr.getConjuredSymbol(E, Count);
if (Loc::IsLocType(T))
- return Loc::MakeVal(MRMgr.getSymbolicRegion(sym));
+ return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
if (T->isIntegerType() && T->isScalarType())
return NonLoc::MakeVal(sym);
return UnknownVal();
}
-SVal SVal::GetConjuredSymbolVal(SymbolManager &SymMgr, MemRegionManager& MRMgr,
- const Expr* E, QualType T, unsigned Count) {
+SVal ValueManager::getConjuredSymbolVal(const Expr* E, QualType T,
+ unsigned Count) {
+
SymbolRef sym = SymMgr.getConjuredSymbol(E, T, Count);
if (Loc::IsLocType(T))
- return Loc::MakeVal(MRMgr.getSymbolicRegion(sym));
+ return Loc::MakeVal(MemMgr.getSymbolicRegion(sym));
if (T->isIntegerType() && T->isScalarType())
return NonLoc::MakeVal(sym);