aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-06-23 00:15:41 +0000
committerTed Kremenek <kremenek@apple.com>2009-06-23 00:15:41 +0000
commit7ae7ad9951f032d0a33b64c964f7cdcb9cc6f59b (patch)
tree0b3d777dcf1d528713566067dc1686533fdce076
parentded1221db96976b392b3dca7b9f2209a923eb68e (diff)
MemRegionManager: Migrate logic for getAllocaRegion() over to using trait-based MemRegion creation.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73927 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Analysis/PathSensitive/MemRegion.h36
-rw-r--r--lib/Analysis/MemRegion.cpp20
2 files changed, 38 insertions, 18 deletions
diff --git a/include/clang/Analysis/PathSensitive/MemRegion.h b/include/clang/Analysis/PathSensitive/MemRegion.h
index 510d2bf453..47d51119f8 100644
--- a/include/clang/Analysis/PathSensitive/MemRegion.h
+++ b/include/clang/Analysis/PathSensitive/MemRegion.h
@@ -123,7 +123,7 @@ protected:
// memory allocated by alloca at the same call site.
const Expr* Ex;
- AllocaRegion(const Expr* ex, unsigned cnt, const MemRegion* superRegion)
+ AllocaRegion(const Expr* ex, unsigned cnt, const MemRegion *superRegion)
: SubRegion(superRegion, AllocaRegionKind), Cnt(cnt), Ex(ex) {}
public:
@@ -133,7 +133,7 @@ public:
void Profile(llvm::FoldingSetNodeID& ID) const;
static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex,
- unsigned Cnt);
+ unsigned Cnt, const MemRegion *superRegion);
void print(llvm::raw_ostream& os) const;
@@ -657,6 +657,9 @@ public:
template <typename RegionTy, typename A1>
RegionTy* getRegion(const A1 a1, const MemRegion* superRegion);
+
+ template <typename RegionTy, typename A1, typename A2>
+ RegionTy* getRegion(const A1 a1, const A2 a2);
private:
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
@@ -707,10 +710,39 @@ RegionTy* MemRegionManager::getRegion(const A1 a1, const MemRegion *superRegion)
return R;
}
+template <typename RegionTy, typename A1, typename A2>
+RegionTy* MemRegionManager::getRegion(const A1 a1, const A2 a2) {
+
+ const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion =
+ MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1, a2);
+
+ llvm::FoldingSetNodeID ID;
+ RegionTy::ProfileRegion(ID, a1, a2, superRegion);
+ void* InsertPos;
+ RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
+ InsertPos));
+
+ if (!R) {
+ R = (RegionTy*) A.Allocate<RegionTy>();
+ new (R) RegionTy(a1, a2, superRegion);
+ Regions.InsertNode(R, InsertPos);
+ }
+
+ return R;
+}
+
//===----------------------------------------------------------------------===//
// Traits for constructing regions.
//===----------------------------------------------------------------------===//
+template <> struct MemRegionManagerTrait<AllocaRegion> {
+ typedef MemRegion SuperRegionTy;
+ static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
+ const Expr *, unsigned) {
+ return MRMgr.getStackRegion();
+ }
+};
+
template <> struct MemRegionManagerTrait<CompoundLiteralRegion> {
typedef MemRegion SuperRegionTy;
static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp
index bd42858a4f..ad40f667d3 100644
--- a/lib/Analysis/MemRegion.cpp
+++ b/lib/Analysis/MemRegion.cpp
@@ -50,14 +50,15 @@ void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
}
void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
- const Expr* Ex, unsigned cnt) {
+ const Expr* Ex, unsigned cnt,
+ const MemRegion *) {
ID.AddInteger((unsigned) AllocaRegionKind);
ID.AddPointer(Ex);
ID.AddInteger(cnt);
}
void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const {
- ProfileRegion(ID, Ex, Cnt);
+ ProfileRegion(ID, Ex, Cnt, superRegion);
}
void TypedViewRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
@@ -335,20 +336,7 @@ MemRegionManager::getTypedViewRegion(QualType t, const MemRegion* superRegion) {
}
AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) {
- llvm::FoldingSetNodeID ID;
- AllocaRegion::ProfileRegion(ID, E, cnt);
-
- void* InsertPos;
- MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
- AllocaRegion* R = cast_or_null<AllocaRegion>(data);
-
- if (!R) {
- R = (AllocaRegion*) A.Allocate<AllocaRegion>();
- new (R) AllocaRegion(E, cnt, getStackRegion());
- Regions.InsertNode(R, InsertPos);
- }
-
- return R;
+ return getRegion<AllocaRegion>(E, cnt);
}
bool MemRegionManager::hasStackStorage(const MemRegion* R) {