[cfe-commits] r62814 - in /cfe/trunk: lib/Analysis/RegionStore.cpp test/Analysis/ObjCProperties.m test/Analysis/refcnt_naming.m

Ted Kremenek kremenek at apple.com
Thu Jan 22 15:43:57 PST 2009


Author: kremenek
Date: Thu Jan 22 17:43:57 2009
New Revision: 62814

URL: http://llvm.org/viewvc/llvm-project?rev=62814&view=rev
Log:
Add RegionStore support for the implicit object region that 'self' references.  This causes tests 'ObjCProperties.m' and 'refcnt_naming.m' to now pass with RegionStore.

Modified:
    cfe/trunk/lib/Analysis/RegionStore.cpp
    cfe/trunk/test/Analysis/ObjCProperties.m
    cfe/trunk/test/Analysis/refcnt_naming.m

Modified: cfe/trunk/lib/Analysis/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RegionStore.cpp?rev=62814&r1=62813&r2=62814&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Thu Jan 22 17:43:57 2009
@@ -110,13 +110,19 @@
   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 @@
   ///  '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 @@
   // 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

Modified: cfe/trunk/test/Analysis/ObjCProperties.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/ObjCProperties.m?rev=62814&r1=62813&r2=62814&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/ObjCProperties.m (original)
+++ cfe/trunk/test/Analysis/ObjCProperties.m Thu Jan 22 17:43:57 2009
@@ -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

Modified: cfe/trunk/test/Analysis/refcnt_naming.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/refcnt_naming.m?rev=62814&r1=62813&r2=62814&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/refcnt_naming.m (original)
+++ cfe/trunk/test/Analysis/refcnt_naming.m Thu Jan 22 17:43:57 2009
@@ -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;





More information about the cfe-commits mailing list