]> granicus.if.org Git - clang/commitdiff
Fix:
authorTed Kremenek <kremenek@apple.com>
Fri, 5 Jun 2009 23:18:01 +0000 (23:18 +0000)
committerTed Kremenek <kremenek@apple.com>
Fri, 5 Jun 2009 23:18:01 +0000 (23:18 +0000)
<rdar://problem/6948053> False positive: object substitution during -init* methods warns about returning +0 when using -fobjc-gc-only

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72971 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFRefCount.cpp
test/Analysis/retain-release-gc-only.m

index 56ab0eb4f6ea2a50bc1a8f4489eabcde9918d7bd..532d16da0f0e8149afbc91b6439af653af83b023 100644 (file)
@@ -636,7 +636,11 @@ class VISIBILITY_HIDDEN RetainSummaryManager {
   /// 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 @@ public:
      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 @@ RetainSummaryManager::getInitMethodSummary(QualType RetTy) {
   // '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 @@ void RetainSummaryManager::InitializeMethodSummaries() {
   // 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);  
index 26765c3ac676af8d2a8179f8bb3627b6a12d86f7..ec33a57d3303df96c2ebead1a4ad7bd97e770e58 100644 (file)
@@ -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 @@ typedef struct _NSZone NSZone;
 @end  @protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;
 @end
 @interface NSObject <NSObject> {}
+- (Class)class;
 + (id)alloc;
 + (id)allocWithZone:(NSZone *)zone;
 @end   typedef float CGFloat;
@@ -172,6 +175,28 @@ void f5b() {
 }
 @end
 
+//===----------------------------------------------------------------------===//
+// <rdar://problem/6948053> False positive: object substitution during -init*
+//   methods warns about returning +0 when using -fobjc-gc-only
+//===----------------------------------------------------------------------===//
+
+@interface MyClassRdar6948053 : NSObject
+- (id) init;
++ (id) shared;
+@end
+
+@implementation MyClassRdar6948053
++(id) shared {
+  return (id) 0;
+}
+- (id) init
+{
+  Class myClass = [self class];  
+  [self release];
+  return [[myClass shared] retain]; // no-warning
+}
+@end
+
 //===----------------------------------------------------------------------===//
 // Tests of ownership attributes.
 //===----------------------------------------------------------------------===//