[cfe-commits] r95354 - in /cfe/trunk: include/clang/Checker/PathSensitive/BasicValueFactory.h include/clang/Checker/PathSensitive/SVals.h include/clang/Checker/PathSensitive/ValueManager.h lib/Checker/BasicValueFactory.cpp lib/Checker/RegionStore.cpp lib/Checker/SVals.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Thu Feb 4 18:26:30 PST 2010
Author: zhongxingxu
Date: Thu Feb 4 20:26:30 2010
New Revision: 95354
URL: http://llvm.org/viewvc/llvm-project?rev=95354&view=rev
Log:
Change LazyCompoundVal to a <Store, MemRegion*> pair. We really don't need to
spread GRState* everywhere.
Modified:
cfe/trunk/include/clang/Checker/PathSensitive/BasicValueFactory.h
cfe/trunk/include/clang/Checker/PathSensitive/SVals.h
cfe/trunk/include/clang/Checker/PathSensitive/ValueManager.h
cfe/trunk/lib/Checker/BasicValueFactory.cpp
cfe/trunk/lib/Checker/RegionStore.cpp
cfe/trunk/lib/Checker/SVals.cpp
Modified: cfe/trunk/include/clang/Checker/PathSensitive/BasicValueFactory.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/BasicValueFactory.h?rev=95354&r1=95353&r2=95354&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/BasicValueFactory.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/BasicValueFactory.h Thu Feb 4 20:26:30 2010
@@ -46,19 +46,19 @@
};
class LazyCompoundValData : public llvm::FoldingSetNode {
- const GRState *state;
+ const void *store;
const TypedRegion *region;
public:
- LazyCompoundValData(const GRState *st, const TypedRegion *r)
- : state(st), region(r) {}
+ LazyCompoundValData(const void *st, const TypedRegion *r)
+ : store(st), region(r) {}
- const GRState *getState() const { return state; }
+ const void *getStore() const { return store; }
const TypedRegion *getRegion() const { return region; }
- static void Profile(llvm::FoldingSetNodeID& ID, const GRState *state,
+ static void Profile(llvm::FoldingSetNodeID& ID, const void *store,
const TypedRegion *region);
- void Profile(llvm::FoldingSetNodeID& ID) { Profile(ID, state, region); }
+ void Profile(llvm::FoldingSetNodeID& ID) { Profile(ID, store, region); }
};
class BasicValueFactory {
@@ -169,7 +169,7 @@
const CompoundValData *getCompoundValData(QualType T,
llvm::ImmutableList<SVal> Vals);
- const LazyCompoundValData *getLazyCompoundValData(const GRState *state,
+ const LazyCompoundValData *getLazyCompoundValData(const void *store,
const TypedRegion *region);
llvm::ImmutableList<SVal> getEmptySValList() {
Modified: cfe/trunk/include/clang/Checker/PathSensitive/SVals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/SVals.h?rev=95354&r1=95353&r2=95354&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/SVals.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/SVals.h Thu Feb 4 20:26:30 2010
@@ -388,7 +388,7 @@
const LazyCompoundValData *getCVData() const {
return static_cast<const LazyCompoundValData*>(Data);
}
- const GRState *getState() const;
+ const void *getStore() const;
const TypedRegion *getRegion() const;
static bool classof(const SVal *V) {
Modified: cfe/trunk/include/clang/Checker/PathSensitive/ValueManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Checker/PathSensitive/ValueManager.h?rev=95354&r1=95353&r2=95354&view=diff
==============================================================================
--- cfe/trunk/include/clang/Checker/PathSensitive/ValueManager.h (original)
+++ cfe/trunk/include/clang/Checker/PathSensitive/ValueManager.h Thu Feb 4 20:26:30 2010
@@ -115,8 +115,8 @@
return nonloc::CompoundVal(BasicVals.getCompoundValData(T, Vals));
}
- NonLoc makeLazyCompoundVal(const GRState *state, const TypedRegion *R) {
- return nonloc::LazyCompoundVal(BasicVals.getLazyCompoundValData(state, R));
+ NonLoc makeLazyCompoundVal(const void *store, const TypedRegion *R) {
+ return nonloc::LazyCompoundVal(BasicVals.getLazyCompoundValData(store, R));
}
NonLoc makeZeroArrayIndex() {
Modified: cfe/trunk/lib/Checker/BasicValueFactory.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/BasicValueFactory.cpp?rev=95354&r1=95353&r2=95354&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/BasicValueFactory.cpp (original)
+++ cfe/trunk/lib/Checker/BasicValueFactory.cpp Thu Feb 4 20:26:30 2010
@@ -24,9 +24,8 @@
}
void LazyCompoundValData::Profile(llvm::FoldingSetNodeID& ID,
- const GRState *state,
- const TypedRegion *region) {
- ID.AddPointer(state);
+ const void *store,const TypedRegion *region) {
+ ID.AddPointer(store);
ID.AddPointer(region);
}
@@ -124,10 +123,10 @@
}
const LazyCompoundValData*
-BasicValueFactory::getLazyCompoundValData(const GRState *state,
+BasicValueFactory::getLazyCompoundValData(const void *store,
const TypedRegion *region) {
llvm::FoldingSetNodeID ID;
- LazyCompoundValData::Profile(ID, state, region);
+ LazyCompoundValData::Profile(ID, store, region);
void* InsertPos;
LazyCompoundValData *D =
@@ -135,7 +134,7 @@
if (!D) {
D = (LazyCompoundValData*) BPAlloc.Allocate<LazyCompoundValData>();
- new (D) LazyCompoundValData(state, region);
+ new (D) LazyCompoundValData(store, region);
LazyCompoundValDataSet.InsertNode(D, InsertPos);
}
Modified: cfe/trunk/lib/Checker/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/RegionStore.cpp?rev=95354&r1=95353&r2=95354&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/RegionStore.cpp (original)
+++ cfe/trunk/lib/Checker/RegionStore.cpp Thu Feb 4 20:26:30 2010
@@ -44,7 +44,7 @@
uint64_t Offset;
explicit BindingKey(const MemRegion *r, uint64_t offset, Kind k)
- : P(r, (unsigned) k), Offset(offset) {}
+ : P(r, (unsigned) k), Offset(offset) { assert(r); }
public:
bool isDefault() const { return P.getInt() == Default; }
@@ -201,7 +201,7 @@
const RegionStoreFeatures Features;
RegionBindings::Factory RBFactory;
- typedef llvm::DenseMap<const GRState *, RegionStoreSubRegionMap*> SMCache;
+ typedef llvm::DenseMap<Store, RegionStoreSubRegionMap*> SMCache;
SMCache SC;
public:
@@ -357,9 +357,9 @@
/// return symbolic
SVal Retrieve(const GRState *state, Loc L, QualType T = QualType());
- SVal RetrieveElement(const GRState *state, const ElementRegion *R);
+ SVal RetrieveElement(Store store, const ElementRegion *R);
- SVal RetrieveField(const GRState *state, const FieldRegion *R);
+ SVal RetrieveField(Store store, const FieldRegion *R);
SVal RetrieveObjCIvar(const GRState *state, const ObjCIvarRegion *R);
@@ -367,7 +367,7 @@
SVal RetrieveLazySymbol(const GRState *state, const TypedRegion *R);
- SVal RetrieveFieldOrElementCommon(const GRState *state, const TypedRegion *R,
+ SVal RetrieveFieldOrElementCommon(Store store, const TypedRegion *R,
QualType Ty, const MemRegion *superR);
/// Retrieve the values in a struct and return a CompoundVal, used when doing
@@ -380,7 +380,7 @@
SVal RetrieveArray(const GRState *St, const TypedRegion* R);
/// Get the state and region whose binding this region R corresponds to.
- std::pair<const GRState*, const MemRegion*>
+ std::pair<Store, const MemRegion*>
GetLazyBinding(RegionBindings B, const MemRegion *R);
const GRState* CopyLazyBindings(nonloc::LazyCompoundVal V,
@@ -1161,7 +1161,7 @@
return UnknownVal();
if (const FieldRegion* FR = dyn_cast<FieldRegion>(R))
- return CastRetrievedVal(RetrieveField(state, FR), FR, T, false);
+ return CastRetrievedVal(RetrieveField(state->getStore(), FR), FR, T, false);
if (const ElementRegion* ER = dyn_cast<ElementRegion>(R)) {
// FIXME: Here we actually perform an implicit conversion from the loaded
@@ -1169,7 +1169,7 @@
// more intelligently. For example, an 'element' can encompass multiple
// bound regions (e.g., several bound bytes), or could be a subset of
// a larger value.
- return CastRetrievedVal(RetrieveElement(state, ER), ER, T, false);
+ return CastRetrievedVal(RetrieveElement(state->getStore(), ER), ER, T, false);
}
if (const ObjCIvarRegion *IVR = dyn_cast<ObjCIvarRegion>(R)) {
@@ -1214,15 +1214,15 @@
return ValMgr.getRegionValueSymbolVal(R, RTy);
}
-std::pair<const GRState*, const MemRegion*>
+std::pair<Store, const MemRegion *>
RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) {
if (Optional<SVal> OV = getDirectBinding(B, R))
if (const nonloc::LazyCompoundVal *V =
dyn_cast<nonloc::LazyCompoundVal>(OV.getPointer()))
- return std::make_pair(V->getState(), V->getRegion());
+ return std::make_pair(V->getStore(), V->getRegion());
if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) {
- const std::pair<const GRState *, const MemRegion *> &X =
+ const std::pair<Store, const MemRegion *> &X =
GetLazyBinding(B, ER->getSuperRegion());
if (X.first)
@@ -1230,7 +1230,7 @@
MRMgr.getElementRegionWithSuper(ER, X.second));
}
else if (const FieldRegion *FR = dyn_cast<FieldRegion>(R)) {
- const std::pair<const GRState *, const MemRegion *> &X =
+ const std::pair<Store, const MemRegion *> &X =
GetLazyBinding(B, FR->getSuperRegion());
if (X.first)
@@ -1238,13 +1238,13 @@
MRMgr.getFieldRegionWithSuper(FR, X.second));
}
- return std::make_pair((const GRState*) 0, (const MemRegion *) 0);
+ return std::make_pair((Store) 0, (const MemRegion *) 0);
}
-SVal RegionStoreManager::RetrieveElement(const GRState* state,
+SVal RegionStoreManager::RetrieveElement(Store store,
const ElementRegion* R) {
// Check if the region has a binding.
- RegionBindings B = GetRegionBindings(state->getStore());
+ RegionBindings B = GetRegionBindings(store);
if (Optional<SVal> V = getDirectBinding(B, R))
return *V;
@@ -1289,29 +1289,29 @@
dyn_cast<nonloc::LazyCompoundVal>(V)) {
R = MRMgr.getElementRegionWithSuper(R, LCV->getRegion());
- return RetrieveElement(LCV->getState(), R);
+ return RetrieveElement(LCV->getStore(), R);
}
// Other cases: give up.
return UnknownVal();
}
- return RetrieveFieldOrElementCommon(state, R, R->getElementType(), superR);
+ return RetrieveFieldOrElementCommon(store, R, R->getElementType(), superR);
}
-SVal RegionStoreManager::RetrieveField(const GRState* state,
+SVal RegionStoreManager::RetrieveField(Store store,
const FieldRegion* R) {
// Check if the region has a binding.
- RegionBindings B = GetRegionBindings(state->getStore());
+ RegionBindings B = GetRegionBindings(store);
if (Optional<SVal> V = getDirectBinding(B, R))
return *V;
QualType Ty = R->getValueType(getContext());
- return RetrieveFieldOrElementCommon(state, R, Ty, R->getSuperRegion());
+ return RetrieveFieldOrElementCommon(store, R, Ty, R->getSuperRegion());
}
-SVal RegionStoreManager::RetrieveFieldOrElementCommon(const GRState *state,
+SVal RegionStoreManager::RetrieveFieldOrElementCommon(Store store,
const TypedRegion *R,
QualType Ty,
const MemRegion *superR) {
@@ -1319,7 +1319,7 @@
// At this point we have already checked in either RetrieveElement or
// RetrieveField if 'R' has a direct binding.
- RegionBindings B = GetRegionBindings(state->getStore());
+ RegionBindings B = GetRegionBindings(store);
while (superR) {
if (const Optional<SVal> &D = getDefaultBinding(B, superR)) {
@@ -1346,18 +1346,18 @@
}
// Lazy binding?
- const GRState *lazyBindingState = NULL;
+ Store lazyBindingStore = NULL;
const MemRegion *lazyBindingRegion = NULL;
- llvm::tie(lazyBindingState, lazyBindingRegion) = GetLazyBinding(B, R);
+ llvm::tie(lazyBindingStore, lazyBindingRegion) = GetLazyBinding(B, R);
- if (lazyBindingState) {
+ if (lazyBindingStore) {
assert(lazyBindingRegion && "Lazy-binding region not set");
if (isa<ElementRegion>(R))
- return RetrieveElement(lazyBindingState,
+ return RetrieveElement(lazyBindingStore,
cast<ElementRegion>(lazyBindingRegion));
- return RetrieveField(lazyBindingState,
+ return RetrieveField(lazyBindingStore,
cast<FieldRegion>(lazyBindingRegion));
}
@@ -1456,7 +1456,7 @@
return ValMgr.makeCompoundVal(T, StructVal);
#else
- return ValMgr.makeLazyCompoundVal(state, R);
+ return ValMgr.makeLazyCompoundVal(state->getStore(), R);
#endif
}
@@ -1480,7 +1480,7 @@
return ValMgr.makeCompoundVal(T, ArrayVal);
#else
assert(isa<ConstantArrayType>(R->getValueType(getContext())));
- return ValMgr.makeLazyCompoundVal(state, R);
+ return ValMgr.makeLazyCompoundVal(state->getStore(), R);
#endif
}
@@ -1823,7 +1823,7 @@
SymbolReaper& SymReaper,
llvm::SmallVectorImpl<const MemRegion*>& RegionRoots)
{
- typedef std::pair<const GRState*, const MemRegion *> RBDNode;
+ typedef std::pair<Store, const MemRegion *> RBDNode;
Store store = state.getStore();
RegionBindings B = GetRegionBindings(store);
@@ -1860,7 +1860,7 @@
if (const VarRegion* VR = dyn_cast<VarRegion>(R)) {
if (SymReaper.isLive(Loc, VR))
- WorkList.push_back(std::make_pair(&state, VR));
+ WorkList.push_back(std::make_pair(store, VR));
continue;
}
@@ -1868,7 +1868,7 @@
llvm::SmallVectorImpl<RBDNode> &Q =
SymReaper.isLive(SR->getSymbol()) ? WorkList : Postponed;
- Q.push_back(std::make_pair(&state, SR));
+ Q.push_back(std::make_pair(store, SR));
continue;
}
@@ -1882,7 +1882,7 @@
// Enqueue the RegionRoots onto WorkList.
for (llvm::SmallVectorImpl<const MemRegion*>::iterator I=RegionRoots.begin(),
E=RegionRoots.end(); I!=E; ++I) {
- WorkList.push_back(std::make_pair(&state, *I));
+ WorkList.push_back(std::make_pair(store, *I));
}
RegionRoots.clear();
@@ -1899,24 +1899,24 @@
Visited.insert(N);
const MemRegion *R = N.second;
- const GRState *state_N = N.first;
+ Store store_N = N.first;
// Enqueue subregions.
RegionStoreSubRegionMap *M;
- if (&state == state_N)
+ if (store == store_N)
M = SubRegions.get();
else {
- RegionStoreSubRegionMap *& SM = SC[state_N];
+ RegionStoreSubRegionMap *& SM = SC[store_N];
if (!SM)
- SM = getRegionStoreSubRegionMap(state_N->getStore());
+ SM = getRegionStoreSubRegionMap(store_N);
M = SM;
}
if (const RegionStoreSubRegionMap::Set *S = M->getSubRegions(R))
for (RegionStoreSubRegionMap::Set::iterator I = S->begin(), E = S->end();
I != E; ++I)
- WorkList.push_back(std::make_pair(state_N, *I));
+ WorkList.push_back(std::make_pair(store_N, *I));
// Enqueue the super region.
if (const SubRegion *SR = dyn_cast<SubRegion>(R)) {
@@ -1927,7 +1927,7 @@
// pointer arithmetic can get us to the other fields or elements.
assert(isa<FieldRegion>(R) || isa<ElementRegion>(R)
|| isa<ObjCIvarRegion>(R));
- WorkList.push_back(std::make_pair(state_N, superR));
+ WorkList.push_back(std::make_pair(store_N, superR));
}
}
@@ -1944,14 +1944,13 @@
RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end();
RI != RE; ++RI) {
if ((*RI)->getDecl()->getAttr<BlocksAttr>())
- WorkList.push_back(std::make_pair(state_N, *RI));
+ WorkList.push_back(std::make_pair(store_N, *RI));
}
// No possible data bindings on a BlockDataRegion. Continue to the
// next region in the worklist.
continue;
}
- Store store_N = state_N->getStore();
RegionBindings B_N = GetRegionBindings(store_N);
// Get the data binding for R (if any).
@@ -1963,7 +1962,7 @@
dyn_cast<nonloc::LazyCompoundVal>(V.getPointer())) {
const LazyCompoundValData *D = LCV->getCVData();
- WorkList.push_back(std::make_pair(D->getState(), D->getRegion()));
+ WorkList.push_back(std::make_pair(D->getStore(), D->getRegion()));
}
else {
// Update the set of live symbols.
@@ -1973,7 +1972,7 @@
// If V is a region, then add it to the worklist.
if (const MemRegion *RX = V->getAsRegion())
- WorkList.push_back(std::make_pair(state_N, RX));
+ WorkList.push_back(std::make_pair(store_N, RX));
}
}
}
@@ -1996,14 +1995,15 @@
// We have now scanned the store, marking reachable regions and symbols
// as live. We now remove all the regions that are dead from the store
// as well as update DSymbols with the set symbols that are now dead.
+ Store new_store = store;
for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) {
const MemRegion* R = I.getKey().getRegion();
// If this region live? Is so, none of its symbols are dead.
- if (Visited.count(std::make_pair(&state, R)))
+ if (Visited.count(std::make_pair(store, R)))
continue;
// Remove this dead region from the store.
- store = Remove(store, I.getKey());
+ new_store = Remove(new_store, I.getKey());
// Mark all non-live symbols that this region references as dead.
if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(R))
@@ -2016,7 +2016,7 @@
}
// Write the store back.
- state.setStore(store);
+ state.setStore(new_store);
}
GRState const *RegionStoreManager::EnterStackFrame(GRState const *state,
Modified: cfe/trunk/lib/Checker/SVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/SVals.cpp?rev=95354&r1=95353&r2=95354&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/SVals.cpp (original)
+++ cfe/trunk/lib/Checker/SVals.cpp Thu Feb 4 20:26:30 2010
@@ -153,8 +153,8 @@
assert(false && "unhandled expansion case");
}
-const GRState *nonloc::LazyCompoundVal::getState() const {
- return static_cast<const LazyCompoundValData*>(Data)->getState();
+const void *nonloc::LazyCompoundVal::getStore() const {
+ return static_cast<const LazyCompoundValData*>(Data)->getStore();
}
const TypedRegion *nonloc::LazyCompoundVal::getRegion() const {
@@ -299,7 +299,7 @@
}
case nonloc::LazyCompoundValKind: {
const nonloc::LazyCompoundVal &C = *cast<nonloc::LazyCompoundVal>(this);
- os << "lazyCompoundVal{" << (void*) C.getState() << ',' << C.getRegion()
+ os << "lazyCompoundVal{" << (void*) C.getStore() << ',' << C.getRegion()
<< '}';
break;
}
More information about the cfe-commits
mailing list