From: Ted Kremenek Date: Wed, 24 Dec 2008 01:05:03 +0000 (+0000) Subject: Comment and fixup GDM entries for RegionStore to use unique 'tag classes' to identify... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50dc1b3c851b5700ea32f81ed360586617e2c92f;p=clang Comment and fixup GDM entries for RegionStore to use unique 'tag classes' to identify GDM entries. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61409 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 06292d20d8..78bb654871 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -29,55 +29,83 @@ using namespace clang; // Actual Store type. typedef llvm::ImmutableMap RegionBindingsTy; -// RegionView GDM stuff. -typedef llvm::ImmutableList RegionViewTy; -typedef llvm::ImmutableMap RegionViewMapTy; -static int RegionViewMapTyIndex = 0; +//===----------------------------------------------------------------------===// +// Region "Views" +//===----------------------------------------------------------------------===// +// +// MemRegions can be layered on top of each other. This GDM entry tracks +// what are the MemRegions that layer a given MemRegion. +// +typedef llvm::ImmutableList RegionViews; +namespace { class VISIBILITY_HIDDEN RegionViewMap {}; } +static int RegionViewMapIndex = 0; namespace clang { -template<> struct GRStateTrait - : public GRStatePartialTrait { - static void* GDMIndex() { return &RegionViewMapTyIndex; } -}; + template<> struct GRStateTrait + : public GRStatePartialTrait > { + + static void* GDMIndex() { return &RegionViewMapIndex; } + }; } -// RegionExtents GDM stuff. -// Currently RegionExtents are in bytes. We can change this representation when -// there are real requirements. -typedef llvm::ImmutableMap RegionExtentsTy; -static int RegionExtentsTyIndex = 0; +//===----------------------------------------------------------------------===// +// Region "Extents" +//===----------------------------------------------------------------------===// +// +// MemRegions represent chunks of memory with a size (their "extent"). This +// GDM entry tracks the extents for regions. Extents are in bytes. +namespace { class VISIBILITY_HIDDEN RegionExtents {}; } +static int RegionExtentsIndex = 0; namespace clang { -template<> struct GRStateTrait - : public GRStatePartialTrait { - static void* GDMIndex() { return &RegionExtentsTyIndex; } -}; + template<> struct GRStateTrait + : public GRStatePartialTrait > { + static void* GDMIndex() { return &RegionExtentsIndex; } + }; } -// KillSet GDM stuff. -typedef llvm::ImmutableSet RegionKills; +//===----------------------------------------------------------------------===// +// Region "killsets". +//===----------------------------------------------------------------------===// +// +// RegionStore lazily adds value bindings to regions when the analyzer +// handles assignment statements. Killsets track which default values have +// been killed, thus distinguishing between "unknown" values and default +// values. +// +namespace { class VISIBILITY_HIDDEN RegionKills {}; } static int RegionKillsIndex = 0; namespace clang { template<> struct GRStateTrait - : public GRStatePartialTrait { + : public GRStatePartialTrait< llvm::ImmutableSet > { static void* GDMIndex() { return &RegionKillsIndex; } }; } -// Regions that have default value zero. -// FIXME: redefinition! -// typedef llvm::ImmutableMap RegionDefaultValue; -// static int RegionDefaultValueIndex = 0; -// namespace clang { -// template<> struct GRStateTrait -// : public GRStatePartialTrait { -// static void* GDMIndex() { return &RegionDefaultValueIndex; } -// }; -// } +//===----------------------------------------------------------------------===// +// Regions with default values of '0'. +//===----------------------------------------------------------------------===// +// +// This GDM entry tracks what regions have a default value of 0 if they +// have no bound value and have not been killed. +// +namespace { class VISIBILITY_HIDDEN RegionDefaultValue {}; } +static int RegionDefaultValueIndex = 0; +namespace clang { + template<> struct GRStateTrait + : public GRStatePartialTrait > { + static void* GDMIndex() { return &RegionDefaultValueIndex; } + }; +} + +//===----------------------------------------------------------------------===// +// Main RegionStore logic. +//===----------------------------------------------------------------------===// namespace { class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager { RegionBindingsTy::Factory RBFactory; - RegionViewTy::Factory RVFactory; + RegionViews::Factory RVFactory; GRStateManager& StateMgr; MemRegionManager MRMgr; @@ -337,13 +365,11 @@ SVal RegionStoreManager::getSizeInElements(const GRState* St, GRStateRef state(St, StateMgr); // Get the size of the super region in bytes. - RegionExtentsTy::data_type* T - = state.get(ATR->getSuperRegion()); - - assert(T && "region extent not exist"); + const SVal* Extent = state.get(ATR->getSuperRegion()); + assert(Extent && "region extent not exist"); // Assume it's ConcreteInt for now. - llvm::APSInt SSize = cast(*T).getValue(); + llvm::APSInt SSize = cast(*Extent).getValue(); // Get the size of the element in bits. QualType LvT = ATR->getLValueType(getContext()); @@ -586,7 +612,7 @@ RegionStoreManager::BindCompoundLiteral(const GRState* St, const GRState* RegionStoreManager::setExtent(const GRState* St, const MemRegion* R, SVal Extent) { GRStateRef state(St, StateMgr); - return state.set(R, Extent); + return state.set(R, Extent); } @@ -843,12 +869,12 @@ const GRState* RegionStoreManager::AddRegionView(const GRState* St, GRStateRef state(St, StateMgr); // First, retrieve the region view of the base region. - RegionViewMapTy::data_type* d = state.get(Base); - RegionViewTy L = d ? *d : RVFactory.GetEmptyList(); + const RegionViews* d = state.get(Base); + RegionViews L = d ? *d : RVFactory.GetEmptyList(); // Now add View to the region view. L = RVFactory.Add(View, L); // Create a new state with the new region view. - return state.set(Base, L); + return state.set(Base, L); }