]> granicus.if.org Git - clang/commitdiff
Add RegionStore support for the implicit object region that 'self' references. This...
authorTed Kremenek <kremenek@apple.com>
Thu, 22 Jan 2009 23:43:57 +0000 (23:43 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 22 Jan 2009 23:43:57 +0000 (23:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62814 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/RegionStore.cpp
test/Analysis/ObjCProperties.m
test/Analysis/refcnt_naming.m

index 6f0ec1d0b73ba180b421c65ac239ea093ae09e0b..ec801d47f28a47203ddae00ad7b8672dc0108848 100644 (file)
@@ -110,13 +110,19 @@ class VISIBILITY_HIDDEN RegionStoreManager : public StoreManager {
   RegionViews::Factory RVFactory;
 
   GRStateManager& StateMgr;
+  const MemRegion* SelfRegion;
+  const ImplicitParamDecl *SelfDecl;
 
 public:
   RegionStoreManager(GRStateManager& mgr) 
     : StoreManager(mgr.getAllocator()),
       RBFactory(mgr.getAllocator()),
       RVFactory(mgr.getAllocator()),
-      StateMgr(mgr) {}
+      StateMgr(mgr), SelfRegion(0), SelfDecl(0) {
+    if (const ObjCMethodDecl* MD =
+          dyn_cast<ObjCMethodDecl>(&StateMgr.getCodeDecl()))
+      SelfDecl = MD->getSelfDecl();
+  }
 
   virtual ~RegionStoreManager() {}
 
@@ -187,8 +193,16 @@ public:
   ///  'this' object (C++).  When used when analyzing a normal function this
   ///  method returns NULL.
   const MemRegion* getSelfRegion(Store) {
-    assert (false && "Not implemented.");
-    return 0;
+    if (!SelfDecl)
+      return 0;
+    
+    if (!SelfRegion) {
+      const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(&StateMgr.getCodeDecl());
+      SelfRegion = MRMgr.getObjCObjectRegion(MD->getClassInterface(),
+                                             MRMgr.getHeapRegion());
+    }
+    
+    return SelfRegion;
   }
   
   /// RemoveDeadBindings - Scans the RegionStore of 'state' for dead values.
@@ -563,9 +577,14 @@ SVal RegionStoreManager::Retrieve(const GRState* St, Loc L, QualType T) {
   // function/method.  These are either symbolic values or 'undefined'.
 
   // We treat function parameters as symbolic values.
-  if (const VarRegion* VR = dyn_cast<VarRegion>(R))
-    if (isa<ParmVarDecl>(VR->getDecl()))
+  if (const VarRegion* VR = dyn_cast<VarRegion>(R)) {
+    const VarDecl *VD = VR->getDecl();
+    
+    if (isa<ParmVarDecl>(VD))
       return SVal::GetRValueSymbolVal(getSymbolManager(), VR);
+    else if (VD == SelfDecl)
+      return loc::MemRegionVal(getSelfRegion(0));
+  }
   
   if (MRMgr.onStack(R) || MRMgr.onHeap(R)) {
     // All stack variables are considered to have undefined values
index f2f18b5771150aabbb33e7ff27f126e208c0a080..7ce434fbfa13170addbf3a8dd09106ef64cb19e3 100644 (file)
@@ -1,4 +1,6 @@
-// RUN: clang -analyze -checker-simple %s -verify
+// RUN: clang -analyze -checker-simple %s -verify &&
+// RUN: clang -analyze -checker-cfref -analyzer-store-basic %s -verify &&
+// RUN: clang -analyze -checker-cfref -analyzer-store-region %s -verify
 
 // The point of this test cases is to exercise properties in the static
 // analyzer
index 3c86853b47ee840c1a3dec8132790316b9cb235b..44ccf27a5662be3afad8eec14bef9a98c81008c0 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: clang -analyze -checker-cfref -verify %s
+// RUN: clang -analyze -checker-cfref -analyzer-store-basic -verify %s &&
+// RUN: clang -analyze -checker-cfref -analyzer-store-region -verify %s
 
 typedef const struct __CFString * CFStringRef;
 typedef const struct __CFAllocator * CFAllocatorRef;