retain-release.m revision 689268a426cf4624c1b8ce67bf9d437ad84c6b04
1// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -analyzer-output=text -fblocks -Wno-objc-root-class %s > %t.objc 2>&1
2// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -analyze -analyzer-checker=core,osx.coreFoundation.CFRetainRelease,osx.cocoa.ClassRelease,osx.cocoa.RetainCount -analyzer-store=region -analyzer-output=text -fblocks -Wno-objc-root-class -x objective-c++ %s > %t.objcpp 2>&1
3// RUN: FileCheck -exact-match -input-file=%t.objc %s
4// RUN: FileCheck -exact-match -input-file=%t.objcpp %s
5
6#if __has_feature(attribute_ns_returns_retained)
7#define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
8#endif
9#if __has_feature(attribute_cf_returns_retained)
10#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
11#endif
12#if __has_feature(attribute_ns_returns_not_retained)
13#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
14#endif
15#if __has_feature(attribute_cf_returns_not_retained)
16#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
17#endif
18#if __has_feature(attribute_ns_consumes_self)
19#define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
20#endif
21#if __has_feature(attribute_ns_consumed)
22#define NS_CONSUMED __attribute__((ns_consumed))
23#endif
24#if __has_feature(attribute_cf_consumed)
25#define CF_CONSUMED __attribute__((cf_consumed))
26#endif
27
28//===----------------------------------------------------------------------===//
29// The following code is reduced using delta-debugging from Mac OS X headers:
30//
31// #include <Cocoa/Cocoa.h>
32// #include <CoreFoundation/CoreFoundation.h>
33// #include <DiskArbitration/DiskArbitration.h>
34// #include <QuartzCore/QuartzCore.h>
35// #include <Quartz/Quartz.h>
36// #include <IOKit/IOKitLib.h>
37//
38// It includes the basic definitions for the test cases below.
39//===----------------------------------------------------------------------===//
40
41typedef unsigned int __darwin_natural_t;
42typedef unsigned long uintptr_t;
43typedef unsigned int uint32_t;
44typedef unsigned long long uint64_t;
45typedef unsigned int UInt32;
46typedef signed long CFIndex;
47typedef CFIndex CFByteOrder;
48typedef struct {
49    CFIndex location;
50    CFIndex length;
51} CFRange;
52static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) {
53    CFRange range;
54    range.location = loc;
55    range.length = len;
56    return range;
57}
58typedef const void * CFTypeRef;
59typedef const struct __CFString * CFStringRef;
60typedef const struct __CFAllocator * CFAllocatorRef;
61extern const CFAllocatorRef kCFAllocatorDefault;
62extern CFTypeRef CFRetain(CFTypeRef cf);
63extern void CFRelease(CFTypeRef cf);
64typedef struct {
65}
66CFArrayCallBacks;
67extern const CFArrayCallBacks kCFTypeArrayCallBacks;
68typedef const struct __CFArray * CFArrayRef;
69typedef struct __CFArray * CFMutableArrayRef;
70extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks);
71extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
72extern void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value);
73typedef struct {
74}
75CFDictionaryKeyCallBacks;
76extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;
77typedef struct {
78}
79CFDictionaryValueCallBacks;
80extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks;
81typedef const struct __CFDictionary * CFDictionaryRef;
82typedef struct __CFDictionary * CFMutableDictionaryRef;
83extern CFMutableDictionaryRef CFDictionaryCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
84typedef UInt32 CFStringEncoding;
85enum {
86kCFStringEncodingMacRoman = 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  };
87extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
88typedef double CFTimeInterval;
89typedef CFTimeInterval CFAbsoluteTime;
90extern CFAbsoluteTime CFAbsoluteTimeGetCurrent(void);
91typedef const struct __CFDate * CFDateRef;
92extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
93extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate);
94typedef __darwin_natural_t natural_t;
95typedef natural_t mach_port_name_t;
96typedef mach_port_name_t mach_port_t;
97typedef int kern_return_t;
98typedef kern_return_t mach_error_t;
99enum {
100kCFNumberSInt8Type = 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    };
101typedef CFIndex CFNumberType;
102typedef const struct __CFNumber * CFNumberRef;
103extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
104typedef const struct __CFAttributedString *CFAttributedStringRef;
105typedef struct __CFAttributedString *CFMutableAttributedStringRef;
106extern CFAttributedStringRef CFAttributedStringCreate(CFAllocatorRef alloc, CFStringRef str, CFDictionaryRef attributes) ;
107extern CFMutableAttributedStringRef CFAttributedStringCreateMutableCopy(CFAllocatorRef alloc, CFIndex maxLength, CFAttributedStringRef aStr) ;
108extern void CFAttributedStringSetAttribute(CFMutableAttributedStringRef aStr, CFRange range, CFStringRef attrName, CFTypeRef value) ;
109typedef signed char BOOL;
110typedef unsigned long NSUInteger;
111@class NSString, Protocol;
112extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
113typedef struct _NSZone NSZone;
114@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
115@protocol NSObject
116- (BOOL)isEqual:(id)object;
117- (id)retain;
118- (oneway void)release;
119- (id)autorelease;
120- (NSString *)description;
121- (id)init;
122@end
123@protocol NSCopying 
124- (id)copyWithZone:(NSZone *)zone;
125@end
126@protocol NSMutableCopying  - (id)mutableCopyWithZone:(NSZone *)zone;
127@end
128@protocol NSCoding  - (void)encodeWithCoder:(NSCoder *)aCoder;
129@end
130@interface NSObject <NSObject> {}
131+ (id)allocWithZone:(NSZone *)zone;
132+ (id)alloc;
133- (void)dealloc;
134@end
135@interface NSObject (NSCoderMethods)
136- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder;
137@end
138extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
139typedef struct {
140}
141NSFastEnumerationState;
142@protocol NSFastEnumeration 
143- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
144@end
145@class NSString, NSDictionary;
146@interface NSValue : NSObject <NSCopying, NSCoding>  - (void)getValue:(void *)value;
147@end
148@interface NSNumber : NSValue
149- (char)charValue;
150- (id)initWithInt:(int)value;
151+ (NSNumber *)numberWithInt:(int)value;
152@end
153@class NSString;
154@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
155- (NSUInteger)count;
156- (id)initWithObjects:(const id [])objects count:(NSUInteger)cnt;
157+ (id)arrayWithObject:(id)anObject;
158+ (id)arrayWithObjects:(const id [])objects count:(NSUInteger)cnt;
159+ (id)arrayWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
160- (id)initWithObjects:(id)firstObj, ... __attribute__((sentinel(0,1)));
161- (id)initWithArray:(NSArray *)array;
162@end  @interface NSArray (NSArrayCreation)  + (id)array;
163@end       @interface NSAutoreleasePool : NSObject {
164}
165- (void)drain;
166@end extern NSString * const NSBundleDidLoadNotification;
167typedef double NSTimeInterval;
168@interface NSDate : NSObject <NSCopying, NSCoding>  - (NSTimeInterval)timeIntervalSinceReferenceDate;
169@end            typedef unsigned short unichar;
170@interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding>
171- (NSUInteger)length;
172- (NSString *)stringByAppendingString:(NSString *)aString;
173- ( const char *)UTF8String;
174- (id)initWithUTF8String:(const char *)nullTerminatedCString;
175+ (id)stringWithUTF8String:(const char *)nullTerminatedCString;
176@end        @class NSString, NSURL, NSError;
177@interface NSData : NSObject <NSCopying, NSMutableCopying, NSCoding>  - (NSUInteger)length;
178+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length;
179+ (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b;
180@end   @class NSLocale, NSDate, NSCalendar, NSTimeZone, NSError, NSArray, NSMutableDictionary;
181@interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
182- (NSUInteger)count;
183+ (id)dictionaryWithObjects:(NSArray *)objects forKeys:(NSArray *)keys;
184+ (id)dictionaryWithObjects:(const id [])objects forKeys:(const id <NSCopying> [])keys count:(NSUInteger)cnt;
185@end
186@interface NSMutableDictionary : NSDictionary  - (void)removeObjectForKey:(id)aKey;
187- (void)setObject:(id)anObject forKey:(id)aKey;
188@end  @interface NSMutableDictionary (NSMutableDictionaryCreation)  + (id)dictionaryWithCapacity:(NSUInteger)numItems;
189@end  typedef double CGFloat;
190struct CGSize {
191};
192typedef struct CGSize CGSize;
193struct CGRect {
194};
195typedef struct CGRect CGRect;
196typedef mach_port_t io_object_t;
197typedef char io_name_t[128];
198typedef io_object_t io_iterator_t;
199typedef io_object_t io_service_t;
200typedef struct IONotificationPort * IONotificationPortRef;
201typedef void (*IOServiceMatchingCallback)(  void * refcon,  io_iterator_t iterator );
202io_service_t IOServiceGetMatchingService(  mach_port_t masterPort,  CFDictionaryRef matching );
203kern_return_t IOServiceGetMatchingServices(  mach_port_t masterPort,  CFDictionaryRef matching,  io_iterator_t * existing );
204kern_return_t IOServiceAddNotification(  mach_port_t masterPort,  const io_name_t notificationType,  CFDictionaryRef matching,  mach_port_t wakePort,  uintptr_t reference,  io_iterator_t * notification ) __attribute__((deprecated)); // expected-note {{'IOServiceAddNotification' declared here}}
205kern_return_t IOServiceAddMatchingNotification(  IONotificationPortRef notifyPort,  const io_name_t notificationType,  CFDictionaryRef matching,         IOServiceMatchingCallback callback,         void * refCon,  io_iterator_t * notification );
206CFMutableDictionaryRef IOServiceMatching(  const char * name );
207CFMutableDictionaryRef IOServiceNameMatching(  const char * name );
208CFMutableDictionaryRef IOBSDNameMatching(  mach_port_t masterPort,  uint32_t options,  const char * bsdName );
209CFMutableDictionaryRef IOOpenFirmwarePathMatching(  mach_port_t masterPort,  uint32_t options,  const char * path );
210CFMutableDictionaryRef IORegistryEntryIDMatching(  uint64_t entryID );
211typedef struct __DASession * DASessionRef;
212extern DASessionRef DASessionCreate( CFAllocatorRef allocator );
213typedef struct __DADisk * DADiskRef;
214extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name );
215extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media );
216extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk );
217extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk );
218@interface NSTask : NSObject - (id)init;
219@end                    typedef struct CGColorSpace *CGColorSpaceRef;
220typedef struct CGImage *CGImageRef;
221typedef struct CGLayer *CGLayerRef;
222@interface NSResponder : NSObject <NSCoding> {
223}
224@end    @protocol NSAnimatablePropertyContainer      - (id)animator;
225@end  extern NSString *NSAnimationTriggerOrderIn ;
226@interface NSView : NSResponder  <NSAnimatablePropertyContainer>  {
227}
228@end @protocol NSValidatedUserInterfaceItem - (SEL)action;
229@end   @protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem;
230@end  @class NSDate, NSDictionary, NSError, NSException, NSNotification;
231@class NSTextField, NSPanel, NSArray, NSWindow, NSImage, NSButton, NSError;
232@interface NSApplication : NSResponder <NSUserInterfaceValidations> {
233}
234- (void)beginSheet:(NSWindow *)sheet modalForWindow:(NSWindow *)docWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)didEndSelector contextInfo:(void *)contextInfo;
235@end   enum {
236NSTerminateCancel = 0,         NSTerminateNow = 1,         NSTerminateLater = 2 };
237typedef NSUInteger NSApplicationTerminateReply;
238@protocol NSApplicationDelegate <NSObject> @optional        - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
239@end  @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView, NSTextView;
240@interface NSCell : NSObject <NSCopying, NSCoding> {
241}
242@end 
243typedef struct {
244}
245CVTimeStamp;
246@interface CIImage : NSObject <NSCoding, NSCopying> {
247}
248typedef int CIFormat;
249@end  enum {
250kDAReturnSuccess = 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 };
251typedef mach_error_t DAReturn;
252typedef const struct __DADissenter * DADissenterRef;
253extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string );
254@interface CIContext: NSObject {
255}
256- (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r;
257- (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r     format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs;
258- (CGLayerRef)createCGLayerWithSize:(CGSize)size info:(CFDictionaryRef)d;
259@end extern NSString* const QCRendererEventKey;
260@protocol QCCompositionRenderer - (NSDictionary*) attributes;
261@end   @interface QCRenderer : NSObject <QCCompositionRenderer> {
262}
263- (id) createSnapshotImageOfType:(NSString*)type;
264@end  extern NSString* const QCViewDidStartRenderingNotification;
265@interface QCView : NSView <QCCompositionRenderer> {
266}
267- (id) createSnapshotImageOfType:(NSString*)type;
268@end    enum {
269ICEXIFOrientation1 = 1,     ICEXIFOrientation2 = 2,     ICEXIFOrientation3 = 3,     ICEXIFOrientation4 = 4,     ICEXIFOrientation5 = 5,     ICEXIFOrientation6 = 6,     ICEXIFOrientation7 = 7,     ICEXIFOrientation8 = 8, };
270@class ICDevice;
271@protocol ICDeviceDelegate <NSObject>  @required      - (void)didRemoveDevice:(ICDevice*)device;
272@end extern NSString *const ICScannerStatusWarmingUp;
273@class ICScannerDevice;
274@protocol ICScannerDeviceDelegate <ICDeviceDelegate>  @optional       - (void)scannerDeviceDidBecomeAvailable:(ICScannerDevice*)scanner;
275@end
276
277typedef long unsigned int __darwin_size_t;
278typedef __darwin_size_t size_t;
279typedef unsigned long CFTypeID;
280struct CGPoint {
281  CGFloat x;
282  CGFloat y;
283};
284typedef struct CGPoint CGPoint;
285typedef struct CGGradient *CGGradientRef;
286typedef uint32_t CGGradientDrawingOptions;
287extern CFTypeID CGGradientGetTypeID(void);
288extern CGGradientRef CGGradientCreateWithColorComponents(CGColorSpaceRef
289  space, const CGFloat components[], const CGFloat locations[], size_t count);
290extern CGGradientRef CGGradientCreateWithColors(CGColorSpaceRef space,
291  CFArrayRef colors, const CGFloat locations[]);
292extern CGGradientRef CGGradientRetain(CGGradientRef gradient);
293extern void CGGradientRelease(CGGradientRef gradient);
294typedef struct CGContext *CGContextRef;
295extern void CGContextDrawLinearGradient(CGContextRef context,
296    CGGradientRef gradient, CGPoint startPoint, CGPoint endPoint,
297    CGGradientDrawingOptions options);
298extern CGColorSpaceRef CGColorSpaceCreateDeviceRGB(void);
299
300@interface NSMutableArray : NSObject
301- (void)addObject:(id)object;
302+ (id)array;
303@end
304
305// This is how NSMakeCollectable is declared in the OS X 10.8 headers.
306id NSMakeCollectable(CFTypeRef __attribute__((cf_consumed))) __attribute__((ns_returns_retained));
307
308typedef const struct __CFUUID * CFUUIDRef;
309
310extern
311void *CFPlugInInstanceCreate(CFAllocatorRef allocator, CFUUIDRef factoryUUID, CFUUIDRef typeUUID);
312
313//===----------------------------------------------------------------------===//
314// Test cases.
315//===----------------------------------------------------------------------===//
316
317CFAbsoluteTime f1() {
318  CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
319  CFDateRef date = CFDateCreate(0, t);
320  CFRetain(date);
321  CFRelease(date);
322  CFDateGetAbsoluteTime(date);
323  CFRelease(date);
324  t = CFDateGetAbsoluteTime(date);
325  return t;
326}
327
328CFAbsoluteTime f2() {
329  CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
330  CFDateRef date = CFDateCreate(0, t);  
331  [((NSDate*) date) retain];
332  CFRelease(date);
333  CFDateGetAbsoluteTime(date);
334  [((NSDate*) date) release];
335  t = CFDateGetAbsoluteTime(date);
336  return t;
337}
338
339
340NSDate* global_x;
341
342// Test to see if we supresss an error when we store the pointer
343// to a global.
344
345CFAbsoluteTime f3() {
346  CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
347  CFDateRef date = CFDateCreate(0, t);  
348  [((NSDate*) date) retain];
349  CFRelease(date);
350  CFDateGetAbsoluteTime(date);
351  global_x = (NSDate*) date;  
352  [((NSDate*) date) release];
353  t = CFDateGetAbsoluteTime(date);
354  return t;
355}
356
357//---------------------------------------------------------------------------
358// Test case 'f4' differs for region store and basic store.  See
359// retain-release-region-store.m and retain-release-basic-store.m.
360//---------------------------------------------------------------------------
361
362// Test a leak.
363
364CFAbsoluteTime f5(int x) {  
365  CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
366  CFDateRef date = CFDateCreate(0, t);
367  
368  if (x)
369    CFRelease(date);
370  
371  return t;
372}
373
374// Test a leak involving the return.
375
376CFDateRef f6(int x) {  
377  CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
378  CFRetain(date);
379  return date;
380}
381
382// Test a leak involving an overwrite.
383
384CFDateRef f7() {
385  CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());  //expected-warning{{leak}}
386  CFRetain(date);
387  date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
388  return date;
389}
390
391// Generalization of Create rule.  MyDateCreate returns a CFXXXTypeRef, and
392// has the word create.
393CFDateRef MyDateCreate();
394
395CFDateRef f8() {
396  CFDateRef date = MyDateCreate();
397  CFRetain(date);  
398  return date;
399}
400
401__attribute__((cf_returns_retained)) CFDateRef f9() {
402  CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
403  int *p = 0;
404  // When allocations fail, CFDateCreate can return null.
405  if (!date) *p = 1;
406  return date;
407}
408
409// Handle DiskArbitration API:
410//
411// http://developer.apple.com/DOCUMENTATION/DARWIN/Reference/DiscArbitrationFramework/
412//
413void f10(io_service_t media, DADiskRef d, CFStringRef s) {
414  DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, 0, "hello");
415  if (disk) NSLog(@"ok");
416  
417  disk = DADiskCreateFromIOMedia(kCFAllocatorDefault, 0, media);
418  if (disk) NSLog(@"ok");
419
420  CFDictionaryRef dict = DADiskCopyDescription(d);
421  if (dict) NSLog(@"ok"); 
422  
423  disk = DADiskCopyWholeDisk(d);
424  if (disk) NSLog(@"ok");
425    
426  DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault,
427                                                kDAReturnSuccess, s);
428  if (dissenter) NSLog(@"ok");
429  
430  DASessionRef session = DASessionCreate(kCFAllocatorDefault);
431  if (session) NSLog(@"ok");
432}
433
434// Test retain/release checker with CFString and CFMutableArray.
435void f11() {
436  // Create the array.
437  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
438
439  // Create a string.
440  CFStringRef s1 = CFStringCreateWithCString(0, "hello world",
441                                             kCFStringEncodingUTF8);
442
443  // Add the string to the array.
444  CFArrayAppendValue(A, s1);
445  
446  // Decrement the reference count.
447  CFRelease(s1);
448  
449  // Get the string.  We don't own it.
450  s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0);
451  
452  // Release the array.
453  CFRelease(A);
454  
455  // Release the string.  This is a bug.
456  CFRelease(s1);
457}
458
459// PR 3337: Handle functions declared using typedefs.
460typedef CFTypeRef CREATEFUN();
461CREATEFUN MyCreateFun;
462
463void f12() {
464  CFTypeRef o = MyCreateFun();
465}
466
467void f13_autorelease() {
468  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
469  [(id) A autorelease];
470}
471
472void f13_autorelease_b() {
473  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
474  [(id) A autorelease];
475  [(id) A autorelease];
476}
477
478CFMutableArrayRef f13_autorelease_c() {
479  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
480  [(id) A autorelease];
481  [(id) A autorelease]; 
482  return A;
483}
484
485CFMutableArrayRef f13_autorelease_d() {
486  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
487  [(id) A autorelease];
488  [(id) A autorelease]; 
489  CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
490  CFRelease(B);
491  while (1) {}
492}
493
494
495// This case exercises the logic where the leak site is the same as the allocation site.
496void f14_leakimmediately() {
497  CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
498}
499
500// Test that we track an allocated object beyond the point where the *name*
501// of the variable storing the reference is no longer live.
502void f15() {
503  // Create the array.
504  CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
505  CFMutableArrayRef *B = &A;
506  // At this point, the name 'A' is no longer live.
507  CFRelease(*B);
508}
509
510// Test when we pass NULL to CFRetain/CFRelease.
511void f16(int x, CFTypeRef p) {
512  if (p)
513    return;
514
515  if (x) {
516    CFRelease(p);
517  }
518  else {
519    CFRetain(p);
520  }
521}
522
523// Test that an object is non-null after being CFRetained/CFReleased.
524void f17(int x, CFTypeRef p) {
525  if (x) {
526    CFRelease(p);
527    if (!p)
528      CFRelease(0);
529  }
530  else {
531    CFRetain(p);
532    if (!p)
533      CFRetain(0);
534  }
535}
536
537// Test basic tracking of ivars associated with 'self'.  For the retain/release
538// checker we currently do not want to flag leaks associated with stores
539// of tracked objects to ivars.
540@interface SelfIvarTest : NSObject {
541  id myObj;
542}
543- (void)test_self_tracking;
544@end
545
546@implementation SelfIvarTest
547- (void)test_self_tracking {
548  myObj = (id) CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
549}
550@end
551
552// Test return of non-owned objects in contexts where an owned object
553// is expected.
554@interface TestReturnNotOwnedWhenExpectedOwned
555- (NSString*)newString;
556@end
557
558@implementation TestReturnNotOwnedWhenExpectedOwned
559- (NSString*)newString {
560  NSString *s = [NSString stringWithUTF8String:"hello"];
561  return s;
562}
563@end
564
565// <rdar://problem/6659160>
566int isFoo(char c);
567
568static void rdar_6659160(char *inkind, char *inname)
569{
570  // We currently expect that [NSObject alloc] cannot fail.  This
571  // will be a toggled flag in the future.  It can indeed return null, but
572  // Cocoa programmers generally aren't expected to reason about out-of-memory
573  // conditions.
574  NSString *kind = [[NSString alloc] initWithUTF8String:inkind];
575  
576  // We do allow stringWithUTF8String to fail.  This isn't really correct, as
577  // far as returning 0.  In most error conditions it will throw an exception.
578  // If allocation fails it could return 0, but again this
579  // isn't expected.
580  NSString *name = [NSString stringWithUTF8String:inname];
581  if(!name)
582    return;
583
584  const char *kindC = 0;
585  const char *nameC = 0;
586  
587  // In both cases, we cannot reach a point down below where we
588  // dereference kindC or nameC with either being null.  This is because
589  // we assume that [NSObject alloc] doesn't fail and that we have the guard
590  // up above.
591  
592  if(kind)
593    kindC = [kind UTF8String];
594  if(name)
595    nameC = [name UTF8String];
596  if(!isFoo(kindC[0]))
597    return;
598  if(!isFoo(nameC[0]))
599    return;
600
601  [kind release];
602  [name release];
603}
604
605// PR 3677 - 'allocWithZone' should be treated as following the Cocoa naming
606//  conventions with respect to 'return'ing ownership.
607@interface PR3677: NSObject @end
608@implementation PR3677
609+ (id)allocWithZone:(NSZone *)inZone {
610  return [super allocWithZone:inZone];
611}
612@end
613
614// PR 3820 - Reason about calls to -dealloc
615void pr3820_DeallocInsteadOfRelease(void)
616{
617  id foo = [[NSString alloc] init];
618  [foo dealloc];
619  // foo is not leaked, since it has been deallocated.
620}
621
622void pr3820_ReleaseAfterDealloc(void)
623{
624  id foo = [[NSString alloc] init];
625  [foo dealloc];
626  [foo release];
627  // NSInternalInconsistencyException: message sent to deallocated object
628}
629
630void pr3820_DeallocAfterRelease(void)
631{
632  NSLog(@"\n\n[%s]", __FUNCTION__);
633  id foo = [[NSString alloc] init];
634  [foo release];
635  [foo dealloc];
636  // message sent to released object
637}
638
639// From <rdar://problem/6704930>.  The problem here is that 'length' binds to
640// '($0 - 1)' after '--length', but SimpleConstraintManager doesn't know how to
641// reason about '($0 - 1) > constant'.  As a temporary hack, we drop the value
642// of '($0 - 1)' and conjure a new symbol.
643void rdar6704930(unsigned char *s, unsigned int length) {
644  NSString* name = 0;
645  if (s != 0) {
646    if (length > 0) {
647      while (length > 0) {
648        if (*s == ':') {
649          ++s;
650          --length;
651          name = [[NSString alloc] init];
652          break;
653        }
654        ++s;
655        --length;
656      }
657      if ((length == 0) && (name != 0)) {
658        [name release];
659        name = 0;
660      }
661      if (length == 0) { // no ':' found -> use it all as name
662        name = [[NSString alloc] init];
663      }
664    }
665  }
666
667  if (name != 0) {
668    [name release];
669  }
670}
671
672//===----------------------------------------------------------------------===//
673// <rdar://problem/6833332>
674// One build of the analyzer accidentally stopped tracking the allocated
675// object after the 'retain'.
676//===----------------------------------------------------------------------===//
677
678@interface rdar_6833332 : NSObject <NSApplicationDelegate> {
679    NSWindow *window;
680}
681@property (nonatomic, retain) NSWindow *window;
682@end
683
684@implementation rdar_6833332
685@synthesize window;
686- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
687 NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
688
689 [dict setObject:@"foo" forKey:@"bar"];
690
691 NSLog(@"%@", dict);
692}
693- (void)dealloc {
694    [window release];
695    [super dealloc];
696}
697
698- (void)radar10102244 {
699 NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
700 if (window) 
701   NSLog(@"%@", window);    
702}
703@end
704
705//===----------------------------------------------------------------------===//
706// <rdar://problem/6257780> clang checker fails to catch use-after-release
707//===----------------------------------------------------------------------===//
708
709int rdar_6257780_Case1() {
710  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
711  NSArray *array = [NSArray array];
712  [array release];
713  [pool drain];
714  return 0;
715}
716
717//===----------------------------------------------------------------------===//
718// <rdar://problem/10640253> Analyzer is confused about NSAutoreleasePool -allocWithZone:.
719//===----------------------------------------------------------------------===//
720
721void rdar_10640253_autorelease_allocWithZone() {
722    NSAutoreleasePool *pool = [[NSAutoreleasePool allocWithZone:(NSZone*)0] init];
723    (void) pool;
724}
725
726//===----------------------------------------------------------------------===//
727// <rdar://problem/6866843> Checker should understand new/setObject:/release constructs
728//===----------------------------------------------------------------------===//
729
730void rdar_6866843() {
731 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
732 NSMutableDictionary* dictionary = [[NSMutableDictionary alloc] init];
733 NSArray* array = [[NSArray alloc] init];
734 [dictionary setObject:array forKey:@"key"];
735 [array release];
736 // Using 'array' here should be fine
737 NSLog(@"array = %@\n", array);
738 // Now the array is released
739 [dictionary release];
740 [pool drain];
741}
742
743
744//===----------------------------------------------------------------------===//
745// <rdar://problem/6877235> Classes typedef-ed to CF objects should get the same treatment as CF objects
746//===----------------------------------------------------------------------===//
747
748typedef CFTypeRef OtherRef;
749
750@interface RDar6877235 : NSObject {}
751- (CFTypeRef)_copyCFTypeRef;
752- (OtherRef)_copyOtherRef;
753@end
754
755@implementation RDar6877235
756- (CFTypeRef)_copyCFTypeRef {
757  return [[NSString alloc] init];
758}
759- (OtherRef)_copyOtherRef {
760  return [[NSString alloc] init];
761}
762@end
763
764//===----------------------------------------------------------------------===//
765// <rdar://problem/6320065> false positive - init method returns an object
766// owned by caller
767//===----------------------------------------------------------------------===//
768
769@interface RDar6320065 : NSObject {
770  NSString *_foo;
771}
772- (id)initReturningNewClass;
773- (id)_initReturningNewClassBad;
774- (id)initReturningNewClassBad2;
775@end
776
777@interface RDar6320065Subclass : RDar6320065
778@end
779
780@implementation RDar6320065
781- (id)initReturningNewClass {
782  [self release];
783  self = [[RDar6320065Subclass alloc] init];
784  return self;
785}
786- (id)_initReturningNewClassBad {
787  [self release];
788  [[RDar6320065Subclass alloc] init];
789  return self;
790}
791- (id)initReturningNewClassBad2 {
792  [self release];
793  self = [[RDar6320065Subclass alloc] init];
794  return [self autorelease];
795}
796
797@end
798
799@implementation RDar6320065Subclass
800@end
801
802int RDar6320065_test() {
803  RDar6320065 *test = [[RDar6320065 alloc] init];
804  [test release];
805  return 0;
806}
807
808//===----------------------------------------------------------------------===//
809// <rdar://problem/7129086> -awakeAfterUsingCoder: returns an owned object 
810//  and claims the receiver
811//===----------------------------------------------------------------------===//
812
813@interface RDar7129086 : NSObject {} @end
814@implementation RDar7129086
815- (id)awakeAfterUsingCoder:(NSCoder *)aDecoder {
816  [self release];
817  return [NSString alloc];
818}
819@end
820
821//===----------------------------------------------------------------------===//
822// <rdar://problem/6859457> [NSData dataWithBytesNoCopy] does not return a
823//  retained object
824//===----------------------------------------------------------------------===//
825
826@interface RDar6859457 : NSObject {}
827- (NSString*) NoCopyString;
828- (NSString*) noCopyString;
829@end
830
831@implementation RDar6859457 
832- (NSString*) NoCopyString { return [[NSString alloc] init]; }
833- (NSString*) noCopyString { return [[NSString alloc] init]; }
834@end
835
836void test_RDar6859457(RDar6859457 *x, void *bytes, NSUInteger dataLength) {
837  [x NoCopyString];
838  [x noCopyString];
839  [NSData dataWithBytesNoCopy:bytes length:dataLength];
840  [NSData dataWithBytesNoCopy:bytes length:dataLength freeWhenDone:1];
841}
842
843//===----------------------------------------------------------------------===//
844// PR 4230 - an autorelease pool is not necessarily leaked during a premature
845//  return
846//===----------------------------------------------------------------------===//
847
848static void PR4230(void)
849{
850  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
851  NSString *object = [[[NSString alloc] init] autorelease];
852  return;
853}
854
855//===----------------------------------------------------------------------===//
856// Method name that has a null IdentifierInfo* for its first selector slot.
857// This test just makes sure that we handle it.
858//===----------------------------------------------------------------------===//
859
860@interface TestNullIdentifier
861@end
862
863@implementation TestNullIdentifier
864+ (id):(int)x, ... {
865  return [[NSString alloc] init];
866}
867@end
868
869//===----------------------------------------------------------------------===//
870// <rdar://problem/6893565> don't flag leaks for return types that cannot be 
871//                          determined to be CF types
872//===----------------------------------------------------------------------===//
873
874// We don't know if 'struct s6893565' represents a Core Foundation type, so
875// we shouldn't emit an error here.
876typedef struct s6893565* TD6893565;
877
878@interface RDar6893565 {}
879-(TD6893565)newThing;
880@end
881
882@implementation RDar6893565
883-(TD6893565)newThing {  
884  return (TD6893565) [[NSString alloc] init];
885}
886@end
887
888//===----------------------------------------------------------------------===//
889// <rdar://problem/6902710> clang: false positives w/QC and CoreImage methods
890//===----------------------------------------------------------------------===//
891
892void rdar6902710(QCView *view, QCRenderer *renderer, CIContext *context,
893                 NSString *str, CIImage *img, CGRect rect,
894                 CIFormat form, CGColorSpaceRef cs) {
895  [view createSnapshotImageOfType:str];
896  [renderer createSnapshotImageOfType:str];
897  [context createCGImage:img fromRect:rect];
898  [context createCGImage:img fromRect:rect format:form colorSpace:cs];
899}
900
901//===----------------------------------------------------------------------===//
902// <rdar://problem/6945561> -[CIContext createCGLayerWithSize:info:]
903//                           misinterpreted by clang scan-build
904//===----------------------------------------------------------------------===//
905
906void rdar6945561(CIContext *context, CGSize size, CFDictionaryRef d) {
907  [context createCGLayerWithSize:size info:d];
908}
909
910//===----------------------------------------------------------------------===//
911// <rdar://problem/6961230> add knowledge of IOKit functions to retain/release 
912//                          checker
913//===----------------------------------------------------------------------===//
914
915void IOBSDNameMatching_wrapper(mach_port_t masterPort, uint32_t options,  const char * bsdName) {  
916  IOBSDNameMatching(masterPort, options, bsdName);
917}
918
919void IOServiceMatching_wrapper(const char * name) {
920  IOServiceMatching(name);
921}
922
923void IOServiceNameMatching_wrapper(const char * name) {
924  IOServiceNameMatching(name);
925}
926
927CF_RETURNS_RETAINED CFDictionaryRef CreateDict();
928
929void IOServiceAddNotification_wrapper(mach_port_t masterPort, const io_name_t notificationType,
930  mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) {
931
932  CFDictionaryRef matching = CreateDict();
933  CFRelease(matching);
934  IOServiceAddNotification(masterPort, notificationType, matching,
935                           wakePort, reference, notification);
936}
937
938void IORegistryEntryIDMatching_wrapper(uint64_t entryID ) {
939  IORegistryEntryIDMatching(entryID);
940}
941
942void IOOpenFirmwarePathMatching_wrapper(mach_port_t masterPort, uint32_t options,
943                                        const char * path) {
944  IOOpenFirmwarePathMatching(masterPort, options, path);
945}
946
947void IOServiceGetMatchingService_wrapper(mach_port_t masterPort) {
948  CFDictionaryRef matching = CreateDict();
949  IOServiceGetMatchingService(masterPort, matching);
950  CFRelease(matching);
951}
952
953void IOServiceGetMatchingServices_wrapper(mach_port_t masterPort, io_iterator_t *existing) {
954  CFDictionaryRef matching = CreateDict();
955  IOServiceGetMatchingServices(masterPort, matching, existing);
956  CFRelease(matching);
957}
958
959void IOServiceAddMatchingNotification_wrapper(IONotificationPortRef notifyPort, const io_name_t notificationType, 
960  IOServiceMatchingCallback callback, void * refCon, io_iterator_t * notification) {
961    
962  CFDictionaryRef matching = CreateDict();
963  IOServiceAddMatchingNotification(notifyPort, notificationType, matching, callback, refCon, notification);
964  CFRelease(matching);
965}
966
967//===----------------------------------------------------------------------===//
968// Test of handling objects whose references "escape" to containers.
969//===----------------------------------------------------------------------===//
970
971void CFDictionaryAddValue(CFMutableDictionaryRef, void *, void *);
972
973// <rdar://problem/6539791>
974void rdar_6539791(CFMutableDictionaryRef y, void* key, void* val_key) {
975  CFMutableDictionaryRef x = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
976  CFDictionaryAddValue(y, key, x);
977  CFRelease(x); // the dictionary keeps a reference, so the object isn't deallocated yet
978  signed z = 1;
979  CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
980  if (value) {
981    CFDictionaryAddValue(x, val_key, (void*)value);
982    CFRelease(value);
983    CFDictionaryAddValue(y, val_key, (void*)value);
984  }
985}
986
987// <rdar://problem/6560661>
988// Same issue, except with "AppendValue" functions.
989void rdar_6560661(CFMutableArrayRef x) {
990  signed z = 1;
991  CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
992  // CFArrayAppendValue keeps a reference to value.
993  CFArrayAppendValue(x, value);
994  CFRelease(value);
995  CFRetain(value);
996  CFRelease(value);
997}
998
999// <rdar://problem/7152619>
1000// Same issue, excwept with "CFAttributeStringSetAttribute".
1001void rdar_7152619(CFStringRef str) {
1002  CFAttributedStringRef string = CFAttributedStringCreate(kCFAllocatorDefault, str, 0);
1003  CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutableCopy(kCFAllocatorDefault, 100, string);
1004  CFRelease(string);
1005  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1006  CFAttributedStringSetAttribute(attrString, CFRangeMake(0, 1), str, number);
1007  [number release];
1008  [number retain];
1009  CFRelease(attrString);  
1010}
1011
1012//===----------------------------------------------------------------------===//
1013// Test of handling CGGradientXXX functions.
1014//===----------------------------------------------------------------------===//
1015
1016void rdar_7184450(CGContextRef myContext, CGFloat x, CGPoint myStartPoint,
1017                  CGPoint myEndPoint) {
1018  size_t num_locations = 6;
1019  CGFloat locations[6] = { 0.0, 0.265, 0.28, 0.31, 0.36, 1.0 };
1020  CGFloat components[28] = { 239.0/256.0, 167.0/256.0, 170.0/256.0,
1021     x,  // Start color
1022    207.0/255.0, 39.0/255.0, 39.0/255.0, x,
1023    147.0/255.0, 21.0/255.0, 22.0/255.0, x,
1024    175.0/255.0, 175.0/255.0, 175.0/255.0, x,
1025    255.0/255.0,255.0/255.0, 255.0/255.0, x,
1026    255.0/255.0,255.0/255.0, 255.0/255.0, x
1027  }; // End color
1028  
1029  CGGradientRef myGradient =
1030    CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),
1031      components, locations, num_locations);
1032
1033  CGContextDrawLinearGradient(myContext, myGradient, myStartPoint, myEndPoint,
1034                              0);
1035  CGGradientRelease(myGradient);
1036}
1037
1038void rdar_7184450_pos(CGContextRef myContext, CGFloat x, CGPoint myStartPoint,
1039                  CGPoint myEndPoint) {
1040  size_t num_locations = 6;
1041  CGFloat locations[6] = { 0.0, 0.265, 0.28, 0.31, 0.36, 1.0 };
1042  CGFloat components[28] = { 239.0/256.0, 167.0/256.0, 170.0/256.0,
1043     x,  // Start color
1044    207.0/255.0, 39.0/255.0, 39.0/255.0, x,
1045    147.0/255.0, 21.0/255.0, 22.0/255.0, x,
1046    175.0/255.0, 175.0/255.0, 175.0/255.0, x,
1047    255.0/255.0,255.0/255.0, 255.0/255.0, x,
1048    255.0/255.0,255.0/255.0, 255.0/255.0, x
1049  }; // End color
1050  
1051  CGGradientRef myGradient =
1052   CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations);
1053
1054  CGContextDrawLinearGradient(myContext, myGradient, myStartPoint, myEndPoint,
1055                              0);
1056}
1057
1058//===----------------------------------------------------------------------===//
1059// <rdar://problem/7299394> clang false positive: retained instance passed to
1060//                          thread in pthread_create marked as leak
1061//
1062// Until we have full IPA, the analyzer should stop tracking the reference
1063// count of objects passed to pthread_create.
1064//
1065//===----------------------------------------------------------------------===//
1066
1067struct _opaque_pthread_t {};
1068struct _opaque_pthread_attr_t {};
1069typedef struct _opaque_pthread_t *__darwin_pthread_t;
1070typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t;
1071typedef __darwin_pthread_t pthread_t;
1072typedef __darwin_pthread_attr_t pthread_attr_t;
1073typedef unsigned long __darwin_pthread_key_t;
1074typedef __darwin_pthread_key_t pthread_key_t;
1075
1076int pthread_create(pthread_t *, const pthread_attr_t *,
1077                   void *(*)(void *), void *);
1078
1079int pthread_setspecific(pthread_key_t key, const void *value);
1080
1081void *rdar_7299394_start_routine(void *p) {
1082  [((id) p) release];
1083  return 0;
1084}
1085void rdar_7299394(pthread_attr_t *attr, pthread_t *thread, void *args) {
1086  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1087  pthread_create(thread, attr, rdar_7299394_start_routine, number);
1088}
1089void rdar_7299394_positive(pthread_attr_t *attr, pthread_t *thread) {
1090  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1091}
1092
1093//===----------------------------------------------------------------------===//
1094// <rdar://problem/11282706> false positive with not understanding thread
1095// local storage
1096//===----------------------------------------------------------------------===//
1097
1098void rdar11282706(pthread_key_t key) {
1099  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1100  pthread_setspecific(key, (void*) number);
1101}
1102
1103//===----------------------------------------------------------------------===//
1104// <rdar://problem/7283567> False leak associated with call to 
1105//                          CVPixelBufferCreateWithBytes ()
1106//
1107// According to the Core Video Reference (ADC), CVPixelBufferCreateWithBytes and
1108// CVPixelBufferCreateWithPlanarBytes can release (via a callback) the
1109// pixel buffer object.  These test cases show how the analyzer stops tracking
1110// the reference count for the objects passed for this argument.  This
1111// could be made smarter.
1112//===----------------------------------------------------------------------===//
1113
1114typedef int int32_t;
1115typedef UInt32 FourCharCode;
1116typedef FourCharCode OSType;
1117typedef uint64_t CVOptionFlags;
1118typedef int32_t CVReturn;
1119typedef struct __CVBuffer *CVBufferRef;
1120typedef CVBufferRef CVImageBufferRef;
1121typedef CVImageBufferRef CVPixelBufferRef;
1122typedef void (*CVPixelBufferReleaseBytesCallback)( void *releaseRefCon, const void *baseAddress );
1123
1124extern CVReturn CVPixelBufferCreateWithBytes(CFAllocatorRef allocator,
1125            size_t width,
1126            size_t height,
1127            OSType pixelFormatType,
1128            void *baseAddress,
1129            size_t bytesPerRow,
1130            CVPixelBufferReleaseBytesCallback releaseCallback,
1131            void *releaseRefCon,
1132            CFDictionaryRef pixelBufferAttributes,
1133                   CVPixelBufferRef *pixelBufferOut) ;
1134
1135typedef void (*CVPixelBufferReleasePlanarBytesCallback)( void *releaseRefCon, const void *dataPtr, size_t dataSize, size_t numberOfPlanes, const void *planeAddresses[] );
1136
1137extern CVReturn CVPixelBufferCreateWithPlanarBytes(CFAllocatorRef allocator,
1138        size_t width,
1139        size_t height,
1140        OSType pixelFormatType,
1141        void *dataPtr,
1142        size_t dataSize,
1143        size_t numberOfPlanes,
1144        void *planeBaseAddress[],
1145        size_t planeWidth[],
1146        size_t planeHeight[],
1147        size_t planeBytesPerRow[],
1148        CVPixelBufferReleasePlanarBytesCallback releaseCallback,
1149        void *releaseRefCon,
1150        CFDictionaryRef pixelBufferAttributes,
1151        CVPixelBufferRef *pixelBufferOut) ;
1152
1153extern CVReturn CVPixelBufferCreateWithBytes(CFAllocatorRef allocator,
1154            size_t width,
1155            size_t height,
1156            OSType pixelFormatType,
1157            void *baseAddress,
1158            size_t bytesPerRow,
1159            CVPixelBufferReleaseBytesCallback releaseCallback,
1160            void *releaseRefCon,
1161            CFDictionaryRef pixelBufferAttributes,
1162                   CVPixelBufferRef *pixelBufferOut) ;
1163
1164CVReturn rdar_7283567(CFAllocatorRef allocator, size_t width, size_t height,
1165                      OSType pixelFormatType, void *baseAddress,
1166                      size_t bytesPerRow,
1167                      CVPixelBufferReleaseBytesCallback releaseCallback,
1168                      CFDictionaryRef pixelBufferAttributes,
1169                      CVPixelBufferRef *pixelBufferOut) {
1170
1171  // For the allocated object, it doesn't really matter what type it is
1172  // for the purpose of this test.  All we want to show is that
1173  // this is freed later by the callback.
1174  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1175  
1176  return CVPixelBufferCreateWithBytes(allocator, width, height, pixelFormatType,
1177                                baseAddress, bytesPerRow, releaseCallback,
1178                                number, // potentially released by callback
1179                                pixelBufferAttributes, pixelBufferOut) ;
1180}
1181
1182CVReturn rdar_7283567_2(CFAllocatorRef allocator, size_t width, size_t height,
1183        OSType pixelFormatType, void *dataPtr, size_t dataSize,
1184        size_t numberOfPlanes, void *planeBaseAddress[],
1185        size_t planeWidth[], size_t planeHeight[], size_t planeBytesPerRow[],
1186        CVPixelBufferReleasePlanarBytesCallback releaseCallback,
1187        CFDictionaryRef pixelBufferAttributes,
1188        CVPixelBufferRef *pixelBufferOut) {
1189    
1190    // For the allocated object, it doesn't really matter what type it is
1191    // for the purpose of this test.  All we want to show is that
1192    // this is freed later by the callback.
1193    NSNumber *number = [[NSNumber alloc] initWithInt:5];
1194
1195    return CVPixelBufferCreateWithPlanarBytes(allocator,
1196              width, height, pixelFormatType, dataPtr, dataSize,
1197              numberOfPlanes, planeBaseAddress, planeWidth,
1198              planeHeight, planeBytesPerRow, releaseCallback,
1199              number, // potentially released by callback
1200              pixelBufferAttributes, pixelBufferOut) ;
1201}
1202
1203//===----------------------------------------------------------------------===//
1204// <rdar://problem/7358899> False leak associated with 
1205//  CGBitmapContextCreateWithData
1206//===----------------------------------------------------------------------===//
1207typedef uint32_t CGBitmapInfo;
1208typedef void (*CGBitmapContextReleaseDataCallback)(void *releaseInfo, void *data);
1209    
1210CGContextRef CGBitmapContextCreateWithData(void *data,
1211    size_t width, size_t height, size_t bitsPerComponent,
1212    size_t bytesPerRow, CGColorSpaceRef space, CGBitmapInfo bitmapInfo,
1213    CGBitmapContextReleaseDataCallback releaseCallback, void *releaseInfo);
1214
1215void rdar_7358899(void *data,
1216      size_t width, size_t height, size_t bitsPerComponent,
1217      size_t bytesPerRow, CGColorSpaceRef space, CGBitmapInfo bitmapInfo,
1218      CGBitmapContextReleaseDataCallback releaseCallback) {
1219
1220    // For the allocated object, it doesn't really matter what type it is
1221    // for the purpose of this test.  All we want to show is that
1222    // this is freed later by the callback.
1223    NSNumber *number = [[NSNumber alloc] initWithInt:5];
1224
1225  CGBitmapContextCreateWithData(data, width, height, bitsPerComponent,
1226    bytesPerRow, space, bitmapInfo, releaseCallback, number);
1227}
1228
1229//===----------------------------------------------------------------------===//
1230// <rdar://problem/7265711> allow 'new', 'copy', 'alloc', 'init' prefix to
1231//  start before '_' when determining Cocoa fundamental rule
1232//
1233// Previously the retain/release checker just skipped prefixes before the
1234// first '_' entirely.  Now the checker honors the prefix if it results in a
1235// recognizable naming convention (e.g., 'new', 'init').
1236//===----------------------------------------------------------------------===//
1237
1238@interface RDar7265711 {}
1239- (id) new_stuff;
1240@end
1241
1242void rdar7265711_a(RDar7265711 *x) {
1243  id y = [x new_stuff];
1244}
1245
1246void rdar7265711_b(RDar7265711 *x) {
1247  id y = [x new_stuff];
1248  [y release];
1249}
1250
1251//===----------------------------------------------------------------------===//
1252// <rdar://problem/7306898> clang thinks [NSCursor dragCopyCursor] returns a
1253//                          retained reference
1254//===----------------------------------------------------------------------===//
1255
1256@interface NSCursor : NSObject
1257+ (NSCursor *)dragCopyCursor;
1258@end
1259
1260void rdar7306898(void) {
1261  // 'dragCopyCursor' does not follow Cocoa's fundamental rule.  It is a noun, not an sentence
1262  // implying a 'copy' of something.
1263  NSCursor *c =  [NSCursor dragCopyCursor];
1264  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1265}
1266
1267//===----------------------------------------------------------------------===//
1268// <rdar://problem/7252064> sending 'release', 'retain', etc. to a Class
1269// directly is not likely what the user intended
1270//===----------------------------------------------------------------------===//
1271
1272@interface RDar7252064 : NSObject @end
1273void rdar7252064(void) {
1274  [RDar7252064 release];
1275  [RDar7252064 retain];
1276  [RDar7252064 autorelease];
1277  [NSAutoreleasePool drain];
1278}
1279
1280//===----------------------------------------------------------------------===//
1281// Tests of ownership attributes.
1282//===----------------------------------------------------------------------===//
1283
1284typedef NSString* MyStringTy;
1285
1286@protocol FooP;
1287
1288@interface TestOwnershipAttr : NSObject
1289- (NSString*) returnsAnOwnedString  NS_RETURNS_RETAINED;
1290- (NSString*) returnsAnOwnedCFString  CF_RETURNS_RETAINED;
1291- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED;
1292- (NSString*) newString NS_RETURNS_NOT_RETAINED;
1293- (NSString*) newStringNoAttr;
1294- (int) returnsAnOwnedInt NS_RETURNS_RETAINED;
1295- (id) pseudoInit NS_CONSUMES_SELF NS_RETURNS_RETAINED;
1296+ (void) consume:(id) NS_CONSUMED x;
1297+ (void) consume2:(id) CF_CONSUMED x;
1298@end
1299
1300static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED;
1301
1302void test_attr_1(TestOwnershipAttr *X) {
1303  NSString *str = [X returnsAnOwnedString];
1304}
1305
1306void test_attr_1b(TestOwnershipAttr *X) {
1307  NSString *str = [X returnsAnOwnedCFString];
1308}
1309
1310void test_attr1c(TestOwnershipAttr *X) {
1311  NSString *str = [X newString];
1312  NSString *str2 = [X newStringNoAttr];
1313}
1314
1315void testattr2_a() {
1316  TestOwnershipAttr *x = [TestOwnershipAttr alloc];
1317}
1318
1319void testattr2_b() {
1320  TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];
1321}
1322
1323void testattr2_b_11358224_self_assign_looses_the_leak() {
1324  TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];// expected-warning{{leak}}
1325  x = x;
1326}
1327
1328void testattr2_c() {
1329  TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];
1330  [x release];
1331}
1332
1333void testattr3() {
1334  TestOwnershipAttr *x = [TestOwnershipAttr alloc];
1335  [TestOwnershipAttr consume:x];
1336  TestOwnershipAttr *y = [TestOwnershipAttr alloc];
1337  [TestOwnershipAttr consume2:y];
1338}
1339
1340void consume_ns(id NS_CONSUMED x);
1341void consume_cf(id CF_CONSUMED x);
1342
1343void testattr4() {
1344  TestOwnershipAttr *x = [TestOwnershipAttr alloc];
1345  consume_ns(x);
1346  TestOwnershipAttr *y = [TestOwnershipAttr alloc];
1347  consume_cf(y);
1348}
1349
1350@interface TestOwnershipAttr2 : NSObject
1351- (NSString*) newString NS_RETURNS_NOT_RETAINED;
1352@end
1353
1354@implementation TestOwnershipAttr2
1355- (NSString*) newString {
1356  return [NSString alloc];
1357}
1358@end
1359
1360@interface MyClassTestCFAttr : NSObject {}
1361- (NSDate*) returnsCFRetained CF_RETURNS_RETAINED;
1362- (CFDateRef) returnsCFRetainedAsCF CF_RETURNS_RETAINED;
1363- (CFDateRef) newCFRetainedAsCF CF_RETURNS_NOT_RETAINED;
1364- (CFDateRef) newCFRetainedAsCFNoAttr;
1365- (NSDate*) alsoReturnsRetained;
1366- (CFDateRef) alsoReturnsRetainedAsCF;
1367- (NSDate*) returnsNSRetained NS_RETURNS_RETAINED;
1368@end
1369
1370CF_RETURNS_RETAINED
1371CFDateRef returnsRetainedCFDate()  {
1372  return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
1373}
1374
1375@implementation MyClassTestCFAttr
1376- (NSDate*) returnsCFRetained {
1377  return (NSDate*) returnsRetainedCFDate(); // No leak.
1378}
1379
1380- (CFDateRef) returnsCFRetainedAsCF {
1381  return returnsRetainedCFDate(); // No leak.
1382}
1383
1384- (CFDateRef) newCFRetainedAsCF {
1385  return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
1386}
1387
1388- (CFDateRef) newCFRetainedAsCFNoAttr {
1389  return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
1390}
1391
1392- (NSDate*) alsoReturnsRetained {
1393  return (NSDate*) returnsRetainedCFDate();
1394}
1395
1396- (CFDateRef) alsoReturnsRetainedAsCF {
1397  return returnsRetainedCFDate();
1398}
1399
1400
1401- (NSDate*) returnsNSRetained {
1402  return (NSDate*) returnsRetainedCFDate();
1403}
1404@end
1405
1406//===----------------------------------------------------------------------===//
1407// Test that leaks post-dominated by "panic" functions are not reported.
1408//
1409// <rdar://problem/5905851> do not report a leak when post-dominated by a call
1410// to a noreturn or panic function
1411//===----------------------------------------------------------------------===//
1412
1413void panic() __attribute__((noreturn));
1414void panic_not_in_hardcoded_list() __attribute__((noreturn));
1415
1416void test_panic_negative() {
1417  signed z = 1;
1418  CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
1419}
1420
1421void test_panic_positive() {
1422  signed z = 1;
1423  CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
1424  panic();
1425}
1426
1427void test_panic_neg_2(int x) {
1428  signed z = 1;
1429  CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
1430  if (x)
1431    panic();
1432}
1433
1434void test_panic_pos_2(int x) {
1435  signed z = 1;
1436  CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
1437  if (x)
1438    panic();
1439  if (!x) {
1440    // This showed up in <rdar://problem/7796563>, where we silently missed checking
1441    // the function type for noreturn.  "panic()" is a hard-coded known panic function
1442    // that isn't always noreturn.
1443    panic_not_in_hardcoded_list();
1444  }
1445}
1446
1447//===----------------------------------------------------------------------===//
1448// Test uses of blocks (closures)
1449//===----------------------------------------------------------------------===//
1450
1451void test_blocks_1_pos(void) {
1452  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1453  ^{}();
1454}
1455
1456void test_blocks_1_indirect_release(void) {
1457  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1458  ^{ [number release]; }();
1459}
1460
1461void test_blocks_1_indirect_retain(void) {
1462  // Eventually this should be reported as a leak.
1463  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1464  ^{ [number retain]; }();
1465}
1466
1467void test_blocks_1_indirect_release_via_call(void) {
1468  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1469  ^(NSObject *o){ [o release]; }(number);
1470}
1471
1472void test_blocks_1_indirect_retain_via_call(void) {
1473  NSNumber *number = [[NSNumber alloc] initWithInt:5];
1474  ^(NSObject *o){ [o retain]; }(number);
1475}
1476
1477//===--------------------------------------------------------------------===//
1478// Test sending message to super that returns an object alias.  Previously
1479// this caused a crash in the analyzer.
1480//===--------------------------------------------------------------------===//
1481
1482@interface Rdar8015556 : NSObject {} @end
1483@implementation Rdar8015556
1484- (id)retain {
1485  return [super retain];
1486}
1487@end
1488
1489// <rdar://problem/8272168> - Correcly handle Class<...> in Cocoa Conventions
1490// detector.
1491
1492@protocol Prot_R8272168 @end
1493Class <Prot_R8272168> GetAClassThatImplementsProt_R8272168();
1494void r8272168() {
1495  GetAClassThatImplementsProt_R8272168();
1496}
1497
1498// Test case for <rdar://problem/8356342>, which in the past triggered
1499// a false positive.
1500@interface RDar8356342
1501- (NSDate*) rdar8356342:(NSDate *)inValue;
1502@end
1503
1504@implementation RDar8356342
1505- (NSDate*) rdar8356342:(NSDate*)inValue {
1506  NSDate *outValue = inValue;
1507  if (outValue == 0)
1508    outValue = [[NSDate alloc] init];
1509
1510  if (outValue != inValue)
1511    [outValue autorelease];
1512
1513  return outValue;
1514}
1515@end
1516
1517// <rdar://problem/8724287> - This test case previously crashed because
1518// of a bug in BugReporter.
1519extern const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key);
1520typedef struct __CFError * CFErrorRef;
1521extern const CFStringRef kCFErrorUnderlyingErrorKey;
1522extern CFDictionaryRef CFErrorCopyUserInfo(CFErrorRef err);
1523static void rdar_8724287(CFErrorRef error)
1524{
1525    CFErrorRef error_to_dump;
1526
1527    error_to_dump = error;
1528    while (error_to_dump != ((void*)0)) {
1529        CFDictionaryRef info;
1530
1531        info = CFErrorCopyUserInfo(error_to_dump);
1532
1533        if (info != ((void*)0)) {
1534        }
1535
1536        error_to_dump = (CFErrorRef) CFDictionaryGetValue(info, kCFErrorUnderlyingErrorKey);
1537    }
1538}
1539
1540// <rdar://problem/9234108> - Make sure the model applies cf_consumed
1541// correctly in argument positions besides the first.
1542extern void *CFStringCreate(void);
1543extern void rdar_9234108_helper(void *key, void * CF_CONSUMED value);
1544void rdar_9234108() {
1545  rdar_9234108_helper(0, CFStringCreate());
1546}
1547
1548// <rdar://problem/9726279> - Make sure that objc_method_family works
1549// to override naming conventions.
1550struct TwoDoubles {
1551  double one;
1552  double two;
1553};
1554typedef struct TwoDoubles TwoDoubles;
1555
1556@interface NSValue (Mine)
1557- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles __attribute__((objc_method_family(init)));
1558@end
1559
1560@implementation NSValue (Mine)
1561- (id)_prefix_initWithTwoDoubles:(TwoDoubles)twoDoubles
1562{
1563  return [self init];
1564}
1565@end
1566
1567void rdar9726279() {
1568  TwoDoubles twoDoubles = { 0.0, 0.0 };
1569  NSValue *value = [[NSValue alloc] _prefix_initWithTwoDoubles:twoDoubles];
1570  [value release];
1571}
1572
1573// <rdar://problem/9732321>
1574// Test camelcase support for CF conventions.  While Core Foundation APIs
1575// don't use camel casing, other code is allowed to use it.
1576CFArrayRef camelcase_create_1() {
1577  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1578}
1579
1580CFArrayRef camelcase_createno() {
1581  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1582}
1583
1584CFArrayRef camelcase_copy() {
1585  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1586}
1587
1588CFArrayRef camelcase_copying() {
1589  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1590}
1591
1592CFArrayRef copyCamelCase() {
1593  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1594}
1595
1596CFArrayRef __copyCamelCase() {
1597  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1598}
1599
1600CFArrayRef __createCamelCase() {
1601  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1602}
1603
1604CFArrayRef camel_create() {
1605  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1606}
1607
1608
1609CFArrayRef camel_creat() {
1610  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1611}
1612
1613CFArrayRef camel_copy() {
1614  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1615}
1616
1617CFArrayRef camel_copyMachine() {
1618  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1619}
1620
1621CFArrayRef camel_copymachine() {
1622  return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1623}
1624
1625// rdar://problem/8024350
1626@protocol F18P
1627- (id) clone;
1628@end
1629@interface F18 : NSObject<F18P> @end
1630@interface F18(Cat)
1631- (id) clone NS_RETURNS_RETAINED;
1632@end
1633
1634@implementation F18
1635- (id) clone {
1636  return [F18 alloc];
1637}
1638@end
1639
1640// Radar 6582778.
1641void rdar6582778(void) {
1642  CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
1643  CFTypeRef vals[] = { CFDateCreate(0, t) };
1644}
1645
1646CFTypeRef global;
1647
1648void rdar6582778_2(void) {
1649  CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
1650  global = CFDateCreate(0, t);
1651}
1652
1653// <rdar://problem/10232019> - Test that objects passed to containers
1654// are marked "escaped".
1655
1656void rdar10232019() {
1657  NSMutableArray *array = [NSMutableArray array];
1658
1659  NSString *string = [[NSString alloc] initWithUTF8String:"foo"];
1660  [array addObject:string];
1661  [string release];
1662
1663  NSString *otherString = [string stringByAppendingString:@"bar"];
1664  NSLog(@"%@", otherString);
1665}
1666
1667void rdar10232019_positive() {
1668  NSMutableArray *array = [NSMutableArray array];
1669
1670  NSString *string = [[NSString alloc] initWithUTF8String:"foo"];
1671  [string release];
1672
1673  NSString *otherString = [string stringByAppendingString:@"bar"];
1674  NSLog(@"%@", otherString);
1675}
1676
1677// RetainCountChecker support for XPC.
1678// <rdar://problem/9658496>
1679typedef void * xpc_object_t;
1680xpc_object_t _CFXPCCreateXPCObjectFromCFObject(CFTypeRef cf);
1681void xpc_release(xpc_object_t object);
1682
1683void rdar9658496() {
1684  CFStringRef cf;
1685  xpc_object_t xpc;
1686  cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 );
1687  xpc = _CFXPCCreateXPCObjectFromCFObject( cf );
1688  CFRelease(cf);
1689  xpc_release(xpc);
1690}
1691
1692// Support annotations with method families.
1693@interface RDar10824732 : NSObject
1694- (id)initWithObj:(id CF_CONSUMED)obj;
1695@end
1696
1697@implementation RDar10824732
1698- (id)initWithObj:(id)obj {
1699  [obj release];
1700  return [super init];
1701}
1702@end
1703
1704void rdar_10824732() {
1705  @autoreleasepool {
1706    NSString *obj = @"test";
1707    RDar10824732 *foo = [[RDar10824732 alloc] initWithObj:obj];
1708    [foo release];
1709  }
1710}
1711
1712// Stop tracking objects passed to functions, which take callbacks as parameters.
1713// radar://10973977
1714typedef int (*CloseCallback) (void *);
1715void ReaderForIO(CloseCallback ioclose, void *ioctx);
1716int IOClose(void *context);
1717
1718@protocol SInS <NSObject>
1719@end
1720
1721@interface radar10973977 : NSObject
1722- (id<SInS>)inputS;
1723- (void)reader;
1724@end
1725
1726@implementation radar10973977
1727- (void)reader
1728{
1729    id<SInS> inputS = [[self inputS] retain];
1730    ReaderForIO(IOClose, inputS);
1731}
1732- (id<SInS>)inputS
1733{
1734    return 0;
1735}
1736@end
1737
1738// Object escapes through a selector callback: radar://11398514
1739extern id NSApp;
1740@interface MySheetController
1741- (id<SInS>)inputS;
1742- (void)showDoSomethingSheetAction:(id)action;
1743- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
1744@end
1745
1746@implementation MySheetController
1747- (id<SInS>)inputS {
1748    return 0;
1749}
1750- (void)showDoSomethingSheetAction:(id)action {
1751  id<SInS> inputS = [[self inputS] retain]; 
1752  [NSApp beginSheet:0
1753         modalForWindow:0
1754         modalDelegate:0
1755         didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
1756         contextInfo:(void *)inputS]; // no - warning
1757}
1758- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo {
1759   
1760      id contextObject = (id)contextInfo;
1761      [contextObject release];
1762}
1763@end
1764//===----------------------------------------------------------------------===//
1765// Test returning allocated memory in a struct.
1766//
1767// We currently don't have a general way to track pointers that "escape".
1768// Here we test that RetainCountChecker doesn't get excited about returning
1769// allocated CF objects in struct fields.
1770//===----------------------------------------------------------------------===//
1771void *malloc(size_t);
1772struct rdar11104566 { CFStringRef myStr; };
1773struct rdar11104566 test_rdar11104566() {
1774  CFStringRef cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 );
1775  struct rdar11104566 V;
1776  V.myStr = cf;
1777  return V;
1778}
1779
1780struct rdar11104566 *test_2_rdar11104566() {
1781  CFStringRef cf = CFStringCreateWithCString( ((CFAllocatorRef)0), "test", kCFStringEncodingUTF8 );
1782  struct rdar11104566 *V = (struct rdar11104566 *) malloc(sizeof(*V));
1783  V->myStr = cf;
1784  return V;
1785}
1786
1787//===----------------------------------------------------------------------===//
1788// ObjC literals support.
1789//===----------------------------------------------------------------------===//
1790
1791void test_objc_arrays() {
1792    { // CASE ONE -- OBJECT IN ARRAY CREATED DIRECTLY
1793        NSObject *o = [[NSObject alloc] init];
1794        NSArray *a = [[NSArray alloc] initWithObjects:o, (void*)0];
1795        [o release];
1796        [a description];
1797        [o description];
1798    }
1799
1800    { // CASE TWO -- OBJECT IN ARRAY CREATED BY DUPING AUTORELEASED ARRAY
1801        NSObject *o = [[NSObject alloc] init];
1802        NSArray *a1 = [NSArray arrayWithObjects:o, (void*)0];
1803        NSArray *a2 = [[NSArray alloc] initWithArray:a1];
1804        [o release];        
1805        [a2 description];
1806        [o description];
1807    }
1808
1809    { // CASE THREE -- OBJECT IN RETAINED @[]
1810        NSObject *o = [[NSObject alloc] init];
1811        NSArray *a3 = [@[o] retain];
1812        [o release];        
1813        [a3 description];
1814        [o description];
1815    }
1816    
1817    { // CASE FOUR -- OBJECT IN ARRAY CREATED BY DUPING @[]
1818        NSObject *o = [[NSObject alloc] init];
1819        NSArray *a = [[NSArray alloc] initWithArray:@[o]];
1820        [o release];
1821        
1822        [a description];
1823        [o description];
1824    }
1825    
1826    { // CASE FIVE -- OBJECT IN RETAINED @{}
1827        NSValue *o = [[NSValue alloc] init];
1828        NSDictionary *a = [@{o : o} retain];
1829        [o release];
1830        
1831        [a description];
1832        [o description];
1833    }
1834}
1835
1836void test_objc_integer_literals() {
1837  id value = [@1 retain];
1838  [value description];
1839}
1840
1841void test_objc_boxed_expressions(int x, const char *y) {
1842  id value = [@(x) retain];
1843  [value description];
1844
1845  value = [@(y) retain];
1846  [value description];
1847}
1848
1849// Test NSLog doesn't escape tracked objects.
1850void rdar11400885(int y)
1851{
1852  @autoreleasepool {
1853    NSString *printString;
1854    if(y > 2)
1855      printString = [[NSString alloc] init];
1856    else
1857      printString = [[NSString alloc] init];
1858    NSLog(@"Once %@", printString);
1859    [printString release];
1860    NSLog(@"Again: %@", printString);
1861  }
1862}
1863
1864id makeCollectableNonLeak() {
1865  extern CFTypeRef CFCreateSomething();
1866
1867  CFTypeRef object = CFCreateSomething(); // +1
1868  CFRetain(object); // +2
1869  id objCObject = NSMakeCollectable(object); // +2
1870  [objCObject release]; // +1
1871  return [objCObject autorelease]; // +0
1872}
1873
1874
1875void consumeAndStopTracking(id NS_CONSUMED obj, void (^callback)(void));
1876void CFConsumeAndStopTracking(CFTypeRef CF_CONSUMED obj, void (^callback)(void));
1877
1878void testConsumeAndStopTracking() {
1879  id retained = [@[] retain]; // +1
1880  consumeAndStopTracking(retained, ^{});
1881
1882  id doubleRetained = [[@[] retain] retain]; // +2
1883  consumeAndStopTracking(doubleRetained, ^{
1884    [doubleRetained release];
1885  });
1886
1887  id unretained = @[]; // +0
1888  consumeAndStopTracking(unretained, ^{});
1889}
1890
1891void testCFConsumeAndStopTracking() {
1892  id retained = [@[] retain]; // +1
1893  CFConsumeAndStopTracking((CFTypeRef)retained, ^{});
1894
1895  id doubleRetained = [[@[] retain] retain];
1896  CFConsumeAndStopTracking((CFTypeRef)doubleRetained, ^{
1897    [doubleRetained release];
1898  });
1899
1900  id unretained = @[]; // +0
1901  CFConsumeAndStopTracking((CFTypeRef)unretained, ^{});
1902}
1903//===----------------------------------------------------------------------===//
1904// Test 'pragma clang arc_cf_code_audited' support.
1905//===----------------------------------------------------------------------===//
1906
1907typedef void *MyCFType;
1908#pragma clang arc_cf_code_audited begin
1909MyCFType CreateMyCFType();
1910#pragma clang arc_cf_code_audited end 
1911    
1912void test_custom_cf() {
1913  MyCFType x = CreateMyCFType();
1914}
1915
1916//===----------------------------------------------------------------------===//
1917// Test calling CFPlugInInstanceCreate, which appears in CF but doesn't
1918// return a CF object.
1919//===----------------------------------------------------------------------===//
1920
1921void test_CFPlugInInstanceCreate(CFUUIDRef factoryUUID, CFUUIDRef typeUUID) {
1922  CFPlugInInstanceCreate(kCFAllocatorDefault, factoryUUID, typeUUID);
1923}
1924
1925// CHECK: 934:3: warning: 'IOServiceAddNotification' is deprecated
1926// CHECK:   IOServiceAddNotification(masterPort, notificationType, matching,
1927// CHECK:   ^
1928// CHECK: 204:15: note: 'IOServiceAddNotification' declared here
1929// CHECK: kern_return_t IOServiceAddNotification(  mach_port_t masterPort,  const io_name_t notificationType,  CFDictionaryRef matching,  mach_port_t wakePort,  uintptr_t reference,  io_iterator_t * notification ) __attribute__((deprecated)); // expected-note {{'IOServiceAddNotification' declared here}}
1930// CHECK:               ^
1931// CHECK: 1277:3: warning: class method '+drain' not found (return type defaults to 'id')
1932// CHECK:   [NSAutoreleasePool drain];
1933// CHECK:   ^                  ~~~~~
1934// CHECK: 1294:1: warning: 'ns_returns_retained' attribute only applies to methods that return an Objective-C object
1935// CHECK: - (int) returnsAnOwnedInt NS_RETURNS_RETAINED;
1936// CHECK: ^                         ~~~~~~~~~~~~~~~~~~~
1937// CHECK: 1300:1: warning: 'ns_returns_retained' attribute only applies to functions and methods
1938// CHECK: static int ownership_attribute_doesnt_go_here NS_RETURNS_RETAINED;
1939// CHECK: ^                                             ~~~~~~~~~~~~~~~~~~~
1940// CHECK: 324:7: warning: Reference-counted object is used after it is released
1941// CHECK:   t = CFDateGetAbsoluteTime(date);
1942// CHECK:       ^                     ~~~~
1943// CHECK: 335:7: warning: Reference-counted object is used after it is released
1944// CHECK:   t = CFDateGetAbsoluteTime(date);
1945// CHECK:       ^                     ~~~~
1946// CHECK: 366:20: warning: Potential leak of an object stored into 'date'
1947// CHECK:   CFDateRef date = CFDateCreate(0, t);
1948// CHECK:                    ^
1949// CHECK: 377:20: warning: Potential leak of an object stored into 'date'
1950// CHECK:   CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
1951// CHECK:                    ^
1952// CHECK: 385:20: warning: Potential leak of an object stored into 'date'
1953// CHECK:   CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());  //expected-warning{{leak}}
1954// CHECK:                    ^
1955// CHECK: 387:10: warning: Potential leak of an object stored into 'date'
1956// CHECK:   date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
1957// CHECK:          ^
1958// CHECK: 396:20: warning: Potential leak of an object stored into 'date'
1959// CHECK:   CFDateRef date = MyDateCreate();
1960// CHECK:                    ^
1961// CHECK: 405:17: warning: Dereference of null pointer (loaded from variable 'p')
1962// CHECK:   if (!date) *p = 1;
1963// CHECK:               ~ ^
1964// CHECK: 414:20: warning: Potential leak of an object stored into 'disk'
1965// CHECK:   DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, 0, "hello");
1966// CHECK:                    ^
1967// CHECK: 417:10: warning: Potential leak of an object stored into 'disk'
1968// CHECK:   disk = DADiskCreateFromIOMedia(kCFAllocatorDefault, 0, media);
1969// CHECK:          ^
1970// CHECK: 420:26: warning: Potential leak of an object stored into 'dict'
1971// CHECK:   CFDictionaryRef dict = DADiskCopyDescription(d);
1972// CHECK:                          ^
1973// CHECK: 423:10: warning: Potential leak of an object stored into 'disk'
1974// CHECK:   disk = DADiskCopyWholeDisk(d);
1975// CHECK:          ^
1976// CHECK: 426:30: warning: Potential leak of an object stored into 'dissenter'
1977// CHECK:   DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault,
1978// CHECK:                              ^
1979// CHECK: 430:26: warning: Potential leak of an object stored into 'session'
1980// CHECK:   DASessionRef session = DASessionCreate(kCFAllocatorDefault);
1981// CHECK:                          ^
1982// CHECK: 456:3: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
1983// CHECK:   CFRelease(s1);
1984// CHECK:   ^         ~~
1985// CHECK: 464:17: warning: Potential leak of an object stored into 'o'
1986// CHECK:   CFTypeRef o = MyCreateFun();
1987// CHECK:                 ^
1988// CHECK: 475:3: warning: Object sent -autorelease too many times
1989// CHECK:   [(id) A autorelease];
1990// CHECK:   ^~~~~~~~~~~~~~~~~~~~
1991// CHECK: 482:3: warning: Object sent -autorelease too many times
1992// CHECK:   return A;
1993// CHECK:   ^
1994// CHECK: 489:25: warning: Object sent -autorelease too many times
1995// CHECK:   CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1996// CHECK:                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1997// CHECK: 497:3: warning: Potential leak of an object
1998// CHECK:   CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
1999// CHECK:   ^
2000// CHECK: 516:5: warning: Null pointer argument in call to CFRelease
2001// CHECK:     CFRelease(p);
2002// CHECK:     ^         ~
2003// CHECK: 519:5: warning: Null pointer argument in call to CFRetain
2004// CHECK:     CFRetain(p);
2005// CHECK:     ^        ~
2006// CHECK: 561:3: warning: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected
2007// CHECK:   return s;
2008// CHECK:   ^
2009// CHECK: 574:20: warning: Potential leak of an object stored into 'kind'
2010// CHECK:   NSString *kind = [[NSString alloc] initWithUTF8String:inkind];
2011// CHECK:                    ^
2012// CHECK: 596:13: warning: Array access (from variable 'kindC') results in a null pointer dereference
2013// CHECK:   if(!isFoo(kindC[0]))
2014// CHECK:             ^~~~~
2015// CHECK: 602:3: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2016// CHECK:   [name release];
2017// CHECK:   ^~~~~
2018// CHECK: 626:3: warning: Reference-counted object is used after it is released
2019// CHECK:   [foo release];
2020// CHECK:   ^~~~
2021// CHECK: 635:3: warning: Reference-counted object is used after it is released
2022// CHECK:   [foo dealloc];
2023// CHECK:   ^~~~
2024// CHECK: 687:31: warning: Potential leak of an object stored into 'dict'
2025// CHECK:  NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
2026// CHECK:                               ^
2027// CHECK: 699:31: warning: Potential leak of an object stored into 'dict'
2028// CHECK:  NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
2029// CHECK:                               ^
2030// CHECK: 712:3: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2031// CHECK:   [array release];
2032// CHECK:   ^~~~~~
2033// CHECK: 788:3: warning: Potential leak of an object
2034// CHECK:   [[RDar6320065Subclass alloc] init];
2035// CHECK:   ^
2036// CHECK: 794:3: warning: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected
2037// CHECK:   return [self autorelease];
2038// CHECK:   ^
2039// CHECK: 832:37: warning: Potential leak of an object
2040// CHECK: - (NSString*) NoCopyString { return [[NSString alloc] init]; }
2041// CHECK:                                     ^
2042// CHECK: 833:37: warning: Potential leak of an object
2043// CHECK: - (NSString*) noCopyString { return [[NSString alloc] init]; }
2044// CHECK:                                     ^
2045// CHECK: 837:3: warning: Potential leak of an object
2046// CHECK:   [x NoCopyString];
2047// CHECK:   ^
2048// CHECK: 838:3: warning: Potential leak of an object
2049// CHECK:   [x noCopyString];
2050// CHECK:   ^
2051// CHECK: 865:10: warning: Potential leak of an object
2052// CHECK:   return [[NSString alloc] init];
2053// CHECK:          ^
2054// CHECK: 895:3: warning: Potential leak of an object
2055// CHECK:   [view createSnapshotImageOfType:str];
2056// CHECK:   ^
2057// CHECK: 896:3: warning: Potential leak of an object
2058// CHECK:   [renderer createSnapshotImageOfType:str];
2059// CHECK:   ^
2060// CHECK: 897:3: warning: Potential leak of an object
2061// CHECK:   [context createCGImage:img fromRect:rect];
2062// CHECK:   ^
2063// CHECK: 898:3: warning: Potential leak of an object
2064// CHECK:   [context createCGImage:img fromRect:rect format:form colorSpace:cs];
2065// CHECK:   ^
2066// CHECK: 907:3: warning: Potential leak of an object
2067// CHECK:   [context createCGLayerWithSize:size info:d];
2068// CHECK:   ^
2069// CHECK: 916:3: warning: Potential leak of an object
2070// CHECK:   IOBSDNameMatching(masterPort, options, bsdName);
2071// CHECK:   ^
2072// CHECK: 920:3: warning: Potential leak of an object
2073// CHECK:   IOServiceMatching(name);
2074// CHECK:   ^
2075// CHECK: 924:3: warning: Potential leak of an object
2076// CHECK:   IOServiceNameMatching(name);
2077// CHECK:   ^
2078// CHECK: 934:3: warning: Reference-counted object is used after it is released
2079// CHECK:   IOServiceAddNotification(masterPort, notificationType, matching,
2080// CHECK:   ^                                                      ~~~~~~~~
2081// CHECK: 939:3: warning: Potential leak of an object
2082// CHECK:   IORegistryEntryIDMatching(entryID);
2083// CHECK:   ^
2084// CHECK: 944:3: warning: Potential leak of an object
2085// CHECK:   IOOpenFirmwarePathMatching(masterPort, options, path);
2086// CHECK:   ^
2087// CHECK: 950:3: warning: Reference-counted object is used after it is released
2088// CHECK:   CFRelease(matching);
2089// CHECK:   ^         ~~~~~~~~
2090// CHECK: 956:3: warning: Reference-counted object is used after it is released
2091// CHECK:   CFRelease(matching);
2092// CHECK:   ^         ~~~~~~~~
2093// CHECK: 964:3: warning: Reference-counted object is used after it is released
2094// CHECK:   CFRelease(matching);
2095// CHECK:   ^         ~~~~~~~~
2096// CHECK: 1005:22: warning: Potential leak of an object stored into 'number'
2097// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2098// CHECK:                      ^
2099// CHECK: 1030:41: warning: Potential leak of an object
2100// CHECK:     CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),
2101// CHECK:                                         ^
2102// CHECK: 1052:4: warning: Potential leak of an object stored into 'myGradient'
2103// CHECK:    CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations);
2104// CHECK:    ^
2105// CHECK: 1052:40: warning: Potential leak of an object
2106// CHECK:    CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations);
2107// CHECK:                                        ^
2108// CHECK: 1090:22: warning: Potential leak of an object stored into 'number'
2109// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2110// CHECK:                      ^
2111// CHECK: 1225:3: warning: Potential leak of an object
2112// CHECK:   CGBitmapContextCreateWithData(data, width, height, bitsPerComponent,
2113// CHECK:   ^
2114// CHECK: 1243:10: warning: Potential leak of an object stored into 'y'
2115// CHECK:   id y = [x new_stuff];
2116// CHECK:          ^
2117// CHECK: 1264:22: warning: Potential leak of an object stored into 'number'
2118// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2119// CHECK:                      ^
2120// CHECK: 1274:3: warning: The 'release' message should be sent to instances of class 'RDar7252064' and not the class directly
2121// CHECK:   [RDar7252064 release];
2122// CHECK:   ^~~~~~~~~~~~~~~~~~~~~
2123// CHECK: 1275:3: warning: The 'retain' message should be sent to instances of class 'RDar7252064' and not the class directly
2124// CHECK:   [RDar7252064 retain];
2125// CHECK:   ^~~~~~~~~~~~~~~~~~~~
2126// CHECK: 1276:3: warning: The 'autorelease' message should be sent to instances of class 'RDar7252064' and not the class directly
2127// CHECK:   [RDar7252064 autorelease];
2128// CHECK:   ^~~~~~~~~~~~~~~~~~~~~~~~~
2129// CHECK: 1277:3: warning: The 'drain' message should be sent to instances of class 'NSAutoreleasePool' and not the class directly
2130// CHECK:   [NSAutoreleasePool drain];
2131// CHECK:   ^~~~~~~~~~~~~~~~~~~~~~~~~
2132// CHECK: 1303:19: warning: Potential leak of an object stored into 'str'
2133// CHECK:   NSString *str = [X returnsAnOwnedString];
2134// CHECK:                   ^
2135// CHECK: 1307:19: warning: Potential leak of an object stored into 'str'
2136// CHECK:   NSString *str = [X returnsAnOwnedCFString];
2137// CHECK:                   ^
2138// CHECK: 1312:20: warning: Potential leak of an object stored into 'str2'
2139// CHECK:   NSString *str2 = [X newStringNoAttr];
2140// CHECK:                    ^
2141// CHECK: 1316:26: warning: Potential leak of an object stored into 'x'
2142// CHECK:   TestOwnershipAttr *x = [TestOwnershipAttr alloc];
2143// CHECK:                          ^
2144// CHECK: 1320:26: warning: Potential leak of an object stored into 'x'
2145// CHECK:   TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];
2146// CHECK:                          ^
2147// CHECK: 1324:26: warning: Potential leak of an object stored into 'x'
2148// CHECK:   TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];// expected-warning{{leak}}
2149// CHECK:                          ^
2150// CHECK: 1356:10: warning: Potential leak of an object
2151// CHECK:   return [NSString alloc];
2152// CHECK:          ^
2153// CHECK: 1389:3: warning: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected
2154// CHECK:   return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
2155// CHECK:   ^
2156// CHECK: 1393:20: warning: Potential leak of an object
2157// CHECK:   return (NSDate*) returnsRetainedCFDate();
2158// CHECK:                    ^
2159// CHECK: 1397:10: warning: Potential leak of an object
2160// CHECK:   return returnsRetainedCFDate();
2161// CHECK:          ^
2162// CHECK: 1418:23: warning: Potential leak of an object stored into 'value'
2163// CHECK:   CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
2164// CHECK:                       ^
2165// CHECK: 1429:23: warning: Potential leak of an object stored into 'value'
2166// CHECK:   CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
2167// CHECK:                       ^
2168// CHECK: 1452:22: warning: Potential leak of an object stored into 'number'
2169// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2170// CHECK:                      ^
2171// CHECK: 1473:22: warning: Potential leak of an object stored into 'number'
2172// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2173// CHECK:                      ^
2174// CHECK: 1531:16: warning: Potential leak of an object stored into 'info'
2175// CHECK:         info = CFErrorCopyUserInfo(error_to_dump);
2176// CHECK:                ^
2177// CHECK: 1581:10: warning: Potential leak of an object
2178// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2179// CHECK:          ^
2180// CHECK: 1589:10: warning: Potential leak of an object
2181// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2182// CHECK:          ^
2183// CHECK: 1610:10: warning: Potential leak of an object
2184// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2185// CHECK:          ^
2186// CHECK: 1622:10: warning: Potential leak of an object
2187// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2188// CHECK:          ^
2189// CHECK: 1643:24: warning: Potential leak of an object stored into 'vals'
2190// CHECK:   CFTypeRef vals[] = { CFDateCreate(0, t) };
2191// CHECK:                        ^
2192// CHECK: 1673:27: warning: Reference-counted object is used after it is released
2193// CHECK:   NSString *otherString = [string stringByAppendingString:@"bar"];
2194// CHECK:                           ^~~~~~~
2195// CHECK: 1794:22: warning: Potential leak of an object stored into 'a'
2196// CHECK:         NSArray *a = [[NSArray alloc] initWithObjects:o, (void*)0];
2197// CHECK:                      ^
2198// CHECK: 1803:23: warning: Potential leak of an object stored into 'a2'
2199// CHECK:         NSArray *a2 = [[NSArray alloc] initWithArray:a1];
2200// CHECK:                       ^
2201// CHECK: 1811:24: warning: Potential leak of an object stored into 'a3'
2202// CHECK:         NSArray *a3 = [@[o] retain];
2203// CHECK:                        ^
2204// CHECK: 1819:22: warning: Potential leak of an object stored into 'a'
2205// CHECK:         NSArray *a = [[NSArray alloc] initWithArray:@[o]];
2206// CHECK:                      ^
2207// CHECK: 1828:28: warning: Potential leak of an object stored into 'a'
2208// CHECK:         NSDictionary *a = [@{o : o} retain];
2209// CHECK:                            ^
2210// CHECK: 1837:15: warning: Potential leak of an object stored into 'value'
2211// CHECK:   id value = [@1 retain];
2212// CHECK:               ^
2213// CHECK: 1842:15: warning: Potential leak of an object stored into 'value'
2214// CHECK:   id value = [@(x) retain];
2215// CHECK:               ^
2216// CHECK: 1845:12: warning: Potential leak of an object stored into 'value'
2217// CHECK:   value = [@(y) retain];
2218// CHECK:            ^
2219// CHECK: 1860:5: warning: Reference-counted object is used after it is released
2220// CHECK:     NSLog(@"Again: %@", printString);
2221// CHECK:     ^                   ~~~~~~~~~~~
2222// CHECK: 1888:3: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2223// CHECK:   consumeAndStopTracking(unretained, ^{});
2224// CHECK:   ^                      ~~~~~~~~~~
2225// CHECK: 1901:3: warning: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2226// CHECK:   CFConsumeAndStopTracking((CFTypeRef)unretained, ^{});
2227// CHECK:   ^                        ~~~~~~~~~~~~~~~~~~~~~
2228// CHECK: 1913:16: warning: Potential leak of an object stored into 'x'
2229// CHECK:   MyCFType x = CreateMyCFType();
2230// CHECK:                ^
2231// CHECK: 319:20: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2232// CHECK:   CFDateRef date = CFDateCreate(0, t);
2233// CHECK:                    ^
2234// CHECK: 320:3: note: Reference count incremented. The object now has a +2 retain count
2235// CHECK:   CFRetain(date);
2236// CHECK:   ^
2237// CHECK: 321:3: note: Reference count decremented. The object now has a +1 retain count
2238// CHECK:   CFRelease(date);
2239// CHECK:   ^
2240// CHECK: 323:3: note: Object released
2241// CHECK:   CFRelease(date);
2242// CHECK:   ^
2243// CHECK: 324:7: note: Reference-counted object is used after it is released
2244// CHECK:   t = CFDateGetAbsoluteTime(date);
2245// CHECK:       ^
2246// CHECK: 330:20: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2247// CHECK:   CFDateRef date = CFDateCreate(0, t);  
2248// CHECK:                    ^
2249// CHECK: 331:3: note: Reference count incremented. The object now has a +2 retain count
2250// CHECK:   [((NSDate*) date) retain];
2251// CHECK:   ^
2252// CHECK: 332:3: note: Reference count decremented. The object now has a +1 retain count
2253// CHECK:   CFRelease(date);
2254// CHECK:   ^
2255// CHECK: 334:3: note: Object released
2256// CHECK:   [((NSDate*) date) release];
2257// CHECK:   ^
2258// CHECK: 335:7: note: Reference-counted object is used after it is released
2259// CHECK:   t = CFDateGetAbsoluteTime(date);
2260// CHECK:       ^
2261// CHECK: 366:20: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2262// CHECK:   CFDateRef date = CFDateCreate(0, t);
2263// CHECK:                    ^
2264// CHECK: 368:3: note: Taking false branch
2265// CHECK:   if (x)
2266// CHECK:   ^
2267// CHECK: 371:10: note: Object leaked: object allocated and stored into 'date' is not referenced later in this execution path and has a retain count of +1
2268// CHECK:   return t;
2269// CHECK:          ^
2270// CHECK: 377:20: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2271// CHECK:   CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
2272// CHECK:                    ^
2273// CHECK: 378:3: note: Reference count incremented. The object now has a +2 retain count
2274// CHECK:   CFRetain(date);
2275// CHECK:   ^
2276// CHECK: 379:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2277// CHECK:   return date;
2278// CHECK:   ^
2279// CHECK: 380:1: note: Object leaked: object allocated and stored into 'date' is not referenced later in this execution path and has a retain count of +1
2280// CHECK: }
2281// CHECK: ^
2282// CHECK: 385:20: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2283// CHECK:   CFDateRef date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());  //expected-warning{{leak}}
2284// CHECK:                    ^
2285// CHECK: 386:3: note: Reference count incremented. The object now has a +2 retain count
2286// CHECK:   CFRetain(date);
2287// CHECK:   ^
2288// CHECK: 388:3: note: Object leaked: object allocated and stored into 'date' is not referenced later in this execution path and has a retain count of +2
2289// CHECK:   return date;
2290// CHECK:   ^
2291// CHECK: 387:10: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2292// CHECK:   date = CFDateCreate(0, CFAbsoluteTimeGetCurrent());
2293// CHECK:          ^
2294// CHECK: 388:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2295// CHECK:   return date;
2296// CHECK:   ^
2297// CHECK: 388:3: note: Object leaked: object allocated and stored into 'date' is returned from a function whose name ('f7') does not contain 'Copy' or 'Create'.  This violates the naming convention rules given in the Memory Management Guide for Core Foundation
2298// CHECK: 396:20: note: Call to function 'MyDateCreate' returns a Core Foundation object with a +1 retain count
2299// CHECK:   CFDateRef date = MyDateCreate();
2300// CHECK:                    ^
2301// CHECK: 397:3: note: Reference count incremented. The object now has a +2 retain count
2302// CHECK:   CFRetain(date);  
2303// CHECK:   ^
2304// CHECK: 398:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2305// CHECK:   return date;
2306// CHECK:   ^
2307// CHECK: 399:1: note: Object leaked: object allocated and stored into 'date' is not referenced later in this execution path and has a retain count of +1
2308// CHECK: }
2309// CHECK: ^
2310// CHECK: 403:3: note: Variable 'p' initialized to a null pointer value
2311// CHECK:   int *p = 0;
2312// CHECK:   ^
2313// CHECK: 405:3: note: Taking true branch
2314// CHECK:   if (!date) *p = 1;
2315// CHECK:   ^
2316// CHECK: 405:14: note: Dereference of null pointer (loaded from variable 'p')
2317// CHECK:   if (!date) *p = 1;
2318// CHECK:              ^
2319// CHECK: 415:3: note: Taking false branch
2320// CHECK:   if (disk) NSLog(@"ok");
2321// CHECK:   ^
2322// CHECK: 418:3: note: Taking false branch
2323// CHECK:   if (disk) NSLog(@"ok");
2324// CHECK:   ^
2325// CHECK: 420:26: note: Call to function 'DADiskCopyDescription' returns a Core Foundation object with a +1 retain count
2326// CHECK:   CFDictionaryRef dict = DADiskCopyDescription(d);
2327// CHECK:                          ^
2328// CHECK: 421:7: note: Assuming 'dict' is non-null
2329// CHECK:   if (dict) NSLog(@"ok"); 
2330// CHECK:       ^
2331// CHECK: 421:3: note: Taking true branch
2332// CHECK:   if (dict) NSLog(@"ok"); 
2333// CHECK:   ^
2334// CHECK: 421:20: note: Object leaked: object allocated and stored into 'dict' is not referenced later in this execution path and has a retain count of +1
2335// CHECK:   if (dict) NSLog(@"ok"); 
2336// CHECK:                    ^
2337// CHECK: 415:3: note: Taking false branch
2338// CHECK:   if (disk) NSLog(@"ok");
2339// CHECK:   ^
2340// CHECK: 418:3: note: Taking false branch
2341// CHECK:   if (disk) NSLog(@"ok");
2342// CHECK:   ^
2343// CHECK: 421:3: note: Taking false branch
2344// CHECK:   if (dict) NSLog(@"ok"); 
2345// CHECK:   ^
2346// CHECK: 423:10: note: Call to function 'DADiskCopyWholeDisk' returns a Core Foundation object with a +1 retain count
2347// CHECK:   disk = DADiskCopyWholeDisk(d);
2348// CHECK:          ^
2349// CHECK: 424:7: note: Assuming 'disk' is non-null
2350// CHECK:   if (disk) NSLog(@"ok");
2351// CHECK:       ^
2352// CHECK: 424:3: note: Taking true branch
2353// CHECK:   if (disk) NSLog(@"ok");
2354// CHECK:   ^
2355// CHECK: 424:20: note: Object leaked: object allocated and stored into 'disk' is not referenced later in this execution path and has a retain count of +1
2356// CHECK:   if (disk) NSLog(@"ok");
2357// CHECK:                    ^
2358// CHECK: 415:3: note: Taking false branch
2359// CHECK:   if (disk) NSLog(@"ok");
2360// CHECK:   ^
2361// CHECK: 418:3: note: Taking false branch
2362// CHECK:   if (disk) NSLog(@"ok");
2363// CHECK:   ^
2364// CHECK: 421:3: note: Taking false branch
2365// CHECK:   if (dict) NSLog(@"ok"); 
2366// CHECK:   ^
2367// CHECK: 424:3: note: Taking false branch
2368// CHECK:   if (disk) NSLog(@"ok");
2369// CHECK:   ^
2370// CHECK: 426:30: note: Call to function 'DADissenterCreate' returns a Core Foundation object with a +1 retain count
2371// CHECK:   DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault,
2372// CHECK:                              ^
2373// CHECK: 428:7: note: Assuming 'dissenter' is non-null
2374// CHECK:   if (dissenter) NSLog(@"ok");
2375// CHECK:       ^
2376// CHECK: 428:3: note: Taking true branch
2377// CHECK:   if (dissenter) NSLog(@"ok");
2378// CHECK:   ^
2379// CHECK: 428:25: note: Object leaked: object allocated and stored into 'dissenter' is not referenced later in this execution path and has a retain count of +1
2380// CHECK:   if (dissenter) NSLog(@"ok");
2381// CHECK:                         ^
2382// CHECK: 415:3: note: Taking false branch
2383// CHECK:   if (disk) NSLog(@"ok");
2384// CHECK:   ^
2385// CHECK: 418:3: note: Taking false branch
2386// CHECK:   if (disk) NSLog(@"ok");
2387// CHECK:   ^
2388// CHECK: 421:3: note: Taking false branch
2389// CHECK:   if (dict) NSLog(@"ok"); 
2390// CHECK:   ^
2391// CHECK: 424:3: note: Taking false branch
2392// CHECK:   if (disk) NSLog(@"ok");
2393// CHECK:   ^
2394// CHECK: 428:3: note: Taking false branch
2395// CHECK:   if (dissenter) NSLog(@"ok");
2396// CHECK:   ^
2397// CHECK: 430:26: note: Call to function 'DASessionCreate' returns a Core Foundation object with a +1 retain count
2398// CHECK:   DASessionRef session = DASessionCreate(kCFAllocatorDefault);
2399// CHECK:                          ^
2400// CHECK: 431:7: note: Assuming 'session' is non-null
2401// CHECK:   if (session) NSLog(@"ok");
2402// CHECK:       ^
2403// CHECK: 431:3: note: Taking true branch
2404// CHECK:   if (session) NSLog(@"ok");
2405// CHECK:   ^
2406// CHECK: 431:23: note: Object leaked: object allocated and stored into 'session' is not referenced later in this execution path and has a retain count of +1
2407// CHECK:   if (session) NSLog(@"ok");
2408// CHECK:                       ^
2409// CHECK: 415:3: note: Taking false branch
2410// CHECK:   if (disk) NSLog(@"ok");
2411// CHECK:   ^
2412// CHECK: 417:10: note: Call to function 'DADiskCreateFromIOMedia' returns a Core Foundation object with a +1 retain count
2413// CHECK:   disk = DADiskCreateFromIOMedia(kCFAllocatorDefault, 0, media);
2414// CHECK:          ^
2415// CHECK: 418:7: note: Assuming 'disk' is non-null
2416// CHECK:   if (disk) NSLog(@"ok");
2417// CHECK:       ^
2418// CHECK: 418:3: note: Taking true branch
2419// CHECK:   if (disk) NSLog(@"ok");
2420// CHECK:   ^
2421// CHECK: 421:3: note: Taking false branch
2422// CHECK:   if (dict) NSLog(@"ok"); 
2423// CHECK:   ^
2424// CHECK: 424:3: note: Taking false branch
2425// CHECK:   if (disk) NSLog(@"ok");
2426// CHECK:   ^
2427// CHECK: 428:3: note: Taking false branch
2428// CHECK:   if (dissenter) NSLog(@"ok");
2429// CHECK:   ^
2430// CHECK: 431:3: note: Taking false branch
2431// CHECK:   if (session) NSLog(@"ok");
2432// CHECK:   ^
2433// CHECK: 432:1: note: Object leaked: object allocated and stored into 'disk' is not referenced later in this execution path and has a retain count of +1
2434// CHECK: }
2435// CHECK: ^
2436// CHECK: 450:22: note: Call to function 'CFArrayGetValueAtIndex' returns a Core Foundation object with a +0 retain count
2437// CHECK:   s1 = (CFStringRef) CFArrayGetValueAtIndex(A, 0);
2438// CHECK:                      ^
2439// CHECK: 456:3: note: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2440// CHECK:   CFRelease(s1);
2441// CHECK:   ^
2442// CHECK: 464:17: note: Call to function 'MyCreateFun' returns a Core Foundation object with a +1 retain count
2443// CHECK:   CFTypeRef o = MyCreateFun();
2444// CHECK:                 ^
2445// CHECK: 465:1: note: Object leaked: object allocated and stored into 'o' is not referenced later in this execution path and has a retain count of +1
2446// CHECK: }
2447// CHECK: ^
2448// CHECK: 473:25: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2449// CHECK:   CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2450// CHECK:                         ^
2451// CHECK: 474:3: note: Object sent -autorelease message
2452// CHECK:   [(id) A autorelease];
2453// CHECK:   ^
2454// CHECK: 475:3: note: Object sent -autorelease message
2455// CHECK:   [(id) A autorelease];
2456// CHECK:   ^
2457// CHECK: 476:1: note: Object over-autoreleased: object was sent -autorelease 2 times but the object has a +1 retain count
2458// CHECK: }
2459// CHECK: ^
2460// CHECK: 479:25: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2461// CHECK:   CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2462// CHECK:                         ^
2463// CHECK: 480:3: note: Object sent -autorelease message
2464// CHECK:   [(id) A autorelease];
2465// CHECK:   ^
2466// CHECK: 481:3: note: Object sent -autorelease message
2467// CHECK:   [(id) A autorelease]; 
2468// CHECK:   ^
2469// CHECK: 482:3: note: Object over-autoreleased: object was sent -autorelease 2 times but the object has a +0 retain count
2470// CHECK:   return A;
2471// CHECK:   ^
2472// CHECK: 486:25: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2473// CHECK:   CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2474// CHECK:                         ^
2475// CHECK: 487:3: note: Object sent -autorelease message
2476// CHECK:   [(id) A autorelease];
2477// CHECK:   ^
2478// CHECK: 488:3: note: Object sent -autorelease message
2479// CHECK:   [(id) A autorelease]; 
2480// CHECK:   ^
2481// CHECK: 489:25: note: Object over-autoreleased: object was sent -autorelease 2 times but the object has a +1 retain count
2482// CHECK:   CFMutableArrayRef B = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2483// CHECK:                         ^
2484// CHECK: 497:3: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2485// CHECK:   CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2486// CHECK:   ^
2487// CHECK: 498:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2488// CHECK: }
2489// CHECK: ^
2490// CHECK: 512:7: note: Assuming 'p' is null
2491// CHECK:   if (p)
2492// CHECK:       ^
2493// CHECK: 512:7: note: Assuming pointer value is null
2494// CHECK: 512:3: note: Taking false branch
2495// CHECK:   if (p)
2496// CHECK:   ^
2497// CHECK: 515:3: note: Taking true branch
2498// CHECK:   if (x) {
2499// CHECK:   ^
2500// CHECK: 516:5: note: Null pointer argument in call to CFRelease
2501// CHECK:     CFRelease(p);
2502// CHECK:     ^
2503// CHECK: 512:7: note: Assuming 'p' is null
2504// CHECK:   if (p)
2505// CHECK:       ^
2506// CHECK: 512:7: note: Assuming pointer value is null
2507// CHECK: 512:3: note: Taking false branch
2508// CHECK:   if (p)
2509// CHECK:   ^
2510// CHECK: 515:3: note: Taking false branch
2511// CHECK:   if (x) {
2512// CHECK:   ^
2513// CHECK: 519:5: note: Null pointer argument in call to CFRetain
2514// CHECK:     CFRetain(p);
2515// CHECK:     ^
2516// CHECK: 560:17: note: Method returns an Objective-C object with a +0 retain count
2517// CHECK:   NSString *s = [NSString stringWithUTF8String:"hello"];
2518// CHECK:                 ^
2519// CHECK: 561:3: note: Object returned to caller with a +0 retain count
2520// CHECK:   return s;
2521// CHECK:   ^
2522// CHECK: 561:3: note: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected
2523// CHECK: 574:20: note: Method returns an Objective-C object with a +1 retain count
2524// CHECK:   NSString *kind = [[NSString alloc] initWithUTF8String:inkind];
2525// CHECK:                    ^
2526// CHECK: 581:3: note: Taking true branch
2527// CHECK:   if(!name)
2528// CHECK:   ^
2529// CHECK: 582:5: note: Object leaked: object allocated and stored into 'kind' is not referenced later in this execution path and has a retain count of +1
2530// CHECK:     return;
2531// CHECK:     ^
2532// CHECK: 581:3: note: Taking false branch
2533// CHECK:   if(!name)
2534// CHECK:   ^
2535// CHECK: 584:3: note: Variable 'kindC' initialized to a null pointer value
2536// CHECK:   const char *kindC = 0;
2537// CHECK:   ^
2538// CHECK: 592:3: note: Taking false branch
2539// CHECK:   if(kind)
2540// CHECK:   ^
2541// CHECK: 594:3: note: Taking true branch
2542// CHECK:   if(name)
2543// CHECK:   ^
2544// CHECK: 596:13: note: Array access (from variable 'kindC') results in a null pointer dereference
2545// CHECK:   if(!isFoo(kindC[0]))
2546// CHECK:             ^
2547// CHECK: 580:20: note: Method returns an Objective-C object with a +0 retain count
2548// CHECK:   NSString *name = [NSString stringWithUTF8String:inname];
2549// CHECK:                    ^
2550// CHECK: 581:6: note: Assuming 'name' is non-nil
2551// CHECK:   if(!name)
2552// CHECK:      ^
2553// CHECK: 581:3: note: Taking false branch
2554// CHECK:   if(!name)
2555// CHECK:   ^
2556// CHECK: 592:3: note: Taking true branch
2557// CHECK:   if(kind)
2558// CHECK:   ^
2559// CHECK: 594:3: note: Taking true branch
2560// CHECK:   if(name)
2561// CHECK:   ^
2562// CHECK: 596:3: note: Taking false branch
2563// CHECK:   if(!isFoo(kindC[0]))
2564// CHECK:   ^
2565// CHECK: 598:3: note: Taking false branch
2566// CHECK:   if(!isFoo(nameC[0]))
2567// CHECK:   ^
2568// CHECK: 602:3: note: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2569// CHECK:   [name release];
2570// CHECK:   ^
2571// CHECK: 624:12: note: Method returns an Objective-C object with a +1 retain count
2572// CHECK:   id foo = [[NSString alloc] init];
2573// CHECK:            ^
2574// CHECK: 625:3: note: Object released by directly sending the '-dealloc' message
2575// CHECK:   [foo dealloc];
2576// CHECK:   ^
2577// CHECK: 626:3: note: Reference-counted object is used after it is released
2578// CHECK:   [foo release];
2579// CHECK:   ^
2580// CHECK: 633:12: note: Method returns an Objective-C object with a +1 retain count
2581// CHECK:   id foo = [[NSString alloc] init];
2582// CHECK:            ^
2583// CHECK: 634:3: note: Object released
2584// CHECK:   [foo release];
2585// CHECK:   ^
2586// CHECK: 635:3: note: Reference-counted object is used after it is released
2587// CHECK:   [foo dealloc];
2588// CHECK:   ^
2589// CHECK: 687:31: note: Method returns an Objective-C object with a +0 retain count
2590// CHECK:  NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
2591// CHECK:                               ^
2592// CHECK: 687:30: note: Reference count incremented. The object now has a +1 retain count
2593// CHECK:  NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
2594// CHECK:                              ^
2595// CHECK: 692:1: note: Object leaked: object allocated and stored into 'dict' is not referenced later in this execution path and has a retain count of +1
2596// CHECK: }
2597// CHECK: ^
2598// CHECK: 699:31: note: Method returns an Objective-C object with a +0 retain count
2599// CHECK:  NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
2600// CHECK:                               ^
2601// CHECK: 699:30: note: Reference count incremented. The object now has a +1 retain count
2602// CHECK:  NSMutableDictionary *dict = [[NSMutableDictionary dictionaryWithCapacity:4] retain];
2603// CHECK:                              ^
2604// CHECK: 700:2: note: Taking false branch
2605// CHECK:  if (window) 
2606// CHECK:  ^
2607// CHECK: 702:1: note: Object leaked: object allocated and stored into 'dict' is not referenced later in this execution path and has a retain count of +1
2608// CHECK: }
2609// CHECK: ^
2610// CHECK: 711:20: note: Method returns an Objective-C object with a +0 retain count
2611// CHECK:   NSArray *array = [NSArray array];
2612// CHECK:                    ^
2613// CHECK: 712:3: note: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
2614// CHECK:   [array release];
2615// CHECK:   ^
2616// CHECK: 788:3: note: Method returns an Objective-C object with a +1 retain count
2617// CHECK:   [[RDar6320065Subclass alloc] init];
2618// CHECK:   ^
2619// CHECK: 790:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2620// CHECK: }
2621// CHECK: ^
2622// CHECK: 793:10: note: Method returns an Objective-C object with a +1 retain count
2623// CHECK:   self = [[RDar6320065Subclass alloc] init];
2624// CHECK:          ^
2625// CHECK: 794:10: note: Object sent -autorelease message
2626// CHECK:   return [self autorelease];
2627// CHECK:          ^
2628// CHECK: 794:3: note: Object returned to caller with a +0 retain count
2629// CHECK:   return [self autorelease];
2630// CHECK:   ^
2631// CHECK: 794:3: note: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected
2632// CHECK: 832:37: note: Method returns an Objective-C object with a +1 retain count
2633// CHECK: - (NSString*) NoCopyString { return [[NSString alloc] init]; }
2634// CHECK:                                     ^
2635// CHECK: 832:30: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2636// CHECK: - (NSString*) NoCopyString { return [[NSString alloc] init]; }
2637// CHECK:                              ^
2638// CHECK: 832:30: note: Object leaked: allocated object is returned from a method whose name ('NoCopyString') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'.  This violates the naming convention rules given in the Memory Management Guide for Cocoa
2639// CHECK: 833:37: note: Method returns an Objective-C object with a +1 retain count
2640// CHECK: - (NSString*) noCopyString { return [[NSString alloc] init]; }
2641// CHECK:                                     ^
2642// CHECK: 833:30: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2643// CHECK: - (NSString*) noCopyString { return [[NSString alloc] init]; }
2644// CHECK:                              ^
2645// CHECK: 833:30: note: Object leaked: allocated object is returned from a method whose name ('noCopyString') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'.  This violates the naming convention rules given in the Memory Management Guide for Cocoa
2646// CHECK: 837:3: note: Calling 'NoCopyString'
2647// CHECK:   [x NoCopyString];
2648// CHECK:   ^
2649// CHECK: 832:37: note: Method returns an Objective-C object with a +1 retain count
2650// CHECK: - (NSString*) NoCopyString { return [[NSString alloc] init]; }
2651// CHECK:                                     ^
2652// CHECK: 837:3: note: Returning from 'NoCopyString'
2653// CHECK:   [x NoCopyString];
2654// CHECK:   ^
2655// CHECK: 841:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2656// CHECK: }
2657// CHECK: ^
2658// CHECK: 865:10: note: Method returns an Objective-C object with a +1 retain count
2659// CHECK:   return [[NSString alloc] init];
2660// CHECK:          ^
2661// CHECK: 865:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2662// CHECK:   return [[NSString alloc] init];
2663// CHECK:   ^
2664// CHECK: 865:3: note: Object leaked: allocated object is returned from a method whose name (':') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'.  This violates the naming convention rules given in the Memory Management Guide for Cocoa
2665// CHECK: 895:3: note: Method returns an Objective-C object with a +1 retain count
2666// CHECK:   [view createSnapshotImageOfType:str];
2667// CHECK:   ^
2668// CHECK: 899:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2669// CHECK: }
2670// CHECK: ^
2671// CHECK: 907:3: note: Method returns a Core Foundation object with a +1 retain count
2672// CHECK:   [context createCGLayerWithSize:size info:d];
2673// CHECK:   ^
2674// CHECK: 908:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2675// CHECK: }
2676// CHECK: ^
2677// CHECK: 916:3: note: Call to function 'IOBSDNameMatching' returns a Core Foundation object with a +1 retain count
2678// CHECK:   IOBSDNameMatching(masterPort, options, bsdName);
2679// CHECK:   ^
2680// CHECK: 917:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2681// CHECK: }
2682// CHECK: ^
2683// CHECK: 920:3: note: Call to function 'IOServiceMatching' returns a Core Foundation object with a +1 retain count
2684// CHECK:   IOServiceMatching(name);
2685// CHECK:   ^
2686// CHECK: 921:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2687// CHECK: }
2688// CHECK: ^
2689// CHECK: 924:3: note: Call to function 'IOServiceNameMatching' returns a Core Foundation object with a +1 retain count
2690// CHECK:   IOServiceNameMatching(name);
2691// CHECK:   ^
2692// CHECK: 925:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2693// CHECK: }
2694// CHECK: ^
2695// CHECK: 932:30: note: Call to function 'CreateDict' returns a Core Foundation object with a +1 retain count
2696// CHECK:   CFDictionaryRef matching = CreateDict();
2697// CHECK:                              ^
2698// CHECK: 933:3: note: Object released
2699// CHECK:   CFRelease(matching);
2700// CHECK:   ^
2701// CHECK: 934:3: note: Reference-counted object is used after it is released
2702// CHECK:   IOServiceAddNotification(masterPort, notificationType, matching,
2703// CHECK:   ^
2704// CHECK: 939:3: note: Call to function 'IORegistryEntryIDMatching' returns a Core Foundation object with a +1 retain count
2705// CHECK:   IORegistryEntryIDMatching(entryID);
2706// CHECK:   ^
2707// CHECK: 940:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2708// CHECK: }
2709// CHECK: ^
2710// CHECK: 944:3: note: Call to function 'IOOpenFirmwarePathMatching' returns a Core Foundation object with a +1 retain count
2711// CHECK:   IOOpenFirmwarePathMatching(masterPort, options, path);
2712// CHECK:   ^
2713// CHECK: 945:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2714// CHECK: }
2715// CHECK: ^
2716// CHECK: 948:30: note: Call to function 'CreateDict' returns a Core Foundation object with a +1 retain count
2717// CHECK:   CFDictionaryRef matching = CreateDict();
2718// CHECK:                              ^
2719// CHECK: 949:3: note: Object released
2720// CHECK:   IOServiceGetMatchingService(masterPort, matching);
2721// CHECK:   ^
2722// CHECK: 950:3: note: Reference-counted object is used after it is released
2723// CHECK:   CFRelease(matching);
2724// CHECK:   ^
2725// CHECK: 954:30: note: Call to function 'CreateDict' returns a Core Foundation object with a +1 retain count
2726// CHECK:   CFDictionaryRef matching = CreateDict();
2727// CHECK:                              ^
2728// CHECK: 955:3: note: Object released
2729// CHECK:   IOServiceGetMatchingServices(masterPort, matching, existing);
2730// CHECK:   ^
2731// CHECK: 956:3: note: Reference-counted object is used after it is released
2732// CHECK:   CFRelease(matching);
2733// CHECK:   ^
2734// CHECK: 962:30: note: Call to function 'CreateDict' returns a Core Foundation object with a +1 retain count
2735// CHECK:   CFDictionaryRef matching = CreateDict();
2736// CHECK:                              ^
2737// CHECK: 963:3: note: Object released
2738// CHECK:   IOServiceAddMatchingNotification(notifyPort, notificationType, matching, callback, refCon, notification);
2739// CHECK:   ^
2740// CHECK: 964:3: note: Reference-counted object is used after it is released
2741// CHECK:   CFRelease(matching);
2742// CHECK:   ^
2743// CHECK: 1005:22: note: Method returns an Objective-C object with a +1 retain count
2744// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2745// CHECK:                      ^
2746// CHECK: 1007:3: note: Reference count decremented
2747// CHECK:   [number release];
2748// CHECK:   ^
2749// CHECK: 1008:3: note: Reference count incremented. The object now has a +1 retain count
2750// CHECK:   [number retain];
2751// CHECK:   ^
2752// CHECK: 1009:3: note: Object leaked: object allocated and stored into 'number' is not referenced later in this execution path and has a retain count of +1
2753// CHECK:   CFRelease(attrString);  
2754// CHECK:   ^
2755// CHECK: 1030:41: note: Call to function 'CGColorSpaceCreateDeviceRGB' returns a Core Foundation object with a +1 retain count
2756// CHECK:     CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),
2757// CHECK:                                         ^
2758// CHECK: 1029:3: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2759// CHECK:   CGGradientRef myGradient =
2760// CHECK:   ^
2761// CHECK: 1052:40: note: Call to function 'CGColorSpaceCreateDeviceRGB' returns a Core Foundation object with a +1 retain count
2762// CHECK:    CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations);
2763// CHECK:                                        ^
2764// CHECK: 1051:3: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2765// CHECK:   CGGradientRef myGradient =
2766// CHECK:   ^
2767// CHECK: 1052:4: note: Call to function 'CGGradientCreateWithColorComponents' returns a Core Foundation object with a +1 retain count
2768// CHECK:    CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), components, locations, num_locations);
2769// CHECK:    ^
2770// CHECK: 1056:1: note: Object leaked: object allocated and stored into 'myGradient' is not referenced later in this execution path and has a retain count of +1
2771// CHECK: }
2772// CHECK: ^
2773// CHECK: 1090:22: note: Method returns an Objective-C object with a +1 retain count
2774// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2775// CHECK:                      ^
2776// CHECK: 1091:1: note: Object leaked: object allocated and stored into 'number' is not referenced later in this execution path and has a retain count of +1
2777// CHECK: }
2778// CHECK: ^
2779// CHECK: 1225:3: note: Call to function 'CGBitmapContextCreateWithData' returns a Core Foundation object with a +1 retain count
2780// CHECK:   CGBitmapContextCreateWithData(data, width, height, bitsPerComponent,
2781// CHECK:   ^
2782// CHECK: 1227:1: note: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1
2783// CHECK: }
2784// CHECK: ^
2785// CHECK: 1243:10: note: Method returns an Objective-C object with a +1 retain count
2786// CHECK:   id y = [x new_stuff];
2787// CHECK:          ^
2788// CHECK: 1244:1: note: Object leaked: object allocated and stored into 'y' is not referenced later in this execution path and has a retain count of +1
2789// CHECK: }
2790// CHECK: ^
2791// CHECK: 1264:22: note: Method returns an Objective-C object with a +1 retain count
2792// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2793// CHECK:                      ^
2794// CHECK: 1265:1: note: Object leaked: object allocated and stored into 'number' is not referenced later in this execution path and has a retain count of +1
2795// CHECK: }
2796// CHECK: ^
2797// CHECK: 1274:3: note: The 'release' message should be sent to instances of class 'RDar7252064' and not the class directly
2798// CHECK:   [RDar7252064 release];
2799// CHECK:   ^
2800// CHECK: 1275:3: note: The 'retain' message should be sent to instances of class 'RDar7252064' and not the class directly
2801// CHECK:   [RDar7252064 retain];
2802// CHECK:   ^
2803// CHECK: 1276:3: note: The 'autorelease' message should be sent to instances of class 'RDar7252064' and not the class directly
2804// CHECK:   [RDar7252064 autorelease];
2805// CHECK:   ^
2806// CHECK: 1277:3: note: The 'drain' message should be sent to instances of class 'NSAutoreleasePool' and not the class directly
2807// CHECK:   [NSAutoreleasePool drain];
2808// CHECK:   ^
2809// CHECK: 1303:19: note: Method returns an Objective-C object with a +1 retain count
2810// CHECK:   NSString *str = [X returnsAnOwnedString];
2811// CHECK:                   ^
2812// CHECK: 1304:1: note: Object leaked: object allocated and stored into 'str' is not referenced later in this execution path and has a retain count of +1
2813// CHECK: }
2814// CHECK: ^
2815// CHECK: 1307:19: note: Method returns a Core Foundation object with a +1 retain count
2816// CHECK:   NSString *str = [X returnsAnOwnedCFString];
2817// CHECK:                   ^
2818// CHECK: 1308:1: note: Object leaked: object allocated and stored into 'str' is not referenced later in this execution path and has a retain count of +1
2819// CHECK: }
2820// CHECK: ^
2821// CHECK: 1312:20: note: Method returns an Objective-C object with a +1 retain count
2822// CHECK:   NSString *str2 = [X newStringNoAttr];
2823// CHECK:                    ^
2824// CHECK: 1313:1: note: Object leaked: object allocated and stored into 'str2' is not referenced later in this execution path and has a retain count of +1
2825// CHECK: }
2826// CHECK: ^
2827// CHECK: 1316:26: note: Method returns an Objective-C object with a +1 retain count
2828// CHECK:   TestOwnershipAttr *x = [TestOwnershipAttr alloc];
2829// CHECK:                          ^
2830// CHECK: 1317:1: note: Object leaked: object allocated and stored into 'x' is not referenced later in this execution path and has a retain count of +1
2831// CHECK: }
2832// CHECK: ^
2833// CHECK: 1320:26: note: Method returns an Objective-C object with a +1 retain count
2834// CHECK:   TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];
2835// CHECK:                          ^
2836// CHECK: 1321:1: note: Object leaked: object allocated and stored into 'x' is not referenced later in this execution path and has a retain count of +1
2837// CHECK: }
2838// CHECK: ^
2839// CHECK: 1324:26: note: Method returns an Objective-C object with a +1 retain count
2840// CHECK:   TestOwnershipAttr *x = [[TestOwnershipAttr alloc] pseudoInit];// expected-warning{{leak}}
2841// CHECK:                          ^
2842// CHECK: 1326:1: note: Object leaked: object allocated and stored into 'x' is not referenced later in this execution path and has a retain count of +1
2843// CHECK: }
2844// CHECK: ^
2845// CHECK: 1356:10: note: Method returns an Objective-C object with a +1 retain count
2846// CHECK:   return [NSString alloc];
2847// CHECK:          ^
2848// CHECK: 1356:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2849// CHECK:   return [NSString alloc];
2850// CHECK:   ^
2851// CHECK: 1356:3: note: Object leaked: allocated object is returned from a method that is annotated as NS_RETURNS_NOT_RETAINED
2852// CHECK: 1389:26: note: Calling 'returnsCFRetainedAsCF'
2853// CHECK:   return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
2854// CHECK:                          ^
2855// CHECK: 1381:10: note: Calling 'returnsRetainedCFDate'
2856// CHECK:   return returnsRetainedCFDate(); // No leak.
2857// CHECK:          ^
2858// CHECK: 1372:10: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2859// CHECK:   return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
2860// CHECK:          ^
2861// CHECK: 1381:10: note: Returning from 'returnsRetainedCFDate'
2862// CHECK:   return returnsRetainedCFDate(); // No leak.
2863// CHECK:          ^
2864// CHECK: 1389:26: note: Returning from 'returnsCFRetainedAsCF'
2865// CHECK:   return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
2866// CHECK:                          ^
2867// CHECK: 1389:21: note: Object sent -autorelease message
2868// CHECK:   return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
2869// CHECK:                     ^
2870// CHECK: 1389:3: note: Object returned to caller with a +0 retain count
2871// CHECK:   return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
2872// CHECK:   ^
2873// CHECK: 1389:3: note: Object with a +0 retain count returned to caller where a +1 (owning) retain count is expected
2874// CHECK: 1393:20: note: Calling 'returnsRetainedCFDate'
2875// CHECK:   return (NSDate*) returnsRetainedCFDate();
2876// CHECK:                    ^
2877// CHECK: 1372:10: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2878// CHECK:   return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
2879// CHECK:          ^
2880// CHECK: 1393:20: note: Returning from 'returnsRetainedCFDate'
2881// CHECK:   return (NSDate*) returnsRetainedCFDate();
2882// CHECK:                    ^
2883// CHECK: 1393:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2884// CHECK:   return (NSDate*) returnsRetainedCFDate();
2885// CHECK:   ^
2886// CHECK: 1393:3: note: Object leaked: allocated object is returned from a method whose name ('alsoReturnsRetained') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'.  This violates the naming convention rules given in the Memory Management Guide for Cocoa
2887// CHECK: 1397:10: note: Calling 'returnsRetainedCFDate'
2888// CHECK:   return returnsRetainedCFDate();
2889// CHECK:          ^
2890// CHECK: 1372:10: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2891// CHECK:   return CFDateCreate(0, CFAbsoluteTimeGetCurrent());
2892// CHECK:          ^
2893// CHECK: 1397:10: note: Returning from 'returnsRetainedCFDate'
2894// CHECK:   return returnsRetainedCFDate();
2895// CHECK:          ^
2896// CHECK: 1397:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2897// CHECK:   return returnsRetainedCFDate();
2898// CHECK:   ^
2899// CHECK: 1397:3: note: Object leaked: allocated object is returned from a method whose name ('alsoReturnsRetainedAsCF') does not start with 'copy', 'mutableCopy', 'alloc' or 'new'.  This violates the naming convention rules given in the Memory Management Guide for Cocoa
2900// CHECK: 1418:23: note: Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count
2901// CHECK:   CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
2902// CHECK:                       ^
2903// CHECK: 1419:1: note: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1
2904// CHECK: }
2905// CHECK: ^
2906// CHECK: 1429:23: note: Call to function 'CFNumberCreate' returns a Core Foundation object with a +1 retain count
2907// CHECK:   CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &z);
2908// CHECK:                       ^
2909// CHECK: 1430:3: note: Taking false branch
2910// CHECK:   if (x)
2911// CHECK:   ^
2912// CHECK: 1432:1: note: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1
2913// CHECK: }
2914// CHECK: ^
2915// CHECK: 1452:22: note: Method returns an Objective-C object with a +1 retain count
2916// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2917// CHECK:                      ^
2918// CHECK: 1453:3: note: Object leaked: object allocated and stored into 'number' is not referenced later in this execution path and has a retain count of +1
2919// CHECK:   ^{}();
2920// CHECK:   ^
2921// CHECK: 1473:22: note: Method returns an Objective-C object with a +1 retain count
2922// CHECK:   NSNumber *number = [[NSNumber alloc] initWithInt:5];
2923// CHECK:                      ^
2924// CHECK: 1474:3: note: Calling anonymous block
2925// CHECK:   ^(NSObject *o){ [o retain]; }(number);
2926// CHECK:   ^
2927// CHECK: 1474:19: note: Reference count incremented. The object now has a +2 retain count
2928// CHECK:   ^(NSObject *o){ [o retain]; }(number);
2929// CHECK:                   ^
2930// CHECK: 1474:3: note: Returning to caller
2931// CHECK:   ^(NSObject *o){ [o retain]; }(number);
2932// CHECK:   ^
2933// CHECK: 1475:1: note: Object leaked: object allocated and stored into 'number' is not referenced later in this execution path and has a retain count of +2
2934// CHECK: }
2935// CHECK: ^
2936// CHECK: 1528:5: note: Loop condition is true.  Entering loop body
2937// CHECK:     while (error_to_dump != ((void*)0)) {
2938// CHECK:     ^
2939// CHECK: 1531:16: note: Call to function 'CFErrorCopyUserInfo' returns a Core Foundation object with a +1 retain count
2940// CHECK:         info = CFErrorCopyUserInfo(error_to_dump);
2941// CHECK:                ^
2942// CHECK: 1533:13: note: Assuming 'info' is not equal to null
2943// CHECK:         if (info != ((void*)0)) {
2944// CHECK:             ^
2945// CHECK: 1533:9: note: Taking true branch
2946// CHECK:         if (info != ((void*)0)) {
2947// CHECK:         ^
2948// CHECK: 1528:5: note: Loop condition is false. Execution jumps to the end of the function
2949// CHECK:     while (error_to_dump != ((void*)0)) {
2950// CHECK:     ^
2951// CHECK: 1538:1: note: Object leaked: object allocated and stored into 'info' is not referenced later in this execution path and has a retain count of +1
2952// CHECK: }
2953// CHECK: ^
2954// CHECK: 1581:10: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2955// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2956// CHECK:          ^
2957// CHECK: 1581:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2958// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2959// CHECK:   ^
2960// CHECK: 1581:3: note: Object leaked: allocated object is returned from a function whose name ('camelcase_createno') does not contain 'Copy' or 'Create'.  This violates the naming convention rules given in the Memory Management Guide for Core Foundation
2961// CHECK: 1589:10: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2962// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2963// CHECK:          ^
2964// CHECK: 1589:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2965// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2966// CHECK:   ^
2967// CHECK: 1589:3: note: Object leaked: allocated object is returned from a function whose name ('camelcase_copying') does not contain 'Copy' or 'Create'.  This violates the naming convention rules given in the Memory Management Guide for Core Foundation
2968// CHECK: 1610:10: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2969// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2970// CHECK:          ^
2971// CHECK: 1610:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2972// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2973// CHECK:   ^
2974// CHECK: 1610:3: note: Object leaked: allocated object is returned from a function whose name ('camel_creat') does not contain 'Copy' or 'Create'.  This violates the naming convention rules given in the Memory Management Guide for Core Foundation
2975// CHECK: 1622:10: note: Call to function 'CFArrayCreateMutable' returns a Core Foundation object with a +1 retain count
2976// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2977// CHECK:          ^
2978// CHECK: 1622:3: note: Object returned to caller as an owning reference (single retain count transferred to caller)
2979// CHECK:   return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks);
2980// CHECK:   ^
2981// CHECK: 1622:3: note: Object leaked: allocated object is returned from a function whose name ('camel_copymachine') does not contain 'Copy' or 'Create'.  This violates the naming convention rules given in the Memory Management Guide for Core Foundation
2982// CHECK: 1643:24: note: Call to function 'CFDateCreate' returns a Core Foundation object with a +1 retain count
2983// CHECK:   CFTypeRef vals[] = { CFDateCreate(0, t) };
2984// CHECK:                        ^
2985// CHECK: 1644:1: note: Object leaked: object allocated and stored into 'vals' is not referenced later in this execution path and has a retain count of +1
2986// CHECK: }
2987// CHECK: ^
2988// CHECK: 1670:22: note: Method returns an Objective-C object with a +1 retain count
2989// CHECK:   NSString *string = [[NSString alloc] initWithUTF8String:"foo"];
2990// CHECK:                      ^
2991// CHECK: 1671:3: note: Object released
2992// CHECK:   [string release];
2993// CHECK:   ^
2994// CHECK: 1673:27: note: Reference-counted object is used after it is released
2995// CHECK:   NSString *otherString = [string stringByAppendingString:@"bar"];
2996// CHECK:                           ^
2997// CHECK: 1794:22: note: Method returns an Objective-C object with a +1 retain count
2998// CHECK:         NSArray *a = [[NSArray alloc] initWithObjects:o, (void*)0];
2999// CHECK:                      ^
3000// CHECK: 1797:9: note: Object leaked: object allocated and stored into 'a' is not referenced later in this execution path and has a retain count of +1
3001// CHECK:         [o description];
3002// CHECK:         ^
3003// CHECK: 1803:23: note: Method returns an Objective-C object with a +1 retain count
3004// CHECK:         NSArray *a2 = [[NSArray alloc] initWithArray:a1];
3005// CHECK:                       ^
3006// CHECK: 1806:9: note: Object leaked: object allocated and stored into 'a2' is not referenced later in this execution path and has a retain count of +1
3007// CHECK:         [o description];
3008// CHECK:         ^
3009// CHECK: 1811:24: note: NSArray literal is an object with a +0 retain count
3010// CHECK:         NSArray *a3 = [@[o] retain];
3011// CHECK:                        ^
3012// CHECK: 1811:23: note: Reference count incremented. The object now has a +1 retain count
3013// CHECK:         NSArray *a3 = [@[o] retain];
3014// CHECK:                       ^
3015// CHECK: 1814:9: note: Object leaked: object allocated and stored into 'a3' is not referenced later in this execution path and has a retain count of +1
3016// CHECK:         [o description];
3017// CHECK:         ^
3018// CHECK: 1819:22: note: Method returns an Objective-C object with a +1 retain count
3019// CHECK:         NSArray *a = [[NSArray alloc] initWithArray:@[o]];
3020// CHECK:                      ^
3021// CHECK: 1823:9: note: Object leaked: object allocated and stored into 'a' is not referenced later in this execution path and has a retain count of +1
3022// CHECK:         [o description];
3023// CHECK:         ^
3024// CHECK: 1828:28: note: NSDictionary literal is an object with a +0 retain count
3025// CHECK:         NSDictionary *a = [@{o : o} retain];
3026// CHECK:                            ^
3027// CHECK: 1828:27: note: Reference count incremented. The object now has a +1 retain count
3028// CHECK:         NSDictionary *a = [@{o : o} retain];
3029// CHECK:                           ^
3030// CHECK: 1832:9: note: Object leaked: object allocated and stored into 'a' is not referenced later in this execution path and has a retain count of +1
3031// CHECK:         [o description];
3032// CHECK:         ^
3033// CHECK: 1837:15: note: NSNumber literal is an object with a +0 retain count
3034// CHECK:   id value = [@1 retain];
3035// CHECK:               ^
3036// CHECK: 1837:14: note: Reference count incremented. The object now has a +1 retain count
3037// CHECK:   id value = [@1 retain];
3038// CHECK:              ^
3039// CHECK: 1839:1: note: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1
3040// CHECK: }
3041// CHECK: ^
3042// CHECK: 1842:15: note: NSNumber boxed expression produces an object with a +0 retain count
3043// CHECK:   id value = [@(x) retain];
3044// CHECK:               ^
3045// CHECK: 1842:14: note: Reference count incremented. The object now has a +1 retain count
3046// CHECK:   id value = [@(x) retain];
3047// CHECK:              ^
3048// CHECK: 1846:3: note: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1
3049// CHECK:   [value description];
3050// CHECK:   ^
3051// CHECK: 1845:12: note: NSString boxed expression produces an object with a +0 retain count
3052// CHECK:   value = [@(y) retain];
3053// CHECK:            ^
3054// CHECK: 1845:11: note: Reference count incremented. The object now has a +1 retain count
3055// CHECK:   value = [@(y) retain];
3056// CHECK:           ^
3057// CHECK: 1847:1: note: Object leaked: object allocated and stored into 'value' is not referenced later in this execution path and has a retain count of +1
3058// CHECK: }
3059// CHECK: ^
3060// CHECK: 1854:5: note: Taking false branch
3061// CHECK:     if(y > 2)
3062// CHECK:     ^
3063// CHECK: 1857:21: note: Method returns an Objective-C object with a +1 retain count
3064// CHECK:       printString = [[NSString alloc] init];
3065// CHECK:                     ^
3066// CHECK: 1859:5: note: Object released
3067// CHECK:     [printString release];
3068// CHECK:     ^
3069// CHECK: 1860:5: note: Reference-counted object is used after it is released
3070// CHECK:     NSLog(@"Again: %@", printString);
3071// CHECK:     ^
3072// CHECK: 1887:19: note: NSArray literal is an object with a +0 retain count
3073// CHECK:   id unretained = @[]; // +0
3074// CHECK:                   ^
3075// CHECK: 1888:3: note: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
3076// CHECK:   consumeAndStopTracking(unretained, ^{});
3077// CHECK:   ^
3078// CHECK: 1900:19: note: NSArray literal is an object with a +0 retain count
3079// CHECK:   id unretained = @[]; // +0
3080// CHECK:                   ^
3081// CHECK: 1901:3: note: Incorrect decrement of the reference count of an object that is not owned at this point by the caller
3082// CHECK:   CFConsumeAndStopTracking((CFTypeRef)unretained, ^{});
3083// CHECK:   ^
3084// CHECK: 1913:16: note: Call to function 'CreateMyCFType' returns a Core Foundation object with a +1 retain count
3085// CHECK:   MyCFType x = CreateMyCFType();
3086// CHECK:                ^
3087// CHECK: 1914:1: note: Object leaked: object allocated and stored into 'x' is not referenced later in this execution path and has a retain count of +1
3088// CHECK: }
3089// CHECK: ^
3090