[cfe-commits] r73935 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRState.h include/clang/Analysis/PathSensitive/MemRegion.h include/clang/Analysis/PathSensitive/ValueManager.h lib/Analysis/BasicStore.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/GRExprEngineInternalChecks.cpp lib/Analysis/GRSimpleVals.cpp lib/Analysis/MemRegion.cpp
Ted Kremenek
kremenek at apple.com
Mon Jun 22 17:46:41 PDT 2009
Author: kremenek
Date: Mon Jun 22 19:46:41 2009
New Revision: 73935
URL: http://llvm.org/viewvc/llvm-project?rev=73935&view=rev
Log:
MemRegions:
- Embed a reference to MemRegionManager objects in MemSpaceRegion objects
- Use this embedded reference for MemRegion objects to access ASTContext objects without external help
- Use this access to ASTContext to simplify 'isBoundable' (no ASTContext& argument required)
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h
cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h
cfe/trunk/lib/Analysis/BasicStore.cpp
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
cfe/trunk/lib/Analysis/GRSimpleVals.cpp
cfe/trunk/lib/Analysis/MemRegion.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Mon Jun 22 19:46:41 2009
@@ -613,7 +613,7 @@
// We only want to do fetches from regions that we can actually bind
// values. For example, SymbolicRegions of type 'id<...>' cannot
// have direct bindings (but their can be bindings on their subregions).
- if (!R->isBoundable(getContext()))
+ if (!R->isBoundable())
return UnknownVal();
if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
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=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/MemRegion.h Mon Jun 22 19:46:41 2009
@@ -59,11 +59,14 @@
protected:
MemRegion(Kind k) : kind(k) {}
virtual ~MemRegion();
+ ASTContext &getContext() const;
public:
// virtual MemExtent getExtent(MemRegionManager& mrm) const = 0;
virtual void Profile(llvm::FoldingSetNodeID& ID) const = 0;
-
+
+ virtual MemRegionManager* getMemRegionManager() const = 0;
+
std::string getString() const;
virtual void print(llvm::raw_ostream& os) const;
@@ -72,7 +75,7 @@
template<typename RegionTy> const RegionTy* getAs() const;
- virtual bool isBoundable(ASTContext&) const { return true; }
+ virtual bool isBoundable() const { return true; }
static bool classof(const MemRegion*) { return true; }
};
@@ -81,14 +84,23 @@
/// for example, the set of global variables, the stack frame, etc.
class MemSpaceRegion : public MemRegion {
friend class MemRegionManager;
- MemSpaceRegion() : MemRegion(MemSpaceRegionKind) {}
+
+protected:
+ MemRegionManager *Mgr;
+
+ MemSpaceRegion(MemRegionManager *mgr) : MemRegion(MemSpaceRegionKind),
+ Mgr(mgr) {}
+ MemRegionManager* getMemRegionManager() const {
+ return Mgr;
+ }
+
public:
//RegionExtent getExtent() const { return UndefinedExtent(); }
void Profile(llvm::FoldingSetNodeID& ID) const;
- bool isBoundable(ASTContext &) const { return false; }
+ bool isBoundable() const { return false; }
static bool classof(const MemRegion* R) {
return R->getKind() == MemSpaceRegionKind;
@@ -101,11 +113,12 @@
protected:
const MemRegion* superRegion;
SubRegion(const MemRegion* sReg, Kind k) : MemRegion(k), superRegion(sReg) {}
-
public:
const MemRegion* getSuperRegion() const {
return superRegion;
}
+
+ MemRegionManager* getMemRegionManager() const;
bool isSubRegionOf(const MemRegion* R) const;
@@ -164,8 +177,8 @@
return getLocationType(C)->getDesugaredType();
}
- bool isBoundable(ASTContext &C) const {
- return !getValueType(C).isNull();
+ bool isBoundable() const {
+ return !getValueType(getContext()).isNull();
}
static bool classof(const MemRegion* R) {
@@ -229,7 +242,7 @@
return const_cast<SymbolRef>(static_cast<const SymbolRef>(Data));
}
- bool isBoundable(ASTContext&) const { return false; }
+ bool isBoundable() const { return false; }
virtual void print(llvm::raw_ostream& os) const;
@@ -329,7 +342,7 @@
return PTy->getPointeeType();
}
- bool isBoundable(ASTContext &C) const {
+ bool isBoundable() const {
return isa<PointerType>(LValueType);
}
@@ -559,6 +572,7 @@
//===----------------------------------------------------------------------===//
class MemRegionManager {
+ ASTContext &C;
llvm::BumpPtrAllocator& A;
llvm::FoldingSet<MemRegion> Regions;
@@ -569,11 +583,13 @@
MemSpaceRegion* code;
public:
- MemRegionManager(llvm::BumpPtrAllocator& a)
- : A(a), globals(0), stack(0), heap(0), unknown(0), code(0) {}
+ MemRegionManager(ASTContext &c, llvm::BumpPtrAllocator& a)
+ : C(c), A(a), globals(0), stack(0), heap(0), unknown(0), code(0) {}
~MemRegionManager() {}
+ ASTContext &getContext() { return C; }
+
/// getStackRegion - Retrieve the memory region associated with the
/// current stack frame.
MemSpaceRegion* getStackRegion();
@@ -666,9 +682,13 @@
};
//===----------------------------------------------------------------------===//
-// Out-of-line member template definitions.
+// Out-of-line member definitions.
//===----------------------------------------------------------------------===//
+inline ASTContext& MemRegion::getContext() const {
+ return getMemRegionManager()->getContext();
+}
+
template<typename RegionTy> struct MemRegionManagerTrait;
template <typename RegionTy, typename A1>
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/ValueManager.h Mon Jun 22 19:46:41 2009
@@ -39,7 +39,7 @@
ValueManager(llvm::BumpPtrAllocator &alloc, ASTContext &context)
: Context(context), BasicVals(Context, alloc),
SymMgr(Context, BasicVals, alloc),
- MemMgr(alloc) {}
+ MemMgr(Context, alloc) {}
// Accessors to submanagers.
Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Mon Jun 22 19:46:41 2009
@@ -351,7 +351,7 @@
// are incompatible. This may also cause lots of breakage
// elsewhere. Food for thought.
if (const TypedRegion *TyR = dyn_cast<TypedRegion>(R)) {
- if (TyR->isBoundable(C) &&
+ if (TyR->isBoundable() &&
Loc::IsLocType(TyR->getValueType(C)))
V = X->getLoc();
}
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Mon Jun 22 19:46:41 2009
@@ -2835,7 +2835,7 @@
// Remove any existing reference-count binding.
if (Sym) state = state->remove<RefBindings>(Sym);
- if (R->isBoundable(Ctx)) {
+ if (R->isBoundable()) {
// Set the value of the variable to be a conjured symbol.
unsigned Count = Builder.getCurrentBlockCount();
QualType T = R->getValueType(Ctx);
Modified: cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Mon Jun 22 19:46:41 2009
@@ -717,7 +717,7 @@
if (isa<loc::ConcreteInt>(V)) {
bool b = false;
ASTContext &C = BRC.getASTContext();
- if (R->isBoundable(C)) {
+ if (R->isBoundable()) {
if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
if (C.isObjCObjectPointerType(TR->getValueType(C))) {
os << "initialized to nil";
@@ -748,7 +748,7 @@
if (isa<loc::ConcreteInt>(V)) {
bool b = false;
ASTContext &C = BRC.getASTContext();
- if (R->isBoundable(C)) {
+ if (R->isBoundable()) {
if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) {
if (C.isObjCObjectPointerType(TR->getValueType(C))) {
os << "nil object reference stored to ";
Modified: cfe/trunk/lib/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRSimpleVals.cpp?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Mon Jun 22 19:46:41 2009
@@ -367,8 +367,8 @@
if (isa<loc::MemRegionVal>(V)) {
const MemRegion *R = cast<loc::MemRegionVal>(V).getRegion();
- if (R->isBoundable(Eng.getContext()))
- St = StateMgr.BindLoc(St, cast<Loc>(V), UnknownVal());
+ if (R->isBoundable())
+ St = StateMgr.BindLoc(St, cast<Loc>(V), UnknownVal());
} else if (isa<nonloc::LocAsInteger>(V))
St = StateMgr.BindLoc(St, cast<nonloc::LocAsInteger>(V).getLoc(),
UnknownVal());
Modified: cfe/trunk/lib/Analysis/MemRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/MemRegion.cpp?rev=73935&r1=73934&r2=73935&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/MemRegion.cpp (original)
+++ cfe/trunk/lib/Analysis/MemRegion.cpp Mon Jun 22 19:46:41 2009
@@ -37,6 +37,19 @@
return false;
}
+
+MemRegionManager* SubRegion::getMemRegionManager() const {
+ const SubRegion* r = this;
+ do {
+ const MemRegion *superRegion = r->getSuperRegion();
+ if (const SubRegion *sr = dyn_cast<SubRegion>(superRegion)) {
+ r = sr;
+ continue;
+ }
+ return superRegion->getMemRegionManager();
+ } while (1);
+}
+
void MemSpaceRegion::Profile(llvm::FoldingSetNodeID& ID) const {
ID.AddInteger((unsigned)getKind());
}
@@ -192,13 +205,12 @@
// MemRegionManager methods.
//===----------------------------------------------------------------------===//
-MemSpaceRegion* MemRegionManager::LazyAllocate(MemSpaceRegion*& region) {
-
+MemSpaceRegion* MemRegionManager::LazyAllocate(MemSpaceRegion*& region) {
if (!region) {
region = (MemSpaceRegion*) A.Allocate<MemSpaceRegion>();
- new (region) MemSpaceRegion();
+ new (region) MemSpaceRegion(this);
}
-
+
return region;
}
More information about the cfe-commits
mailing list