[cfe-commits] r72971 - in /cfe/trunk: lib/Analysis/CFRefCount.cpp test/Analysis/retain-release-gc-only.m

Ted Kremenek kremenek at apple.com
Fri Jun 5 16:18:02 PDT 2009


Author: kremenek
Date: Fri Jun  5 18:18:01 2009
New Revision: 72971

URL: http://llvm.org/viewvc/llvm-project?rev=72971&view=rev
Log:
Fix:

<rdar://problem/6948053> False positive: object substitution during -init* methods warns about returning +0 when using -fobjc-gc-only


Modified:
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/test/Analysis/retain-release-gc-only.m

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Jun  5 18:18:01 2009
@@ -636,7 +636,11 @@
   /// ObjCAllocRetE - Default return effect for methods returning Objective-C
   ///  objects.
   RetEffect ObjCAllocRetE;
-  
+
+	/// ObjCInitRetE - Default return effect for init methods returning Objective-C
+  ///  objects.
+  RetEffect ObjCInitRetE;
+	
   RetainSummary DefaultSummary;
   RetainSummary* StopSummary;
   
@@ -776,6 +780,8 @@
      GCEnabled(gcenabled), AF(BPAlloc), ScratchArgs(AF.GetEmptyMap()),
      ObjCAllocRetE(gcenabled ? RetEffect::MakeGCNotOwned()
                              : RetEffect::MakeOwned(RetEffect::ObjC, true)),
+		 ObjCInitRetE(gcenabled ? RetEffect::MakeGCNotOwned()
+														:	RetEffect::MakeOwnedWhenTrackedReceiver()),
      DefaultSummary(AF.GetEmptyMap() /* per-argument effects (none) */,
                     RetEffect::MakeNoRet() /* return effect */,
                     MayEscape, /* default argument effect */
@@ -1156,8 +1162,7 @@
   // 'init' methods conceptually return a newly allocated object and claim
   // the receiver.  
   if (isTrackedObjCObjectType(RetTy) || isTrackedCFObjectType(RetTy))
-    return getPersistentSummary(RetEffect::MakeOwnedWhenTrackedReceiver(),
-                                DecRefMsg);
+    return getPersistentSummary(ObjCInitRetE, DecRefMsg);
   
   return getDefaultSummary();
 }
@@ -1374,8 +1379,7 @@
   // Create the "init" selector.  It just acts as a pass-through for the
   // receiver.
   addNSObjectMethSummary(GetNullarySelector("init", Ctx),
-                 getPersistentSummary(RetEffect::MakeOwnedWhenTrackedReceiver(),
-                 DecRefMsg));
+												 getPersistentSummary(ObjCInitRetE, DecRefMsg));
   
   // The next methods are allocators.
   RetainSummary *AllocSumm = getPersistentSummary(ObjCAllocRetE);  

Modified: cfe/trunk/test/Analysis/retain-release-gc-only.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release-gc-only.m?rev=72971&r1=72970&r2=72971&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/retain-release-gc-only.m (original)
+++ cfe/trunk/test/Analysis/retain-release-gc-only.m Fri Jun  5 18:18:01 2009
@@ -5,6 +5,8 @@
 // Header stuff.
 //===----------------------------------------------------------------------===//
 
+typedef struct objc_class *Class;
+
 typedef unsigned int __darwin_natural_t;
 typedef struct {} div_t;
 typedef unsigned long UInt32;
@@ -56,6 +58,7 @@
 @end  @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;
 @end
 @interface NSObject <NSObject> {}
+- (Class)class;
 + (id)alloc;
 + (id)allocWithZone:(NSZone *)zone;
 @end   typedef float CGFloat;
@@ -173,6 +176,28 @@
 @end
 
 //===----------------------------------------------------------------------===//
+// <rdar://problem/6948053> False positive: object substitution during -init*
+//   methods warns about returning +0 when using -fobjc-gc-only
+//===----------------------------------------------------------------------===//
+
+ at interface MyClassRdar6948053 : NSObject
+- (id) init;
++ (id) shared;
+ at end
+
+ at implementation MyClassRdar6948053
++(id) shared {
+  return (id) 0;
+}
+- (id) init
+{
+  Class myClass = [self class];  
+  [self release];
+  return [[myClass shared] retain]; // no-warning
+}
+ at end
+
+//===----------------------------------------------------------------------===//
 // Tests of ownership attributes.
 //===----------------------------------------------------------------------===//
 





More information about the cfe-commits mailing list