[cfe-commits] r80047 - in /cfe/trunk: lib/Analysis/RegionStore.cpp test/Analysis/rdar-7168531.m

Ted Kremenek kremenek at apple.com
Tue Aug 25 15:55:09 PDT 2009


Author: kremenek
Date: Tue Aug 25 17:55:09 2009
New Revision: 80047

URL: http://llvm.org/viewvc/llvm-project?rev=80047&view=rev
Log:
Handle pointer arithmetic in RegionStoreManager involving Objective-C pointers
when using the non-fragile Objective-C ABI.  This fixes <rdar://problem/7168531>.

Added:
    cfe/trunk/test/Analysis/rdar-7168531.m
Modified:
    cfe/trunk/lib/Analysis/RegionStore.cpp

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

==============================================================================
--- cfe/trunk/lib/Analysis/RegionStore.cpp (original)
+++ cfe/trunk/lib/Analysis/RegionStore.cpp Tue Aug 25 17:55:09 2009
@@ -750,8 +750,14 @@
     case MemRegion::SymbolicRegionKind: {
       const SymbolicRegion *SR = cast<SymbolicRegion>(MR);
       SymbolRef Sym = SR->getSymbol();
-      QualType T = Sym->getType(getContext());      
-      QualType EleTy = T->getAs<PointerType>()->getPointeeType();        
+      QualType T = Sym->getType(getContext());
+      QualType EleTy;
+      
+      if (const PointerType *PT = T->getAs<PointerType>())
+        EleTy = PT->getPointeeType();
+      else
+        EleTy = T->getAsObjCObjectPointerType()->getPointeeType();
+      
       SVal ZeroIdx = ValMgr.makeZeroArrayIndex();
       ER = MRMgr.getElementRegion(EleTy, ZeroIdx, SR, getContext());
       break;        

Added: cfe/trunk/test/Analysis/rdar-7168531.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/rdar-7168531.m?rev=80047&view=auto

==============================================================================
--- cfe/trunk/test/Analysis/rdar-7168531.m (added)
+++ cfe/trunk/test/Analysis/rdar-7168531.m Tue Aug 25 17:55:09 2009
@@ -0,0 +1,19 @@
+// RUN: clang-cc -analyze -checker-cfref -triple i386-apple-darwin10 -analyzer-store=region &&
+// RUN: clang-cc -analyze -checker-cfref -triple i386-apple-darwin10 -analyzer-store=basic
+
+// Note that the target triple is important for this test case.  It specifies that we use the
+// fragile Objective-C ABI.
+
+ at interface Foo {
+  int x;
+}
+ at end
+
+ at implementation Foo
+static Foo* bar(Foo *p) {
+  if (p->x)
+   return ++p;  // This is only valid for the fragile ABI.
+
+  return p;
+}
+ at end





More information about the cfe-commits mailing list