[cfe-commits] r90499 - in /cfe/trunk: include/clang/Analysis/PathSensitive/MemRegion.h lib/Analysis/MemRegion.cpp
Ted Kremenek
kremenek at apple.com
Thu Dec 3 16:05:57 PST 2009
Author: kremenek
Date: Thu Dec 3 18:05:57 2009
New Revision: 90499
URL: http://llvm.org/viewvc/llvm-project?rev=90499&view=rev
Log:
More template-logic for MemRegion construction out of MemRegion.h and into MemRegion.cpp.
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=90499&r1=90498&r2=90499&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Thu Dec 3 18:05:57 2009
@@ -769,6 +769,12 @@
BlockDataRegion *getBlockDataRegion(const BlockTextRegion *bc,
const LocationContext *lc);
+ bool isGlobalsRegion(const MemRegion* R) {
+ assert(R);
+ return R == globals;
+ }
+
+private:
template <typename RegionTy, typename A1>
RegionTy* getRegion(const A1 a1);
@@ -782,12 +788,6 @@
RegionTy* getSubRegion(const A1 a1, const A2 a2,
const MemRegion* superRegion);
- bool isGlobalsRegion(const MemRegion* R) {
- assert(R);
- return R == globals;
- }
-
-private:
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
};
@@ -798,157 +798,6 @@
inline ASTContext& MemRegion::getContext() const {
return getMemRegionManager()->getContext();
}
-
-template<typename RegionTy> struct MemRegionManagerTrait;
-
-template <typename RegionTy, typename A1>
-RegionTy* MemRegionManager::getRegion(const A1 a1) {
-
- const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion =
- MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1);
-
- llvm::FoldingSetNodeID ID;
- RegionTy::ProfileRegion(ID, a1, superRegion);
- void* InsertPos;
- RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
- InsertPos));
-
- if (!R) {
- R = (RegionTy*) A.Allocate<RegionTy>();
- new (R) RegionTy(a1, superRegion);
- Regions.InsertNode(R, InsertPos);
- }
-
- return R;
-}
-
-template <typename RegionTy, typename A1>
-RegionTy* MemRegionManager::getSubRegion(const A1 a1,
- const MemRegion *superRegion) {
- llvm::FoldingSetNodeID ID;
- RegionTy::ProfileRegion(ID, a1, superRegion);
- void* InsertPos;
- RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
- InsertPos));
-
- if (!R) {
- R = (RegionTy*) A.Allocate<RegionTy>();
- new (R) RegionTy(a1, superRegion);
- Regions.InsertNode(R, InsertPos);
- }
-
- 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;
-}
-
-template <typename RegionTy, typename A1, typename A2>
-RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2,
- const MemRegion *superRegion) {
-
- 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,
- const CompoundLiteralExpr *CL) {
-
- return CL->isFileScope() ? MRMgr.getGlobalsRegion()
- : MRMgr.getStackRegion();
- }
-};
-
-template <> struct MemRegionManagerTrait<StringRegion> {
- typedef MemSpaceRegion SuperRegionTy;
- static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
- const StringLiteral*) {
- return MRMgr.getGlobalsRegion();
- }
-};
-
-template <> struct MemRegionManagerTrait<VarRegion> {
- typedef MemRegion SuperRegionTy;
- static const SuperRegionTy* getSuperRegion(MemRegionManager &MRMgr,
- const VarDecl *D,
- const LocationContext *LC) {
-
- // FIXME: Make stack regions have a location context?
-
- if (D->hasLocalStorage()) {
- return isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
- ? MRMgr.getStackArgumentsRegion() : MRMgr.getStackRegion();
- }
-
- return MRMgr.getGlobalsRegion();
- }
-};
-
-template <> struct MemRegionManagerTrait<SymbolicRegion> {
- typedef MemRegion SuperRegionTy;
- static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
- SymbolRef) {
- return MRMgr.getUnknownRegion();
- }
-};
-
-template<> struct MemRegionManagerTrait<FunctionTextRegion> {
- typedef MemSpaceRegion SuperRegionTy;
- static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
- const FunctionDecl*) {
- return MRMgr.getCodeRegion();
- }
-};
-template<> struct MemRegionManagerTrait<BlockTextRegion> {
- typedef MemSpaceRegion SuperRegionTy;
- static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
- const BlockDecl*, CanQualType) {
- return MRMgr.getCodeRegion();
- }
-};
} // end clang namespace
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=90499&r1=90498&r2=90499&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Thu Dec 3 18:05:57 2009
@@ -22,6 +22,161 @@
using namespace clang;
//===----------------------------------------------------------------------===//
+// MemRegion Construction.
+//===----------------------------------------------------------------------===//
+
+template<typename RegionTy> struct MemRegionManagerTrait;
+
+template <typename RegionTy, typename A1>
+RegionTy* MemRegionManager::getRegion(const A1 a1) {
+
+ const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion =
+ MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1);
+
+ llvm::FoldingSetNodeID ID;
+ RegionTy::ProfileRegion(ID, a1, superRegion);
+ void* InsertPos;
+ RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
+ InsertPos));
+
+ if (!R) {
+ R = (RegionTy*) A.Allocate<RegionTy>();
+ new (R) RegionTy(a1, superRegion);
+ Regions.InsertNode(R, InsertPos);
+ }
+
+ return R;
+}
+
+template <typename RegionTy, typename A1>
+RegionTy* MemRegionManager::getSubRegion(const A1 a1,
+ const MemRegion *superRegion) {
+ llvm::FoldingSetNodeID ID;
+ RegionTy::ProfileRegion(ID, a1, superRegion);
+ void* InsertPos;
+ RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
+ InsertPos));
+
+ if (!R) {
+ R = (RegionTy*) A.Allocate<RegionTy>();
+ new (R) RegionTy(a1, superRegion);
+ Regions.InsertNode(R, InsertPos);
+ }
+
+ 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;
+}
+
+template <typename RegionTy, typename A1, typename A2>
+RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2,
+ const MemRegion *superRegion) {
+
+ 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,
+ const CompoundLiteralExpr *CL) {
+
+ return CL->isFileScope() ? MRMgr.getGlobalsRegion()
+ : MRMgr.getStackRegion();
+ }
+};
+
+template <> struct MemRegionManagerTrait<StringRegion> {
+ typedef MemSpaceRegion SuperRegionTy;
+ static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
+ const StringLiteral*) {
+ return MRMgr.getGlobalsRegion();
+ }
+};
+
+template <> struct MemRegionManagerTrait<VarRegion> {
+ typedef MemRegion SuperRegionTy;
+ static const SuperRegionTy* getSuperRegion(MemRegionManager &MRMgr,
+ const VarDecl *D,
+ const LocationContext *LC) {
+
+ // FIXME: Make stack regions have a location context?
+
+ if (D->hasLocalStorage()) {
+ return isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)
+ ? MRMgr.getStackArgumentsRegion() : MRMgr.getStackRegion();
+ }
+
+ return MRMgr.getGlobalsRegion();
+ }
+};
+
+template <> struct MemRegionManagerTrait<SymbolicRegion> {
+ typedef MemRegion SuperRegionTy;
+ static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
+ SymbolRef) {
+ return MRMgr.getUnknownRegion();
+ }
+};
+
+template<> struct MemRegionManagerTrait<FunctionTextRegion> {
+ typedef MemSpaceRegion SuperRegionTy;
+ static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
+ const FunctionDecl*) {
+ return MRMgr.getCodeRegion();
+ }
+};
+template<> struct MemRegionManagerTrait<BlockTextRegion> {
+ typedef MemSpaceRegion SuperRegionTy;
+ static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
+ const BlockDecl*, CanQualType) {
+ return MRMgr.getCodeRegion();
+ }
+};
+
+//===----------------------------------------------------------------------===//
// Object destruction.
//===----------------------------------------------------------------------===//
More information about the cfe-commits
mailing list