aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Core
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2011-02-19 01:59:33 +0000
committerTed Kremenek <kremenek@apple.com>2011-02-19 01:59:33 +0000
commit77a4d5687c2cb3199c689892c9d040a94ff270af (patch)
tree2de2bb3aebfd7f4c982d64744324c6a486ccd830 /lib/StaticAnalyzer/Core
parent7ff07dce18a7c693fe1a15bd7b790d8de9d21e92 (diff)
Add 'StoreRef' smart pointer to allow more fine-grain memory lifetime control of Store objects.
This yields a minor memory reduction (for larger functions) on Sqlite at the cost of slightly higher memory usage on some functions because of the increased size of GRState (which can be optimized). I expect the real memory savings from this enhancement will come when we aggressively canabilize more of the ExplodedGraph. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126012 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/StaticAnalyzer/Core')
-rw-r--r--lib/StaticAnalyzer/Core/BasicStore.cpp156
-rw-r--r--lib/StaticAnalyzer/Core/FlatStore.cpp69
-rw-r--r--lib/StaticAnalyzer/Core/GRState.cpp64
-rw-r--r--lib/StaticAnalyzer/Core/RegionStore.cpp187
-rw-r--r--lib/StaticAnalyzer/Core/Store.cpp10
5 files changed, 258 insertions, 228 deletions
diff --git a/lib/StaticAnalyzer/Core/BasicStore.cpp b/lib/StaticAnalyzer/Core/BasicStore.cpp
index 987e790585..98365e7f4e 100644
--- a/lib/StaticAnalyzer/Core/BasicStore.cpp
+++ b/lib/StaticAnalyzer/Core/BasicStore.cpp
@@ -48,24 +48,25 @@ public:
SVal Retrieve(Store store, Loc loc, QualType T = QualType());
- Store invalidateRegion(Store store, const MemRegion *R, const Expr *E,
- unsigned Count, InvalidatedSymbols *IS);
+ StoreRef invalidateRegion(Store store, const MemRegion *R, const Expr *E,
+ unsigned Count, InvalidatedSymbols *IS);
- Store invalidateRegions(Store store, const MemRegion * const *Begin,
- const MemRegion * const *End, const Expr *E,
- unsigned Count, InvalidatedSymbols *IS,
- bool invalidateGlobals, InvalidatedRegions *Regions);
+ StoreRef invalidateRegions(Store store, const MemRegion * const *Begin,
+ const MemRegion * const *End, const Expr *E,
+ unsigned Count, InvalidatedSymbols *IS,
+ bool invalidateGlobals,
+ InvalidatedRegions *Regions);
- Store scanForIvars(Stmt *B, const Decl* SelfDecl,
- const MemRegion *SelfRegion, Store St);
+ StoreRef scanForIvars(Stmt *B, const Decl* SelfDecl,
+ const MemRegion *SelfRegion, Store St);
- Store Bind(Store St, Loc loc, SVal V);
- Store Remove(Store St, Loc loc);
- Store getInitialStore(const LocationContext *InitLoc);
+ StoreRef Bind(Store St, Loc loc, SVal V);
+ StoreRef Remove(Store St, Loc loc);
+ StoreRef getInitialStore(const LocationContext *InitLoc);
- Store BindCompoundLiteral(Store store, const CompoundLiteralExpr*,
+ StoreRef BindCompoundLiteral(Store store, const CompoundLiteralExpr*,
const LocationContext*, SVal val) {
- return store;
+ return StoreRef(store, *this);
}
/// ArrayToPointer - Used by ExprEngine::VistCast to handle implicit
@@ -74,21 +75,21 @@ public:
/// removeDeadBindings - Scans a BasicStore of 'state' for dead values.
/// It updatees the GRState object in place with the values removed.
- Store removeDeadBindings(Store store, const StackFrameContext *LCtx,
- SymbolReaper& SymReaper,
+ StoreRef removeDeadBindings(Store store, const StackFrameContext *LCtx,
+ SymbolReaper& SymReaper,
llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
void iterBindings(Store store, BindingsHandler& f);
- Store BindDecl(Store store, const VarRegion *VR, SVal InitVal) {
+ StoreRef BindDecl(Store store, const VarRegion *VR, SVal InitVal) {
return BindDeclInternal(store, VR, &InitVal);
}
- Store BindDeclWithNoInit(Store store, const VarRegion *VR) {
+ StoreRef BindDeclWithNoInit(Store store, const VarRegion *VR) {
return BindDeclInternal(store, VR, 0);
}
- Store BindDeclInternal(Store store, const VarRegion *VR, SVal *InitVal);
+ StoreRef BindDeclInternal(Store store, const VarRegion *VR, SVal *InitVal);
static inline BindingsTy GetBindings(Store store) {
return BindingsTy(static_cast<const BindingsTy::TreeTy*>(store));
@@ -210,9 +211,9 @@ SVal BasicStoreManager::Retrieve(Store store, Loc loc, QualType T) {
return UnknownVal();
}
-Store BasicStoreManager::Bind(Store store, Loc loc, SVal V) {
+StoreRef BasicStoreManager::Bind(Store store, Loc loc, SVal V) {
if (isa<loc::ConcreteInt>(loc))
- return store;
+ return StoreRef(store, *this);
const MemRegion* R = cast<loc::MemRegionVal>(loc).getRegion();
@@ -220,7 +221,7 @@ Store BasicStoreManager::Bind(Store store, Loc loc, SVal V) {
// that is used to derive other symbols.
if (isa<NonStaticGlobalSpaceRegion>(R)) {
BindingsTy B = GetBindings(store);
- return VBFactory.add(B, R, V).getRoot();
+ return StoreRef(VBFactory.add(B, R, V).getRoot(), *this);
}
// Special case: handle store of pointer values (Loc) to pointers via
@@ -236,14 +237,14 @@ Store BasicStoreManager::Bind(Store store, Loc loc, SVal V) {
}
if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R) || isa<CXXThisRegion>(R)))
- return store;
+ return StoreRef(store, *this);
const TypedRegion *TyR = cast<TypedRegion>(R);
// Do not bind to arrays. We need to explicitly check for this so that
// we do not encounter any weirdness of trying to load/store from arrays.
if (TyR->isBoundable() && TyR->getValueType()->isArrayType())
- return store;
+ return StoreRef(store, *this);
if (nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(&V)) {
// Only convert 'V' to a location iff the underlying region type
@@ -257,31 +258,31 @@ Store BasicStoreManager::Bind(Store store, Loc loc, SVal V) {
}
BindingsTy B = GetBindings(store);
- return V.isUnknown()
- ? VBFactory.remove(B, R).getRoot()
- : VBFactory.add(B, R, V).getRoot();
+ return StoreRef(V.isUnknown()
+ ? VBFactory.remove(B, R).getRoot()
+ : VBFactory.add(B, R, V).getRoot(), *this);
}
-Store BasicStoreManager::Remove(Store store, Loc loc) {
+StoreRef BasicStoreManager::Remove(Store store, Loc loc) {
switch (loc.getSubKind()) {
case loc::MemRegionKind: {
const MemRegion* R = cast<loc::MemRegionVal>(loc).getRegion();
if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R) ||
isa<CXXThisRegion>(R)))
- return store;
+ return StoreRef(store, *this);
- return VBFactory.remove(GetBindings(store), R).getRoot();
+ return StoreRef(VBFactory.remove(GetBindings(store), R).getRoot(), *this);
}
default:
assert ("Remove for given Loc type not yet implemented.");
- return store;
+ return StoreRef(store, *this);
}
}
-Store BasicStoreManager::removeDeadBindings(Store store,
- const StackFrameContext *LCtx,
- SymbolReaper& SymReaper,
+StoreRef BasicStoreManager::removeDeadBindings(Store store,
+ const StackFrameContext *LCtx,
+ SymbolReaper& SymReaper,
llvm::SmallVectorImpl<const MemRegion*>& RegionRoots)
{
BindingsTy B = GetBindings(store);
@@ -347,11 +348,12 @@ Store BasicStoreManager::removeDeadBindings(Store store,
}
// Remove dead variable bindings.
+ StoreRef newStore(store, *this);
for (BindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) {
const MemRegion* R = I.getKey();
if (!Marked.count(R)) {
- store = Remove(store, svalBuilder.makeLoc(R));
+ newStore = Remove(newStore.getStore(), svalBuilder.makeLoc(R));
SVal X = I.getData();
for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI)
@@ -359,11 +361,15 @@ Store BasicStoreManager::removeDeadBindings(Store store,
}
}
- return store;
+ return newStore;
}
-Store BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl,
- const MemRegion *SelfRegion, Store St) {
+StoreRef BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl,
+ const MemRegion *SelfRegion,
+ Store St) {
+
+ StoreRef newStore(St, *this);
+
for (Stmt::child_iterator CI=B->child_begin(), CE=B->child_end();
CI != CE; ++CI) {
@@ -379,24 +385,24 @@ Store BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl,
const ObjCIvarRegion *IVR = MRMgr.getObjCIvarRegion(IV->getDecl(),
SelfRegion);
SVal X = svalBuilder.getRegionValueSymbolVal(IVR);
- St = Bind(St, svalBuilder.makeLoc(IVR), X);
+ newStore = Bind(newStore.getStore(), svalBuilder.makeLoc(IVR), X);
}
}
}
else
- St = scanForIvars(*CI, SelfDecl, SelfRegion, St);
+ newStore = scanForIvars(*CI, SelfDecl, SelfRegion, newStore.getStore());
}
- return St;
+ return newStore;
}
-Store BasicStoreManager::getInitialStore(const LocationContext *InitLoc) {
+StoreRef BasicStoreManager::getInitialStore(const LocationContext *InitLoc) {
// The LiveVariables information already has a compilation of all VarDecls
// used in the function. Iterate through this set, and "symbolicate"
// any VarDecl whose value originally comes from outside the function.
typedef LiveVariables::AnalysisDataTy LVDataTy;
LVDataTy& D = InitLoc->getLiveVariables()->getAnalysisData();
- Store St = VBFactory.getEmptyMap().getRoot();
+ StoreRef St(VBFactory.getEmptyMap().getRoot(), *this);
for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
const NamedDecl* ND = I->first;
@@ -412,10 +418,11 @@ Store BasicStoreManager::getInitialStore(const LocationContext *InitLoc) {
const MemRegion *SelfRegion =
svalBuilder.getRegionValueSymbolVal(VR).getAsRegion();
assert(SelfRegion);
- St = Bind(St, svalBuilder.makeLoc(VR), loc::MemRegionVal(SelfRegion));
+ St = Bind(St.getStore(), svalBuilder.makeLoc(VR),
+ loc::MemRegionVal(SelfRegion));
// Scan the method for ivar references. While this requires an
// entire AST scan, the cost should not be high in practice.
- St = scanForIvars(MD->getBody(), PD, SelfRegion, St);
+ St = scanForIvars(MD->getBody(), PD, SelfRegion, St.getStore());
}
}
}
@@ -427,22 +434,23 @@ Store BasicStoreManager::getInitialStore(const LocationContext *InitLoc) {
MemRegionManager &RegMgr = svalBuilder.getRegionManager();
const CXXThisRegion *ThisR = RegMgr.getCXXThisRegion(ThisT, InitLoc);
SVal ThisV = svalBuilder.getRegionValueSymbolVal(ThisR);
- St = Bind(St, svalBuilder.makeLoc(ThisR), ThisV);
+ St = Bind(St.getStore(), svalBuilder.makeLoc(ThisR), ThisV);
}
return St;
}
-Store BasicStoreManager::BindDeclInternal(Store store, const VarRegion* VR,
- SVal* InitVal) {
+StoreRef BasicStoreManager::BindDeclInternal(Store store, const VarRegion* VR,
+ SVal* InitVal) {
BasicValueFactory& BasicVals = StateMgr.getBasicVals();
const VarDecl *VD = VR->getDecl();
+ StoreRef newStore(store, *this);
// BasicStore does not model arrays and structs.
if (VD->getType()->isArrayType() || VD->getType()->isStructureOrClassType())
- return store;
-
+ return newStore;
+
if (VD->hasGlobalStorage()) {
// Handle variables with global storage: extern, static, PrivateExtern.
@@ -465,13 +473,13 @@ Store BasicStoreManager::BindDeclInternal(Store store, const VarRegion* VR,
if (!InitVal) {
QualType T = VD->getType();
if (Loc::isLocType(T))
- store = Bind(store, loc::MemRegionVal(VR),
- loc::ConcreteInt(BasicVals.getValue(0, T)));
+ newStore = Bind(store, loc::MemRegionVal(VR),
+ loc::ConcreteInt(BasicVals.getValue(0, T)));
else if (T->isIntegerType() && T->isScalarType())
- store = Bind(store, loc::MemRegionVal(VR),
- nonloc::ConcreteInt(BasicVals.getValue(0, T)));
+ newStore = Bind(store, loc::MemRegionVal(VR),
+ nonloc::ConcreteInt(BasicVals.getValue(0, T)));
} else {
- store = Bind(store, loc::MemRegionVal(VR), *InitVal);
+ newStore = Bind(store, loc::MemRegionVal(VR), *InitVal);
}
}
} else {
@@ -481,11 +489,11 @@ Store BasicStoreManager::BindDeclInternal(Store store, const VarRegion* VR,
if ((T->isScalarType() || T->isReferenceType()) &&
svalBuilder.getSymbolManager().canSymbolicate(T)) {
SVal V = InitVal ? *InitVal : UndefinedVal();
- store = Bind(store, loc::MemRegionVal(VR), V);
+ newStore = Bind(store, loc::MemRegionVal(VR), V);
}
}
- return store;
+ return newStore;
}
void BasicStoreManager::print(Store store, llvm::raw_ostream& Out,
@@ -523,19 +531,21 @@ StoreManager::BindingsHandler::~BindingsHandler() {}
//===----------------------------------------------------------------------===//
-Store BasicStoreManager::invalidateRegions(Store store,
- const MemRegion * const *I,
- const MemRegion * const *End,
- const Expr *E, unsigned Count,
- InvalidatedSymbols *IS,
- bool invalidateGlobals,
- InvalidatedRegions *Regions) {
+StoreRef BasicStoreManager::invalidateRegions(Store store,
+ const MemRegion * const *I,
+ const MemRegion * const *End,
+ const Expr *E, unsigned Count,
+ InvalidatedSymbols *IS,
+ bool invalidateGlobals,
+ InvalidatedRegions *Regions) {
+ StoreRef newStore(store, *this);
+
if (invalidateGlobals) {
BindingsTy B = GetBindings(store);
for (BindingsTy::iterator I=B.begin(), End=B.end(); I != End; ++I) {
const MemRegion *R = I.getKey();
if (isa<NonStaticGlobalSpaceRegion>(R->getMemorySpace()))
- store = invalidateRegion(store, R, E, Count, IS);
+ newStore = invalidateRegion(newStore.getStore(), R, E, Count, IS);
}
}
@@ -546,7 +556,7 @@ Store BasicStoreManager::invalidateRegions(Store store,
if (isa<NonStaticGlobalSpaceRegion>(R->getMemorySpace()))
continue;
}
- store = invalidateRegion(store, *I, E, Count, IS);
+ newStore = invalidateRegion(newStore.getStore(), *I, E, Count, IS);
if (Regions)
Regions->push_back(R);
}
@@ -561,24 +571,24 @@ Store BasicStoreManager::invalidateRegions(Store store,
/* symbol type, doesn't matter */ Ctx.IntTy,
Count);
- store = Bind(store, loc::MemRegionVal(GS), V);
+ newStore = Bind(newStore.getStore(), loc::MemRegionVal(GS), V);
if (Regions)
Regions->push_back(GS);
}
- return store;
+ return newStore;
}
-Store BasicStoreManager::invalidateRegion(Store store,
- const MemRegion *R,
- const Expr *E,
- unsigned Count,
- InvalidatedSymbols *IS) {
+StoreRef BasicStoreManager::invalidateRegion(Store store,
+ const MemRegion *R,
+ const Expr *E,
+ unsigned Count,
+ InvalidatedSymbols *IS) {
R = R->StripCasts();
if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R)))
- return store;
+ return StoreRef(store, *this);
if (IS) {
BindingsTy B = GetBindings(store);
diff --git a/lib/StaticAnalyzer/Core/FlatStore.cpp b/lib/StaticAnalyzer/Core/FlatStore.cpp
index c3da72af5a..99a5eadaca 100644
--- a/lib/StaticAnalyzer/Core/FlatStore.cpp
+++ b/lib/StaticAnalyzer/Core/FlatStore.cpp
@@ -31,13 +31,13 @@ public:
BVFactory(mgr.getAllocator()) {}
SVal Retrieve(Store store, Loc L, QualType T);
- Store Bind(Store store, Loc L, SVal val);
- Store Remove(Store St, Loc L);
- Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* cl,
+ StoreRef Bind(Store store, Loc L, SVal val);
+ StoreRef Remove(Store St, Loc L);
+ StoreRef BindCompoundLiteral(Store store, const CompoundLiteralExpr* cl,
const LocationContext *LC, SVal v);
- Store getInitialStore(const LocationContext *InitLoc) {
- return RBFactory.getEmptyMap().getRoot();
+ StoreRef getInitialStore(const LocationContext *InitLoc) {
+ return StoreRef(RBFactory.getEmptyMap().getRoot(), *this);
}
SubRegionMap *getSubRegionMap(Store store) {
@@ -45,22 +45,23 @@ public:
}
SVal ArrayToPointer(Loc Array);
- Store removeDeadBindings(Store store, const StackFrameContext *LCtx,
- SymbolReaper& SymReaper,
- llvm::SmallVectorImpl<const MemRegion*>& RegionRoots){
- return store;
+ StoreRef removeDeadBindings(Store store, const StackFrameContext *LCtx,
+ SymbolReaper& SymReaper,
+ llvm::SmallVectorImpl<const MemRegion*>& RegionRoots){
+ return StoreRef(store, *this);
}
- Store BindDecl(Store store, const VarRegion *VR, SVal initVal);
+ StoreRef BindDecl(Store store, const VarRegion *VR, SVal initVal);
- Store BindDeclWithNoInit(Store store, const VarRegion *VR);
+ StoreRef BindDeclWithNoInit(Store store, const VarRegion *VR);
typedef llvm::DenseSet<SymbolRef> InvalidatedSymbols;
- Store invalidateRegions(Store store, const MemRegion * const *I,
- const MemRegion * const *E, const Expr *Ex,
- unsigned Count, InvalidatedSymbols *IS,
- bool invalidateGlobals, InvalidatedRegions *Regions);
+ StoreRef invalidateRegions(Store store, const MemRegion * const *I,
+ const MemRegion * const *E, const Expr *Ex,
+ unsigned Count, InvalidatedSymbols *IS,
+ bool invalidateGlobals,
+ InvalidatedRegions *Regions);
void print(Store store, llvm::raw_ostream& Out, const char* nl,
const char *sep);
@@ -115,7 +116,7 @@ SVal FlatStoreManager::RetrieveRegionWithNoBinding(const MemRegion *R,
return svalBuilder.getRegionValueSymbolVal(cast<TypedRegion>(R));
}
-Store FlatStoreManager::Bind(Store store, Loc L, SVal val) {
+StoreRef FlatStoreManager::Bind(Store store, Loc L, SVal val) {
const MemRegion *R = cast<loc::MemRegionVal>(L).getRegion();
RegionBindings B = getRegionBindings(store);
const BindingVal *V = B.lookup(R);
@@ -127,45 +128,45 @@ Store FlatStoreManager::Bind(Store store, Loc L, SVal val) {
RegionInterval RI = RegionToInterval(R);
// FIXME: FlatStore should handle regions with unknown intervals.
if (!RI.R)
- return B.getRoot();
+ return StoreRef(B.getRoot(), *this);
BV = BVFactory.add(BV, RI.I, val);
B = RBFactory.add(B, RI.R, BV);
- return B.getRoot();
+ return StoreRef(B.getRoot(), *this);
}
-Store FlatStoreManager::Remove(Store store, Loc L) {
- return store;
+StoreRef FlatStoreManager::Remove(Store store, Loc L) {
+ return StoreRef(store, *this);
}
-Store FlatStoreManager::BindCompoundLiteral(Store store,
+StoreRef FlatStoreManager::BindCompoundLiteral(Store store,
const CompoundLiteralExpr* cl,
const LocationContext *LC,
SVal v) {
- return store;
+ return StoreRef(store, *this);
}
SVal FlatStoreManager::ArrayToPointer(Loc Array) {
return Array;
}
-Store FlatStoreManager::BindDecl(Store store, const VarRegion *VR,
- SVal initVal) {
+StoreRef FlatStoreManager::BindDecl(Store store, const VarRegion *VR,
+ SVal initVal) {
return Bind(store, svalBuilder.makeLoc(VR), initVal);
}
-Store FlatStoreManager::BindDeclWithNoInit(Store store, const VarRegion *VR) {
- return store;
+StoreRef FlatStoreManager::BindDeclWithNoInit(Store store, const VarRegion *VR){
+ return StoreRef(store, *this);
}
-Store FlatStoreManager::invalidateRegions(Store store,
- const MemRegion * const *I,
- const MemRegion * const *E,
- const Expr *Ex, unsigned Count,
- InvalidatedSymbols *IS,
- bool invalidateGlobals,
- InvalidatedRegions *Regions) {
+StoreRef FlatStoreManager::invalidateRegions(Store store,
+ const MemRegion * const *I,
+ const MemRegion * const *E,
+ const Expr *Ex, unsigned Count,
+ InvalidatedSymbols *IS,
+ bool invalidateGlobals,
+ InvalidatedRegions *Regions) {
assert(false && "Not implemented");
- return store;
+ return StoreRef(store, *this);
}
void FlatStoreManager::print(Store store, llvm::raw_ostream& Out,
diff --git a/lib/StaticAnalyzer/Core/GRState.cpp b/lib/StaticAnalyzer/Core/GRState.cpp
index 80c8bbf195..7defecb366 100644
--- a/lib/StaticAnalyzer/Core/GRState.cpp
+++ b/lib/StaticAnalyzer/Core/GRState.cpp
@@ -53,7 +53,7 @@ GRStateManager::removeDeadBindings(const GRState* state,
state, RegionRoots);
// Clean up the store.
- NewState.St = StoreMgr->removeDeadBindings(NewState.St, LCtx,
+ NewState.St = StoreMgr->removeDeadBindings(NewState.getStore(), LCtx,
SymReaper, RegionRoots);
state = getPersistentState(NewState);
return ConstraintMgr->removeDeadBindings(state, SymReaper);
@@ -73,38 +73,39 @@ const GRState *GRStateManager::MarshalState(const GRState *state,
const GRState *GRState::bindCompoundLiteral(const CompoundLiteralExpr* CL,
const LocationContext *LC,
SVal V) const {
- Store new_store =
- getStateManager().StoreMgr->BindCompoundLiteral(St, CL, LC, V);
- return makeWithStore(new_store);
+ const StoreRef &newStore =
+ getStateManager().StoreMgr->BindCompoundLiteral(getStore(), CL, LC, V);
+ return makeWithStore(newStore);
}
const GRState *GRState::bindDecl(const VarRegion* VR, SVal IVal) const {
- Store new_store = getStateManager().StoreMgr->BindDecl(St, VR, IVal);
- return makeWithStore(new_store);
+ const StoreRef &newStore =
+ getStateManager().StoreMgr->BindDecl(getStore(), VR, IVal);
+ return makeWithStore(newStore);
}
const GRState *GRState::bindDeclWithNoInit(const VarRegion* VR) const {
- Store new_store = getStateManager().StoreMgr->BindDeclWithNoInit(St, VR);
- return makeWithStore(new_store);
+ const StoreRef &newStore =
+ getStateManager().StoreMgr->BindDeclWithNoInit(getStore(), VR);
+ return makeWithStore(newStore);
}
const GRState *GRState::bindLoc(Loc LV, SVal V) const {
GRStateManager &Mgr = getStateManager();
- Store new_store = Mgr.StoreMgr->Bind(St, LV, V);
- const GRState *new_state = makeWithStore(new_store);
-
+ const GRState *newState = makeWithStore(Mgr.StoreMgr->Bind(getStore(),
+ LV, V));
const MemRegion *MR = LV.getAsRegion();
if (MR && Mgr.getOwningEngine())
- return Mgr.getOwningEngine()->processRegionChange(new_state, MR);
+ return Mgr.getOwningEngine()->processRegionChange(newState, MR);
- return new_state;
+ return newState;
}
const GRState *GRState::bindDefault(SVal loc, SVal V) const {
GRStateManager &Mgr = getStateManager();
const MemRegion *R = cast<loc::MemRegionVal>(loc).getRegion();
- Store new_store = Mgr.StoreMgr->BindDefault(St, R, V);
- const GRState *new_state = makeWithStore(new_store);
+ const StoreRef &newStore = Mgr.StoreMgr->BindDefault(getStore(), R, V);
+ const GRState *new_state = makeWithStore(newStore);
return Mgr.getOwningEngine() ?
Mgr.getOwningEngine()->processRegionChange(new_state, R) :
new_state;
@@ -120,39 +121,36 @@ const GRState *GRState::invalidateRegions(const MemRegion * const *Begin,
if (Eng && Eng->wantsRegionChangeUpdate(this)) {
StoreManager::InvalidatedRegions Regions;
-
- Store new_store = Mgr.StoreMgr->invalidateRegions(St, Begin, End,
- E, Count, IS,
- invalidateGlobals,
- &Regions);
- const GRState *new_state = makeWithStore(new_store);
-
- return Eng->processRegionChanges(new_state,
+ const StoreRef &newStore
+ = Mgr.StoreMgr->invalidateRegions(getStore(), Begin, End, E, Count, IS,
+ invalidateGlobals, &Regions);
+ const GRState *newState = makeWithStore(newStore);
+ return Eng->processRegionChanges(newState,
&Regions.front(),
&Regions.back()+1);
}
- Store new_store = Mgr.StoreMgr->invalidateRegions(St, Begin, End,
- E, Count, IS,
- invalidateGlobals,
- NULL);
- return makeWithStore(new_store);
+ const StoreRef &newStore =
+ Mgr.StoreMgr->invalidateRegions(getStore(), Begin, End, E, Count, IS,
+ invalidateGlobals, NULL);
+ return makeWithStore(newStore);
}
const GRState *GRState::unbindLoc(Loc LV) const {
assert(!isa<loc::MemRegionVal>(LV) && "Use invalidateRegion instead.");
Store OldStore = getStore();
- Store NewStore = getStateManager().StoreMgr->Remove(OldStore, LV);
+ const StoreRef &newStore = getStateManager().StoreMgr->Remove(OldStore, LV);
- if (NewStore == OldStore)
+ if (newStore.getStore() == OldStore)
return this;
- return makeWithStore(NewStore);
+ return makeWithStore(newStore);
}
const GRState *GRState::enterStackFrame(const StackFrameContext *frame) const {
- Store new_store = getStateManager().StoreMgr->enterStackFrame(this, frame);
+ const StoreRef &new_store =
+ getStateManager().StoreMgr->enterStackFrame(this, frame);
return makeWithStore(new_store);
}
@@ -323,7 +321,7 @@ const GRState* GRStateManager::getPersistentState(GRState& State) {
return newState;
}
-const GRState* GRState::makeWithStore(Store store) const {
+const GRState* GRState::makeWithStore(const StoreRef &store) const {
GRState NewSt = *this;
NewSt.St = store;
return getStateManager().getPersistentState(NewSt);
diff --git a/lib/StaticAnalyzer/Core/RegionStore.cpp b/lib/StaticAnalyzer/Core/RegionStore.cpp
index dc31715ccb..19e0e12572 100644
--- a/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -215,7 +215,7 @@ public:
/// setImplicitDefaultValue - Set the default binding for the provided
/// MemRegion to the value implicitly defined for compound literals when
/// the value is not specified.
- Store setImplicitDefaultValue(Store store, const MemRegion *R, QualType T);
+ StoreRef setImplicitDefaultValue(Store store, const MemRegion *R, QualType T);
/// ArrayToPointer - Emulates the "decay" of an array to a pointer
/// type. 'Array' represents the lvalue of the array being decayed
@@ -228,21 +228,21 @@ public:
/// For DerivedToBase casts, create a CXXBaseObjectRegion and return it.
virtual SVal evalDerivedToBase(SVal derived, QualType basePtrType);
- Store getInitialStore(const LocationContext *InitLoc) {
- return RBFactory.getEmptyMap().getRoot();
+ StoreRef getInitialStore(const LocationContext *InitLoc) {
+ return StoreRef(RBFactory.getEmptyMap().getRootWithoutRetain(), *this);
}
//===-------------------------------------------------------------------===//
// Binding values to regions.
//===-------------------------------------------------------------------===//
- Store invalidateRegions(Store store,
- const MemRegion * const *Begin,
- const MemRegion * const *End,
- const Expr *E, unsigned Count,
- InvalidatedSymbols *IS,
- bool invalidateGlobals,
- InvalidatedRegions *Regions);
+ StoreRef invalidateRegions(Store store,
+ const MemRegion * const *Begin,
+ const MemRegion * const *End,
+ const Expr *E, unsigned Count,
+ InvalidatedSymbols *IS,
+ bool invalidateGlobals,
+ InvalidatedRegions *Regions);
public: // Made public for helper classes.
@@ -268,35 +268,45 @@ public: // Made public for helper classes.
public: // Part of public interface to class.
- Store Bind(Store store, Loc LV, SVal V);
+ StoreRef Bind(Store store, Loc LV, SVal V);
// BindDefault is only used to initialize a region with a default value.
- Store BindDefault(Store store, const MemRegion *R, SVal V) {
+ StoreRef BindDefault(Store store, const MemRegion *R, SVal V) {
RegionBindings B = GetRegionBindings(store);
assert(!lookup(B, R, BindingKey::Default));
assert(!lookup(B, R, BindingKey::Direct));
- return addBinding(B, R, BindingKey::Default, V).getRoot();
+ return StoreRef(addBinding(B, R, BindingKey::Default, V).getRootWithoutRetain(), *this);
}
- Store BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL,
- const LocationContext *LC, SVal V);
+ StoreRef BindCompoundLiteral(Store store, const CompoundLiteralExpr* CL,
+ const LocationContext *LC, SVal V);
- Store BindDecl(Store store, const VarRegion *VR, SVal InitVal);
+ StoreRef BindDecl(Store store, const VarRegion *VR, SVal InitVal);
- Store BindDeclWithNoInit(Store store, const VarRegion *) {
- return store;
+ StoreRef BindDeclWithNoInit(Store store, const VarRegion *) {
+ return StoreRef(store, *this);
}
/// BindStruct - Bind a compound value to a structure.
- Store BindStruct(Store store, const TypedRegion* R, SVal V);
+ StoreRef BindStruct(Store store, const TypedRegion* R, SVal V);
- Store BindArray(Store store, const TypedRegion* R, SVal V);
+ StoreRef BindArray(Store store, const TypedRegion* R, SVal V);
/// KillStruct - Set the entire struct to unknown.
- Store KillStruct(Store store, const TypedRegion* R, SVal DefaultVal);
+ StoreRef KillStruct(Store store, const TypedRegion* R, SVal DefaultVal);
- Store Remove(Store store, Loc LV);
+ StoreRef Remove(Store store, Loc LV);
+ void incrementReferenceCount(Store store) {
+ GetRegionBindings(store).manualRetain();
+ }
+
+ /// If the StoreManager supports it, decrement the reference count of
+ /// the specified Store object. If the reference count hits 0, the memory
+ /// associated with the object is recycled.
+ void decrementReferenceCount(Store store) {
+ GetRegionBindings(store).manualRelease();
+ }
//===------------------------------------------------------------------===//
// Loading values from regions.
@@ -347,8 +357,8 @@ public: // Part of public interface to class.
std::pair<Store, const MemRegion*>
GetLazyBinding(RegionBindings B, const MemRegion *R);
- Store CopyLazyBindings(nonloc::LazyCompoundVal V, Store store,
- const TypedRegion *R);
+ StoreRef CopyLazyBindings(nonloc::LazyCompoundVal V, Store store,
+ const TypedRegion *R);
//===------------------------------------------------------------------===//
// State pruning.
@@ -356,11 +366,11 @@ public: // Part of public interface to class.
/// removeDeadBindings - Scans the RegionStore of 'state' for dead values.
/// It returns a new Store with these values removed.
- Store removeDeadBindings(Store store, const StackFrameContext *LCtx,
+ StoreRef removeDeadBindings(Store store, const StackFrameContext *LCtx,
SymbolReaper& SymReaper,
llvm::SmallVectorImpl<const MemRegion*>& RegionRoots);
- Store enterStackFrame(const GRState *state, const StackFrameContext *frame);
+ StoreRef enterStackFrame(const GRState *state, const StackFrameContext *frame);
//===------------------------------------------------------------------===//
// Region "extents".
@@ -706,13 +716,13 @@ void invalidateRegionsWorker::VisitBaseRegion(const MemRegion *baseR) {
B = RM.addBinding(B, baseR, BindingKey::Direct, V);
}
-Store RegionStoreManager::invalidateRegions(Store store,
- const MemRegion * const *I,
- const MemRegion * const *E,
- const Expr *Ex, unsigned Count,
- InvalidatedSymbols *IS,
- bool invalidateGlobals,
- InvalidatedRegions *Regions) {
+StoreRef RegionStoreManager::invalidateRegions(Store store,
+ const MemRegion * const *I,
+ const MemRegion * const *E,
+ const Expr *Ex, unsigned Count,
+ InvalidatedSymbols *IS,
+ bool invalidateGlobals,
+ InvalidatedRegions *Regions) {
invalidateRegionsWorker W(*this, StateMgr,
RegionStoreManager::GetRegionBindings(store),
Ex, Count, IS, Regions, invalidateGlobals);
@@ -745,7 +755,7 @@ Store RegionStoreManager::invalidateRegions(Store store,
Regions->push_back(GS);
}
- return B.getRoot();
+ return StoreRef(B.getRootWithoutRetain(), *this);
}
//===----------------------------------------------------------------------===//
@@ -1252,17 +1262,19 @@ SVal RegionStoreManager::RetrieveArray(Store store, const TypedRegion * R) {
// Binding values to regions.
//===----------------------------------------------------------------------===//
-Store RegionStoreManager::Remove(Store store, Loc L) {
+StoreRef RegionStoreManager::Remove(Store store, Loc L) {
if (isa<loc::MemRegionVal>(L))
if (const MemRegion* R = cast<loc::MemRegionVal>(L).getRegion())
- return removeBinding(GetRegionBindings(store), R).getRoot();
+ return StoreRef(removeBinding(GetRegionBindings(store),
+ R).getRootWithoutRetain(),
+ *this);
- return store;
+ return StoreRef(store, *this);
}
-Store RegionStoreManager::Bind(Store store, Loc L, SVal V) {
+StoreRef RegionStoreManager::Bind(Store store, Loc L, SVal V) {
if (isa<loc::ConcreteInt>(L))
- return store;
+ return StoreRef(store, *this);
// If we get here, the location should be a region.
const MemRegion *R = cast<loc::MemRegionVal>(L).getRegion();
@@ -1301,11 +1313,12 @@ Store RegionStoreManager::Bind(Store store, Loc L, SVal V) {
// Perform the binding.
RegionBindings B = GetRegionBindings(store);
- return addBinding(B, R, BindingKey::Direct, V).getRoot();
+ return StoreRef(addBinding(B, R, BindingKey::Direct,
+ V).getRootWithoutRetain(), *this);
}
-Store RegionStoreManager::BindDecl(Store store, const VarRegion *VR,
- SVal InitVal) {
+StoreRef RegionStoreManager::BindDecl(Store store, const VarRegion *VR,
+ SVal InitVal) {
QualType T = VR->getDecl()->getType();
@@ -1318,18 +1331,17 @@ Store RegionStoreManager::BindDecl(Store store, const VarRegion *VR,
}
// FIXME: this method should be merged into Bind().
-Store RegionStoreManager::BindCompoundLiteral(Store store,
- const CompoundLiteralExpr *CL,