[cfe-commits] r73927 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp
Ted Kremenek
kremenek at apple.com
Mon Jun 22 17:15:41 PDT 2009
Author: kremenek
Date: Mon Jun 22 19:15:41 2009
New Revision: 73927
URL: http://llvm.org/viewvc/llvm-project?rev=73927&view=rev
Log:
MemRegionManager: Migrate logic for getAllocaRegion() over to using trait-based MemRegion creation.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
cfe/trunk/lib/Analysis/MemRegion.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h?rev=73927&r1=73926&r2=73927&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Mon Jun 22 19:15:41 2009
@@ -123,7 +123,7 @@
// 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 @@
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 @@
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 @@
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,
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=73927&r1=73926&r2=73927&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Mon Jun 22 19:15:41 2009
@@ -50,14 +50,15 @@
}
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 @@
}
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) {
More information about the cfe-commits
mailing list