[cfe-commits] r58107 - in /cfe/trunk: include/clang/Analysis/PathSensitive/GRState.h include/clang/Analysis/PathSensitive/Store.h lib/Analysis/BasicObjCFoundationChecks.cpp lib/Analysis/BasicStore.cpp lib/Analysis/GRExprEngine.cpp lib/Analysis/RegionStore.cpp
Ted Kremenek
kremenek at apple.com
Fri Oct 24 13:32:17 PDT 2008
Author: kremenek
Date: Fri Oct 24 15:32:16 2008
New Revision: 58107
URL: http://llvm.org/viewvc/llvm-project?rev=58107&view=rev
Log:
Added method "getSelfRegion" to Store. This method returns the region associated with the "this" or "self" object (C++ and Objective-C respectively).
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h
cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
cfe/trunk/lib/Analysis/BasicStore.cpp
cfe/trunk/lib/Analysis/GRExprEngine.cpp
cfe/trunk/lib/Analysis/RegionStore.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=58107&r1=58106&r2=58107&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/GRState.h Fri Oct 24 15:32:16 2008
@@ -266,6 +266,9 @@
/// cfg - The CFG for the analyzed function/method.
CFG& cfg;
+
+ /// codedecl - The Decl representing the function/method being analyzed.
+ const Decl& codedecl;
/// TF - Object that represents a bundle of transfer functions
/// for manipulating and creating SVals.
@@ -294,7 +297,8 @@
GRStateManager(ASTContext& Ctx,
StoreManagerCreator CreateStoreManager,
ConstraintManagerCreator CreateConstraintManager,
- llvm::BumpPtrAllocator& alloc, CFG& c, LiveVariables& L)
+ llvm::BumpPtrAllocator& alloc, CFG& c,
+ const Decl& cd, LiveVariables& L)
: EnvMgr(alloc),
ISetFactory(alloc),
GDMFactory(alloc),
@@ -302,6 +306,7 @@
SymMgr(alloc),
Alloc(alloc),
cfg(c),
+ codedecl(cd),
Liveness(L) {
StoreMgr.reset((*CreateStoreManager)(*this));
ConstraintMgr.reset((*CreateConstraintManager)(*this));
@@ -312,6 +317,7 @@
const GRState* getInitialState();
ASTContext& getContext() { return BasicVals.getContext(); }
+ const Decl& getCodeDecl() { return codedecl; }
BasicValueFactory& getBasicVals() { return BasicVals; }
const BasicValueFactory& getBasicVals() const { return BasicVals; }
SymbolManager& getSymbolManager() { return SymMgr; }
@@ -341,6 +347,10 @@
return getRegionManager().getVarRegion(D);
}
+ const MemRegion* getSelfRegion(const GRState* state) {
+ return StoreMgr->getSelfRegion(state->getStore());
+ }
+
// Get the lvalue for a variable reference.
SVal GetLValue(const GRState* St, const VarDecl* D) {
return StoreMgr->getLValueVar(St, D);
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/Store.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/Store.h?rev=58107&r1=58106&r2=58107&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/Store.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/Store.h Fri Oct 24 15:32:16 2008
@@ -61,7 +61,15 @@
virtual SVal getLValueElement(const GRState* St,
SVal Base, SVal Offset) = 0;
+
+ /// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit
+ /// conversions between arrays and pointers.
virtual SVal ArrayToPointer(SVal Array) = 0;
+
+ /// getSelfRegion - Returns the region for the 'self' (Objective-C) or
+ /// 'this' object (C++). When used when analyzing a normal function this
+ /// method returns NULL.
+ virtual const MemRegion* getSelfRegion(Store store) = 0;
virtual Store
RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp?rev=58107&r1=58106&r2=58107&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Fri Oct 24 15:32:16 2008
@@ -508,7 +508,7 @@
return false;
- QualType T = Ctx.getCanonicalType(R->getType());
+ QualType T = Ctx.getCanonicalType(R->getType(Ctx));
// FIXME: If the pointee isn't an integer type, should we flag a warning?
// People can do weird stuff with pointers.
Modified: cfe/trunk/lib/Analysis/BasicStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicStore.cpp?rev=58107&r1=58106&r2=58107&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicStore.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicStore.cpp Fri Oct 24 15:32:16 2008
@@ -27,20 +27,19 @@
VarBindingsTy::Factory VBFactory;
GRStateManager& StateMgr;
MemRegionManager MRMgr;
+ const MemRegion* SelfRegion;
public:
BasicStoreManager(GRStateManager& mgr)
- : StateMgr(mgr), MRMgr(StateMgr.getAllocator()) {}
+ : StateMgr(mgr), MRMgr(StateMgr.getAllocator()), SelfRegion(0) {}
- virtual ~BasicStoreManager() {}
+ ~BasicStoreManager() {}
- virtual SVal Retrieve(Store St, Loc LV, QualType T);
- virtual Store Bind(Store St, Loc LV, SVal V);
- virtual Store Remove(Store St, Loc LV);
-
- virtual Store getInitialStore();
-
- virtual MemRegionManager& getRegionManager() { return MRMgr; }
+ SVal Retrieve(Store St, Loc LV, QualType T);
+ Store Bind(Store St, Loc LV, SVal V);
+ Store Remove(Store St, Loc LV);
+ Store getInitialStore();
+ MemRegionManager& getRegionManager() { return MRMgr; }
// FIXME: Investigate what is using this. This method should be removed.
virtual Loc getLoc(const VarDecl* VD) {
@@ -52,26 +51,31 @@
SVal getLValueField(const GRState* St, SVal Base, const FieldDecl* D);
SVal getLValueElement(const GRState* St, SVal Base, SVal Offset);
+ /// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit
+ /// conversions between arrays and pointers.
SVal ArrayToPointer(SVal Array) { return Array; }
- virtual Store
- RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
- llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
- LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols);
-
- virtual void iterBindings(Store store, BindingsHandler& f);
-
- virtual Store AddDecl(Store store,
- const VarDecl* VD, Expr* Ex,
- SVal InitVal = UndefinedVal(), unsigned Count = 0);
+ /// getSelfRegion - Returns the region for the 'self' (Objective-C) or
+ /// 'this' object (C++). When used when analyzing a normal function this
+ /// method returns NULL.
+ const MemRegion* getSelfRegion(Store) {
+ return SelfRegion;
+ }
+
+ Store RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
+ llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
+ LiveSymbolsTy& LSymbols, DeadSymbolsTy& DSymbols);
+
+ void iterBindings(Store store, BindingsHandler& f);
+
+ Store AddDecl(Store store, const VarDecl* VD, Expr* Ex,
+ SVal InitVal = UndefinedVal(), unsigned Count = 0);
static inline VarBindingsTy GetVarBindings(Store store) {
return VarBindingsTy(static_cast<const VarBindingsTy::TreeTy*>(store));
}
- virtual void print(Store store, std::ostream& Out,
- const char* nl, const char *sep);
-
+ void print(Store store, std::ostream& Out, const char* nl, const char *sep);
};
} // end anonymous namespace
@@ -291,6 +295,7 @@
}
Store BasicStoreManager::getInitialStore() {
+
// The LiveVariables information already has a compilation of all VarDecls
// used in the function. Iterate through this set, and "symbolicate"
// any VarDecl whose value originally comes from outside the function.
@@ -303,7 +308,22 @@
for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) {
NamedDecl* ND = const_cast<NamedDecl*>(I->first);
- if (VarDecl* VD = dyn_cast<VarDecl>(ND)) {
+ // Handle implicit parameters.
+ if (ImplicitParamDecl* PD = dyn_cast<ImplicitParamDecl>(ND)) {
+ const Decl& CD = StateMgr.getCodeDecl();
+ if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(&CD)) {
+ if (MD->getSelfDecl() == PD) {
+ // Create a region for "self".
+ assert (SelfRegion == 0);
+ SelfRegion = MRMgr.getObjCObjectRegion(MD->getClassInterface(),
+ MRMgr.getHeapRegion());
+
+ St = Bind(St, loc::MemRegionVal(MRMgr.getVarRegion(PD)),
+ loc::MemRegionVal(SelfRegion));
+ }
+ }
+ }
+ else if (VarDecl* VD = dyn_cast<VarDecl>(ND)) {
// Punt on static variables for now.
if (VD->getStorageClass() == VarDecl::Static)
continue;
Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=58107&r1=58106&r2=58107&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Fri Oct 24 15:32:16 2008
@@ -122,7 +122,7 @@
Liveness(L),
Builder(NULL),
StateMgr(G.getContext(), SMC,
- CreateBasicConstraintManager, G.getAllocator(), G.getCFG(), L),
+ CreateBasicConstraintManager, G.getAllocator(), cfg, CD, L),
SymMgr(StateMgr.getSymbolManager()),
CurrentStmt(NULL),
NSExceptionII(NULL), NSExceptionInstanceRaiseSelectors(NULL),
Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=58107&r1=58106&r2=58107&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Fri Oct 24 15:32:16 2008
@@ -66,6 +66,14 @@
}
Store getInitialStore();
+
+ /// getSelfRegion - Returns the region for the 'self' (Objective-C) or
+ /// 'this' object (C++). When used when analyzing a normal function this
+ /// method returns NULL.
+ const MemRegion* getSelfRegion(Store) {
+ assert (false && "Not implemented.");
+ return 0;
+ }
Store RemoveDeadBindings(Store store, Stmt* Loc, const LiveVariables& Live,
llvm::SmallVectorImpl<const MemRegion*>& RegionRoots,
More information about the cfe-commits
mailing list