From bfcaf8048d1673320de60a22ca9c297d7484b2a8 Mon Sep 17 00:00:00 2001 From: Zhongxing Xu Date: Fri, 5 Feb 2010 02:26:30 +0000 Subject: [PATCH] Change LazyCompoundVal to a pair. We really don't need to spread GRState* everywhere. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95354 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Checker/PathSensitive/BasicValueFactory.h | 14 +-- include/clang/Checker/PathSensitive/SVals.h | 2 +- .../Checker/PathSensitive/ValueManager.h | 4 +- lib/Checker/BasicValueFactory.cpp | 11 +-- lib/Checker/RegionStore.cpp | 92 +++++++++---------- lib/Checker/SVals.cpp | 6 +- 6 files changed, 64 insertions(+), 65 deletions(-) diff --git a/include/clang/Checker/PathSensitive/BasicValueFactory.h b/include/clang/Checker/PathSensitive/BasicValueFactory.h index 1717c268d3..2f0b6c2a03 100644 --- a/include/clang/Checker/PathSensitive/BasicValueFactory.h +++ b/include/clang/Checker/PathSensitive/BasicValueFactory.h @@ -46,19 +46,19 @@ public: }; 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 @@ public: const CompoundValData *getCompoundValData(QualType T, llvm::ImmutableList Vals); - const LazyCompoundValData *getLazyCompoundValData(const GRState *state, + const LazyCompoundValData *getLazyCompoundValData(const void *store, const TypedRegion *region); llvm::ImmutableList getEmptySValList() { diff --git a/include/clang/Checker/PathSensitive/SVals.h b/include/clang/Checker/PathSensitive/SVals.h index e04f8dc999..65a8a2c01d 100644 --- a/include/clang/Checker/PathSensitive/SVals.h +++ b/include/clang/Checker/PathSensitive/SVals.h @@ -388,7 +388,7 @@ public: const LazyCompoundValData *getCVData() const { return static_cast(Data); } - const GRState *getState() const; + const void *getStore() const; const TypedRegion *getRegion() const; static bool classof(const SVal *V) { diff --git a/include/clang/Checker/PathSensitive/ValueManager.h b/include/clang/Checker/PathSensitive/ValueManager.h index 0141cefb01..ea3af57ed3 100644 --- a/include/clang/Checker/PathSensitive/ValueManager.h +++ b/include/clang/Checker/PathSensitive/ValueManager.h @@ -115,8 +115,8 @@ public: 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() { diff --git a/lib/Checker/BasicValueFactory.cpp b/lib/Checker/BasicValueFactory.cpp index 3b01e23da1..246beead12 100644 --- a/lib/Checker/BasicValueFactory.cpp +++ b/lib/Checker/BasicValueFactory.cpp @@ -24,9 +24,8 @@ void CompoundValData::Profile(llvm::FoldingSetNodeID& ID, QualType T, } 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 @@ BasicValueFactory::getCompoundValData(QualType T, } 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 @@ BasicValueFactory::getLazyCompoundValData(const GRState *state, if (!D) { D = (LazyCompoundValData*) BPAlloc.Allocate(); - new (D) LazyCompoundValData(state, region); + new (D) LazyCompoundValData(store, region); LazyCompoundValDataSet.InsertNode(D, InsertPos); } diff --git a/lib/Checker/RegionStore.cpp b/lib/Checker/RegionStore.cpp index 25e8059d26..e527f356b0 100644 --- a/lib/Checker/RegionStore.cpp +++ b/lib/Checker/RegionStore.cpp @@ -44,7 +44,7 @@ private: 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 @@ class RegionStoreManager : public StoreManager { const RegionStoreFeatures Features; RegionBindings::Factory RBFactory; - typedef llvm::DenseMap SMCache; + typedef llvm::DenseMap SMCache; SMCache SC; public: @@ -357,9 +357,9 @@ public: // Part of public interface to class. /// 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 @@ public: // Part of public interface to class. 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 @@ public: // Part of public interface to class. SVal RetrieveArray(const GRState *St, const TypedRegion* R); /// Get the state and region whose binding this region R corresponds to. - std::pair + std::pair GetLazyBinding(RegionBindings B, const MemRegion *R); const GRState* CopyLazyBindings(nonloc::LazyCompoundVal V, @@ -1161,7 +1161,7 @@ SVal RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { return UnknownVal(); if (const FieldRegion* FR = dyn_cast(R)) - return CastRetrievedVal(RetrieveField(state, FR), FR, T, false); + return CastRetrievedVal(RetrieveField(state->getStore(), FR), FR, T, false); if (const ElementRegion* ER = dyn_cast(R)) { // FIXME: Here we actually perform an implicit conversion from the loaded @@ -1169,7 +1169,7 @@ SVal RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { // 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(R)) { @@ -1214,15 +1214,15 @@ SVal RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { return ValMgr.getRegionValueSymbolVal(R, RTy); } -std::pair +std::pair RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { if (Optional OV = getDirectBinding(B, R)) if (const nonloc::LazyCompoundVal *V = dyn_cast(OV.getPointer())) - return std::make_pair(V->getState(), V->getRegion()); + return std::make_pair(V->getStore(), V->getRegion()); if (const ElementRegion *ER = dyn_cast(R)) { - const std::pair &X = + const std::pair &X = GetLazyBinding(B, ER->getSuperRegion()); if (X.first) @@ -1230,7 +1230,7 @@ RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { MRMgr.getElementRegionWithSuper(ER, X.second)); } else if (const FieldRegion *FR = dyn_cast(R)) { - const std::pair &X = + const std::pair &X = GetLazyBinding(B, FR->getSuperRegion()); if (X.first) @@ -1238,13 +1238,13 @@ RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { 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 V = getDirectBinding(B, R)) return *V; @@ -1289,29 +1289,29 @@ SVal RegionStoreManager::RetrieveElement(const GRState* state, dyn_cast(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 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 @@ SVal RegionStoreManager::RetrieveFieldOrElementCommon(const GRState *state, // 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 &D = getDefaultBinding(B, superR)) { @@ -1346,18 +1346,18 @@ SVal RegionStoreManager::RetrieveFieldOrElementCommon(const GRState *state, } // 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(R)) - return RetrieveElement(lazyBindingState, + return RetrieveElement(lazyBindingStore, cast(lazyBindingRegion)); - return RetrieveField(lazyBindingState, + return RetrieveField(lazyBindingStore, cast(lazyBindingRegion)); } @@ -1456,7 +1456,7 @@ SVal RegionStoreManager::RetrieveStruct(const GRState *state, return ValMgr.makeCompoundVal(T, StructVal); #else - return ValMgr.makeLazyCompoundVal(state, R); + return ValMgr.makeLazyCompoundVal(state->getStore(), R); #endif } @@ -1480,7 +1480,7 @@ SVal RegionStoreManager::RetrieveArray(const GRState *state, return ValMgr.makeCompoundVal(T, ArrayVal); #else assert(isa(R->getValueType(getContext()))); - return ValMgr.makeLazyCompoundVal(state, R); + return ValMgr.makeLazyCompoundVal(state->getStore(), R); #endif } @@ -1823,7 +1823,7 @@ void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, SymbolReaper& SymReaper, llvm::SmallVectorImpl& RegionRoots) { - typedef std::pair RBDNode; + typedef std::pair RBDNode; Store store = state.getStore(); RegionBindings B = GetRegionBindings(store); @@ -1860,7 +1860,7 @@ void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, if (const VarRegion* VR = dyn_cast(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 @@ void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, llvm::SmallVectorImpl &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 @@ void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, // Enqueue the RegionRoots onto WorkList. for (llvm::SmallVectorImpl::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 @@ tryAgain: 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(R)) { @@ -1927,7 +1927,7 @@ tryAgain: // pointer arithmetic can get us to the other fields or elements. assert(isa(R) || isa(R) || isa(R)); - WorkList.push_back(std::make_pair(state_N, superR)); + WorkList.push_back(std::make_pair(store_N, superR)); } } @@ -1944,14 +1944,13 @@ tryAgain: RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end(); RI != RE; ++RI) { if ((*RI)->getDecl()->getAttr()) - 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 @@ tryAgain: dyn_cast(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 @@ tryAgain: // 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 @@ tryAgain: // 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(R)) @@ -2016,7 +2016,7 @@ tryAgain: } // Write the store back. - state.setStore(store); + state.setStore(new_store); } GRState const *RegionStoreManager::EnterStackFrame(GRState const *state, diff --git a/lib/Checker/SVals.cpp b/lib/Checker/SVals.cpp index efa5521ebd..28b3fce050 100644 --- a/lib/Checker/SVals.cpp +++ b/lib/Checker/SVals.cpp @@ -153,8 +153,8 @@ void SVal::symbol_iterator::expand() { assert(false && "unhandled expansion case"); } -const GRState *nonloc::LazyCompoundVal::getState() const { - return static_cast(Data)->getState(); +const void *nonloc::LazyCompoundVal::getStore() const { + return static_cast(Data)->getStore(); } const TypedRegion *nonloc::LazyCompoundVal::getRegion() const { @@ -299,7 +299,7 @@ void NonLoc::dumpToStream(llvm::raw_ostream& os) const { } case nonloc::LazyCompoundValKind: { const nonloc::LazyCompoundVal &C = *cast(this); - os << "lazyCompoundVal{" << (void*) C.getState() << ',' << C.getRegion() + os << "lazyCompoundVal{" << (void*) C.getStore() << ',' << C.getRegion() << '}'; break; } -- 2.40.0