diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-10-24 20:32:16 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-10-24 20:32:16 +0000 |
commit | 9deb0e35dea0f82691fadb60b61f45887ba67aba (patch) | |
tree | 3e4a64cf5410d3c066c2df2382e5f0d60060ef16 /lib/Analysis | |
parent | a7f1b9e8804012ed8df25d93f5a06cb26c9bbd2b (diff) |
Added method "getSelfRegion" to Store. This method returns the region associated with the "this" or "self" object (C++ and Objective-C respectively).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@58107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/BasicObjCFoundationChecks.cpp | 2 | ||||
-rw-r--r-- | lib/Analysis/BasicStore.cpp | 62 | ||||
-rw-r--r-- | lib/Analysis/GRExprEngine.cpp | 2 | ||||
-rw-r--r-- | lib/Analysis/RegionStore.cpp | 8 |
4 files changed, 51 insertions, 23 deletions
diff --git a/lib/Analysis/BasicObjCFoundationChecks.cpp b/lib/Analysis/BasicObjCFoundationChecks.cpp index 96a7ea1c16..033dc02cd7 100644 --- a/lib/Analysis/BasicObjCFoundationChecks.cpp +++ b/lib/Analysis/BasicObjCFoundationChecks.cpp @@ -508,7 +508,7 @@ bool AuditCFNumberCreate::Audit(ExplodedNode<GRState>* N,GRStateManager&){ 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. diff --git a/lib/Analysis/BasicStore.cpp b/lib/Analysis/BasicStore.cpp index 70631ac5bf..e12b9ea0a1 100644 --- a/lib/Analysis/BasicStore.cpp +++ b/lib/Analysis/BasicStore.cpp @@ -27,20 +27,19 @@ class VISIBILITY_HIDDEN BasicStoreManager : public StoreManager { 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 @@ public: 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); + /// 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); - virtual void iterBindings(Store store, BindingsHandler& f); + void iterBindings(Store store, BindingsHandler& f); - virtual Store AddDecl(Store store, - const VarDecl* VD, Expr* Ex, - SVal InitVal = UndefinedVal(), unsigned Count = 0); + 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 @@ BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, } 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 @@ Store BasicStoreManager::getInitialStore() { 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; diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp index 996fea9f63..acfd7a1993 100644 --- a/lib/Analysis/GRExprEngine.cpp +++ b/lib/Analysis/GRExprEngine.cpp @@ -122,7 +122,7 @@ GRExprEngine::GRExprEngine(CFG& cfg, Decl& CD, ASTContext& Ctx, 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), diff --git a/lib/Analysis/RegionStore.cpp b/lib/Analysis/RegionStore.cpp index 5c75ab369e..e2b6b13e64 100644 --- a/lib/Analysis/RegionStore.cpp +++ b/lib/Analysis/RegionStore.cpp @@ -66,6 +66,14 @@ public: } 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, |