1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -fblocks -verify %s
3 //===----------------------------------------------------------------------===//
4 // The following code is reduced using delta-debugging from Mac OS X headers:
6 // #include <Cocoa/Cocoa.h>
7 // #include <CoreFoundation/CoreFoundation.h>
8 // #include <DiskArbitration/DiskArbitration.h>
9 // #include <QuartzCore/QuartzCore.h>
10 // #include <Quartz/Quartz.h>
11 // #include <IOKit/IOKitLib.h>
13 // It includes the basic definitions for the test cases below.
14 //===----------------------------------------------------------------------===//
17 typedef unsigned int __darwin_natural_t;
18 typedef unsigned long uintptr_t;
19 typedef unsigned int uint32_t;
20 typedef unsigned long long uint64_t;
21 typedef unsigned int UInt32;
22 typedef signed long CFIndex;
23 typedef CFIndex CFByteOrder;
28 static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) {
34 typedef const void * CFTypeRef;
35 typedef const struct __CFString * CFStringRef;
36 typedef const struct __CFAllocator * CFAllocatorRef;
37 extern const CFAllocatorRef kCFAllocatorDefault;
38 extern CFTypeRef CFRetain(CFTypeRef cf);
39 extern void CFRelease(CFTypeRef cf);
43 extern const CFArrayCallBacks kCFTypeArrayCallBacks;
44 typedef const struct __CFArray * CFArrayRef;
45 typedef struct __CFArray * CFMutableArrayRef;
46 extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks);
47 extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
48 extern void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value);
51 CFDictionaryKeyCallBacks;
52 extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;
55 CFDictionaryValueCallBacks;
56 extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks;
57 typedef const struct __CFDictionary * CFDictionaryRef;
58 typedef struct __CFDictionary * CFMutableDictionaryRef;
59 extern CFMutableDictionaryRef CFDictionaryCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
60 typedef UInt32 CFStringEncoding;
62 kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF , kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100 };
63 extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
64 typedef double CFTimeInterval;
65 typedef CFTimeInterval CFAbsoluteTime;
66 extern CFAbsoluteTime CFAbsoluteTimeGetCurrent(void);
67 typedef const struct __CFDate * CFDateRef;
68 extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
69 extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate);
70 typedef __darwin_natural_t natural_t;
71 typedef natural_t mach_port_name_t;
72 typedef mach_port_name_t mach_port_t;
73 typedef int kern_return_t;
74 typedef kern_return_t mach_error_t;
76 kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 };
77 typedef CFIndex CFNumberType;
78 typedef const struct __CFNumber * CFNumberRef;
79 extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
80 typedef const struct __CFAttributedString *CFAttributedStringRef;
81 typedef struct __CFAttributedString *CFMutableAttributedStringRef;
82 extern CFAttributedStringRef CFAttributedStringCreate(CFAllocatorRef alloc, CFStringRef str, CFDictionaryRef attributes) ;
83 extern CFMutableAttributedStringRef CFAttributedStringCreateMutableCopy(CFAllocatorRef alloc, CFIndex maxLength, CFAttributedStringRef aStr) ;
84 extern void CFAttributedStringSetAttribute(CFMutableAttributedStringRef aStr, CFRange range, CFStringRef attrName, CFTypeRef value) ;
85 typedef signed char BOOL;
86 typedef unsigned long NSUInteger;
87 @class NSString, Protocol;
88 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
89 typedef struct _NSZone NSZone;
90 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
92 - (BOOL)isEqual:(id)object;
94 - (oneway void)release;
98 @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone;
99 @end @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone;
100 @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
102 @interface NSObject <NSObject> {}
103 + (id)allocWithZone:(NSZone *)zone;
108 @interface NSObject (NSCoderMethods)
109 - (id)awakeAfterUsingCoder:(NSCoder *)aDecoder;
111 extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
114 NSFastEnumerationState;
115 @protocol NSFastEnumeration - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
116 @end @class NSString, NSDictionary;
117 @interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value;
118 @end @interface NSNumber : NSValue - (char)charValue;
119 - (id)initWithInt:(int)value;
120 @end @class NSString;
121 @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count;
122 @end @interface NSArray (NSArrayCreation) + (id)array;
123 @end @interface NSAutoreleasePool : NSObject {
126 @end extern NSString * const NSBundleDidLoadNotification;
127 typedef double NSTimeInterval;
128 @interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate;
129 @end typedef unsigned short unichar;
130 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
131 - (NSUInteger)length;
132 - (NSString *)stringByAppendingString:(NSString *)aString;
133 - ( const char *)UTF8String;
134 - (id)initWithUTF8String:(const char *)nullTerminatedCString;
135 + (id)stringWithUTF8String:(const char *)nullTerminatedCString;
136 @end @class NSString, NSURL, NSError;
137 @interface NSData : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length;
138 + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;
139 + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;
140 @end @class NSLocale, NSDate, NSCalendar, NSTimeZone, NSError, NSArray, NSMutableDictionary;
141 @interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count;
142 @end @interface NSMutableDictionary : NSDictionary - (void)removeObjectForKey:(id)aKey;
143 - (void)setObject:(id)anObject forKey:(id)aKey;
144 @end @interface NSMutableDictionary (NSMutableDictionaryCreation) + (id)dictionaryWithCapacity:(NSUInteger)numItems;
145 @end typedef double CGFloat;
148 typedef struct CGSize CGSize;
151 typedef struct CGRect CGRect;
152 typedef mach_port_t io_object_t;
153 typedef char io_name_t[128];
154 typedef io_object_t io_iterator_t;
155 typedef io_object_t io_service_t;
156 typedef struct IONotificationPort * IONotificationPortRef;
157 typedef void (*IOServiceMatchingCallback)( void * refcon, io_iterator_t iterator );
158 io_service_t IOServiceGetMatchingService( mach_port_t mainPort, CFDictionaryRef matching );
159 kern_return_t IOServiceGetMatchingServices( mach_port_t mainPort, CFDictionaryRef matching, io_iterator_t * existing );
160 kern_return_t IOServiceAddNotification( mach_port_t mainPort, const io_name_t notificationType, CFDictionaryRef matching, mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) __attribute__((deprecated));
161 kern_return_t IOServiceAddMatchingNotification( IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void * refCon, io_iterator_t * notification );
162 CFMutableDictionaryRef IOServiceMatching( const char * name );
163 CFMutableDictionaryRef IOServiceNameMatching( const char * name );
164 CFMutableDictionaryRef IOBSDNameMatching( mach_port_t mainPort, uint32_t options, const char * bsdName );
165 CFMutableDictionaryRef IOOpenFirmwarePathMatching( mach_port_t mainPort, uint32_t options, const char * path );
166 CFMutableDictionaryRef IORegistryEntryIDMatching( uint64_t entryID );
167 typedef struct __DASession * DASessionRef;
168 extern DASessionRef DASessionCreate( CFAllocatorRef allocator );
169 typedef struct __DADisk * DADiskRef;
170 extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name );
171 extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media );
172 extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk );
173 extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk );
174 @interface NSTask : NSObject - (id)init;
175 @end typedef struct CGColorSpace *CGColorSpaceRef;
176 typedef struct CGImage *CGImageRef;
177 typedef struct CGLayer *CGLayerRef;
178 @interface NSResponder : NSObject <NSCoding> {
180 @end @protocol NSAnimatablePropertyContainer - (id)animator;
181 @end extern NSString *NSAnimationTriggerOrderIn ;
182 @interface NSView : NSResponder <NSAnimatablePropertyContainer> {
184 @end @protocol NSValidatedUserInterfaceItem - (SEL)action;
185 @end @protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem;
186 @end @class NSDate, NSDictionary, NSError, NSException, NSNotification;
187 @interface NSApplication : NSResponder <NSUserInterfaceValidations> {
190 NSTerminateCancel = 0, NSTerminateNow = 1, NSTerminateLater = 2 };
191 typedef NSUInteger NSApplicationTerminateReply;
192 @protocol NSApplicationDelegate <NSObject> @optional - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
193 @end @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView, NSTextView;
194 @interface NSCell : NSObject <NSCopying, NSCoding> {
196 @end @class NSTextField, NSPanel, NSArray, NSWindow, NSImage, NSButton, NSError;
200 @interface CIImage : NSObject <NSCoding, NSCopying> {
202 typedef int CIFormat;
204 kDAReturnSuccess = 0, kDAReturnError = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x01, kDAReturnBusy = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x02, kDAReturnBadArgument = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x03, kDAReturnExclusiveAccess = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x04, kDAReturnNoResources = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x05, kDAReturnNotFound = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x06, kDAReturnNotMounted = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x07, kDAReturnNotPermitted = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x08, kDAReturnNotPrivileged = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x09, kDAReturnNotReady = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0A, kDAReturnNotWritable = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0B, kDAReturnUnsupported = (((0x3eU)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0C };
205 typedef mach_error_t DAReturn;
206 typedef const struct __DADissenter * DADissenterRef;
207 extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string );
208 @interface CIContext: NSObject {
210 - (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r;
211 - (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs;
212 - (CGLayerRef)createCGLayerWithSize:(CGSize)size info:(CFDictionaryRef)d;
213 @end extern NSString* const QCRendererEventKey;
214 @protocol QCCompositionRenderer - (NSDictionary*) attributes;
215 @end @interface QCRenderer : NSObject <QCCompositionRenderer> {
217 - (id) createSnapshotImageOfType:(NSString*)type;
218 @end extern NSString* const QCViewDidStartRenderingNotification;
219 @interface QCView : NSView <QCCompositionRenderer> {
221 - (id) createSnapshotImageOfType:(NSString*)type;
223 ICEXIFOrientation1 = 1, ICEXIFOrientation2 = 2, ICEXIFOrientation3 = 3, ICEXIFOrientation4 = 4, ICEXIFOrientation5 = 5, ICEXIFOrientation6 = 6, ICEXIFOrientation7 = 7, ICEXIFOrientation8 = 8, };
225 @protocol ICDeviceDelegate <NSObject> @required - (void)didRemoveDevice:(ICDevice*)device;
226 @end extern NSString *const ICScannerStatusWarmingUp;
227 @class ICScannerDevice;
228 @protocol ICScannerDeviceDelegate <ICDeviceDelegate> @optional - (void)scannerDeviceDidBecomeAvailable:(ICScannerDevice*)scanner;
231 typedef long unsigned int __darwin_size_t;
232 typedef __darwin_size_t size_t;
233 typedef unsigned long CFTypeID;
238 typedef struct CGPoint CGPoint;
239 typedef struct CGGradient *CGGradientRef;
240 typedef uint32_t CGGradientDrawingOptions;
241 extern CFTypeID CGGradientGetTypeID(void);
242 extern CGGradientRef CGGradientCreateWithColorComponents(CGColorSpaceRef
243 space, const CGFloat components[], const CGFloat locations[], size_t count);
244 extern CGGradientRef CGGradientCreateWithColors(CGColorSpaceRef space,
245 CFArrayRef colors, const CGFloat locations[]);
246 extern CGGradientRef CGGradientRetain(CGGradientRef gradient);
247 extern void CGGradientRelease(CGGradientRef gradient);
248 typedef struct CGContext *CGContextRef;
249 extern void CGContextDrawLinearGradient(CGContextRef context,
250 CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,
251 CGGradientDrawingOptions options);
252 extern CGColorSpaceRef CGColorSpaceCreateDeviceRGB(void);
254 @interface NSMutableArray : NSObject
255 - (void)addObject:(id)object;
260 NSASCIIStringEncoding = 1,
261 NSNEXTSTEPStringEncoding = 2,
262 NSJapaneseEUCStringEncoding = 3,
263 NSUTF8StringEncoding = 4,
264 NSISOLatin1StringEncoding = 5,
265 NSSymbolStringEncoding = 6,
266 NSNonLossyASCIIStringEncoding = 7,
268 typedef struct __CFString * CFMutableStringRef;
269 typedef NSUInteger NSStringEncoding;
271 extern CFStringRef CFStringCreateWithCStringNoCopy(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding, CFAllocatorRef contentsDeallocator);
277 //===----------------------------------------------------------------------===//
279 //===----------------------------------------------------------------------===//
290 NSString *s = [[NSString alloc] init]; // expected-warning {{Potential leak}}
296 void test_neg(void) {
297 NSString *s = [[NSString alloc] init]; // no-warning
305 __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_cow(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap);
308 void callee_side_parameter_checking_leak(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) { // expected-warning {{Potential leak of an object}}
311 // As 'isl_basic_map_free' is annotated with 'rc_ownership_trusted_implementation', RetainCountChecker trusts its
312 // implementation and doesn't analyze its body. If the annotation 'rc_ownership_trusted_implementation' is removed,
313 // a leak warning is raised by RetainCountChecker as the analyzer is unable to detect a decrement in the reference
314 // count of 'bmap' along the path in 'isl_basic_map_free' assuming the predicate of the second 'if' branch to be
315 // true or assuming both the predicates in the function to be false.
316 __attribute__((annotate("rc_ownership_trusted_implementation"))) isl_basic_map *isl_basic_map_free(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
327 // As 'isl_basic_map_copy' is annotated with 'rc_ownership_trusted_implementation', RetainCountChecker trusts its
328 // implementation and doesn't analyze its body. If that annotation is removed, a 'use-after-release' warning might
329 // be raised by RetainCountChecker as the pointer which is passed as an argument to this function and the pointer
330 // which is returned from the function point to the same memory location.
331 __attribute__((annotate("rc_ownership_trusted_implementation"))) __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *isl_basic_map_copy(isl_basic_map *bmap) {
339 void test_use_after_release_with_trusted_implementation_annotate_attribute(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
340 // After this call, 'bmap' has a +1 reference count.
341 bmap = isl_basic_map_cow(bmap);
342 // After the call to 'isl_basic_map_copy', 'bmap' has a +1 reference count.
343 isl_basic_map *temp = isl_basic_map_cow(isl_basic_map_copy(bmap));
344 // After this call, 'bmap' has a +0 reference count.
345 isl_basic_map *temp2 = isl_basic_map_cow(bmap); // no-warning
346 isl_basic_map_free(temp2);
347 isl_basic_map_free(temp);
350 void test_leak_with_trusted_implementation_annotate_attribute(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap) {
351 // After this call, 'bmap' has a +1 reference count.
352 bmap = isl_basic_map_cow(bmap); // no-warning
353 // After this call, 'bmap' has a +0 reference count.
354 isl_basic_map_free(bmap);
357 void callee_side_parameter_checking_incorrect_rc_decrement(isl_basic_map *bmap) {
358 isl_basic_map_free(bmap); // expected-warning {{Incorrect decrement of the reference count}}
361 __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *callee_side_parameter_checking_return_notowned_object(isl_basic_map *bmap) {
362 return bmap; // expected-warning {{Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected}}
365 __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *callee_side_parameter_checking_assign_consumed_parameter_leak_return(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap1, __attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap2) { // expected-warning {{Potential leak of an object}}
367 isl_basic_map_free(bmap2);
371 __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *callee_side_parameter_checking_assign_consumed_parameter_leak(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap1, __attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap2) { // expected-warning {{Potential leak of an object}}
373 isl_basic_map_free(bmap1);
377 __attribute__((annotate("rc_ownership_returns_retained"))) isl_basic_map *error_path_leak(__attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap1, __attribute__((annotate("rc_ownership_consumed"))) isl_basic_map *bmap2) { // expected-warning {{Potential leak of an object}}
378 bmap1 = isl_basic_map_cow(bmap1);
379 if (!bmap1 || !bmap2)
382 isl_basic_map_free(bmap2);
385 return isl_basic_map_free(bmap1);
388 //===----------------------------------------------------------------------===//
389 // Test returning retained and not-retained values.
390 //===----------------------------------------------------------------------===//
392 // On return (intraprocedural), assume CF objects are leaked.
393 CFStringRef test_return_ratained_CF(char *bytes) {
395 return CFStringCreateWithCStringNoCopy(0, bytes, NSNEXTSTEPStringEncoding, 0); // expected-warning {{leak}}
398 // On return (intraprocedural), assume NSObjects are not leaked.
399 id test_return_retained_NS(void) {
400 return [[NSString alloc] init]; // no-warning
403 void test_test_return_retained(void) {
404 id x = test_return_retained_NS(); // expected-warning {{leak}}
409 //===----------------------------------------------------------------------===//
410 // Test not applying "double effects" from inlining and RetainCountChecker summaries.
411 // If we inline a call, we should already see its retain/release semantics.
412 //===----------------------------------------------------------------------===//
414 __attribute__((cf_returns_retained)) CFStringRef test_return_inline(CFStringRef x) {
419 void test_test_return_inline(char *bytes) {
420 CFStringRef str = CFStringCreateWithCStringNoCopy(0, bytes, NSNEXTSTEPStringEncoding, 0);
421 // After this call, 'str' really has +2 reference count.
422 CFStringRef str2 = test_return_inline(str);
423 // After this call, 'str' really has a +1 reference count.
425 // After this call, 'str2' and 'str' has a +0 reference count.
429 void test_test_return_inline_2(char *bytes) {
430 CFStringRef str = CFStringCreateWithCStringNoCopy(0, bytes, NSNEXTSTEPStringEncoding, 0); // expected-warning {{leak}}
431 // After this call, 'str' really has +2 reference count.
432 CFStringRef str2 = test_return_inline(str);
433 // After this call, 'str' really has a +1 reference count.
437 extern CFStringRef getString(void);
438 CFStringRef testCovariantReturnType(void) __attribute__((cf_returns_retained));
440 void usetestCovariantReturnType(void) {
441 CFStringRef S = ((void*)0);
442 S = testCovariantReturnType();
447 CFStringRef testCovariantReturnType(void) {
448 CFStringRef Str = ((void*)0);
456 // Test that we reanalyze ObjC methods which have been inlined. When reanalyzing
457 // them, make sure we inline very small functions.
458 id returnInputParam(id x) {
462 @interface MyClass : NSObject
463 - (id)test_reanalyze_as_top_level;
464 - (void)test_inline_tiny_when_reanalyzing;
465 - (void)inline_test_reanalyze_as_top_level;
468 @implementation MyClass
469 - (void)test_inline_tiny_when_reanalyzing {
470 id x = [[NSString alloc] init]; // no-warning
471 x = returnInputParam(x);
475 - (id)test_reanalyze_as_top_level {
476 // This method does not follow naming conventions, so a warning will be
477 // reported when it is reanalyzed at top level.
478 return [[NSString alloc] init]; // expected-warning {{leak}}
481 - (void)inline_test_reanalyze_as_top_level {
482 id x = [self test_reanalyze_as_top_level];
484 [self test_inline_tiny_when_reanalyzing];
488 // Original problem: rdar://problem/50739539
489 @interface MyClassThatLeaksDuringInit : NSObject
491 + (MyClassThatLeaksDuringInit *)getAnInstance1;
492 + (MyClassThatLeaksDuringInit *)getAnInstance2;
496 @implementation MyClassThatLeaksDuringInit
498 + (MyClassThatLeaksDuringInit *)getAnInstance1 {
499 return [[[MyClassThatLeaksDuringInit alloc] init] autorelease]; // expected-warning{{leak}}
502 + (MyClassThatLeaksDuringInit *)getAnInstance2 {
503 return [[[[self class] alloc] init] autorelease]; // expected-warning{{leak}}
506 - (instancetype)init {
511 if (nil != (self = [super init])) {