summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/RegionStore.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2009-05-06 08:33:50 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2009-05-06 08:33:50 +0000
commitc98868136f2d166f8eb9c52706d51f91ba479abd (patch)
tree57a918ea8cdde043837d941d1e1d0632ac2233cc /clang/lib/Analysis/RegionStore.cpp
parent24ed0b28a8dad6e50f6360f92f9b2f9584b0d355 (diff)
downloadbcm5719-llvm-c98868136f2d166f8eb9c52706d51f91ba479abd.tar.gz
bcm5719-llvm-c98868136f2d166f8eb9c52706d51f91ba479abd.zip
Add a GDM for recording the cast type of regions.
llvm-svn: 71076
Diffstat (limited to 'clang/lib/Analysis/RegionStore.cpp')
-rw-r--r--clang/lib/Analysis/RegionStore.cpp27
1 files changed, 25 insertions, 2 deletions
diff --git a/clang/lib/Analysis/RegionStore.cpp b/clang/lib/Analysis/RegionStore.cpp
index 5f8e6c3f92a..043fc95e084 100644
--- a/clang/lib/Analysis/RegionStore.cpp
+++ b/clang/lib/Analysis/RegionStore.cpp
@@ -48,6 +48,17 @@ namespace clang {
};
}
+// RegionCasts records the current cast type of a region.
+namespace { class VISIBILITY_HIDDEN RegionCasts {}; }
+static int RegionCastsIndex = 0;
+namespace clang {
+ template<> struct GRStateTrait<RegionCasts>
+ : public GRStatePartialTrait<llvm::ImmutableMap<const MemRegion*,
+ QualType> > {
+ static void* GDMIndex() { return &RegionCastsIndex; }
+ };
+}
+
//===----------------------------------------------------------------------===//
// Region "Extents"
//===----------------------------------------------------------------------===//
@@ -253,6 +264,7 @@ public:
}
const GRState* setExtent(const GRState* St, const MemRegion* R, SVal Extent);
+ const GRState* setCastType(const GRState* St, const MemRegion* R, QualType T);
static inline RegionBindingsTy GetRegionBindings(Store store) {
return RegionBindingsTy(static_cast<const RegionBindingsTy::TreeTy*>(store));
@@ -488,6 +500,9 @@ SVal RegionStoreManager::getSizeInElements(const GRState* St,
// return the size as signed integer.
return NonLoc::MakeVal(getBasicVals(), CAT->getSize(), false);
}
+
+ // If the VarRegion is cast to other type, compute the size with respect to
+ // that type.
// Clients can use ordinary variables as if they were arrays. These
// essentially are arrays of size 1.
@@ -650,9 +665,11 @@ RegionStoreManager::CastRegion(const GRState* state, const MemRegion* R,
|| isa<ObjCIvarRegion>(R) || isa<CompoundLiteralRegion>(R)) {
if (isSmallerThan(PointeeTy,
cast<TypedRegion>(R)->getRValueType(getContext()))) {
+ // Record the cast type of the region.
+ state = setCastType(state, R, ToTy);
+
SVal Idx = ValMgr.makeZeroArrayIndex();
- ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx,
- cast<TypedRegion>(R));
+ ElementRegion* ER = MRMgr.getElementRegion(PointeeTy, Idx, R);
return CastResult(state, ER);
} else
return CastResult(state, R);
@@ -1295,3 +1312,9 @@ const GRState* RegionStoreManager::RemoveRegionView(const GRState* St,
return state.set<RegionViewMap>(Base, V);
}
+
+const GRState* RegionStoreManager::setCastType(const GRState* St,
+ const MemRegion* R, QualType T) {
+ GRStateRef state(St, StateMgr);
+ return state.set<RegionCasts>(R, T);
+}
OpenPOWER on IntegriCloud