Ted Kremenek | 565e465 | 2010-02-05 02:06:54 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify -fobjc-gc-only -fblocks %s |
| 2 | // RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=region -fobjc-gc-only -fblocks -verify %s |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 3 | |
| 4 | //===----------------------------------------------------------------------===// |
| 5 | // Header stuff. |
| 6 | //===----------------------------------------------------------------------===// |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 7 | |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 8 | typedef unsigned int __darwin_natural_t; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 9 | typedef unsigned long uintptr_t; |
| 10 | typedef unsigned int uint32_t; |
| 11 | typedef unsigned long long uint64_t; |
| 12 | typedef unsigned int UInt32; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 13 | typedef signed long CFIndex; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 14 | typedef struct { |
| 15 | CFIndex location; |
| 16 | CFIndex length; |
| 17 | } CFRange; |
| 18 | static __inline__ __attribute__((always_inline)) CFRange CFRangeMake(CFIndex loc, CFIndex len) { |
| 19 | CFRange range; |
| 20 | range.location = loc; |
| 21 | range.length = len; |
| 22 | return range; |
| 23 | } |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 24 | typedef const void * CFTypeRef; |
| 25 | typedef const struct __CFString * CFStringRef; |
| 26 | typedef const struct __CFAllocator * CFAllocatorRef; |
| 27 | extern const CFAllocatorRef kCFAllocatorDefault; |
| 28 | extern CFTypeRef CFRetain(CFTypeRef cf); |
| 29 | extern void CFRelease(CFTypeRef cf); |
| 30 | typedef struct { |
| 31 | } |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 32 | CFArrayCallBacks; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 33 | extern const CFArrayCallBacks kCFTypeArrayCallBacks; |
| 34 | typedef const struct __CFArray * CFArrayRef; |
| 35 | typedef struct __CFArray * CFMutableArrayRef; |
| 36 | extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks); |
| 37 | extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx); |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 38 | extern void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value); |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 39 | typedef struct { |
| 40 | } |
| 41 | CFDictionaryKeyCallBacks; |
| 42 | extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks; |
| 43 | typedef struct { |
| 44 | } |
| 45 | CFDictionaryValueCallBacks; |
| 46 | extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 47 | typedef const struct __CFDictionary * CFDictionaryRef; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 48 | typedef struct __CFDictionary * CFMutableDictionaryRef; |
| 49 | extern CFMutableDictionaryRef CFDictionaryCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 50 | typedef UInt32 CFStringEncoding; |
| 51 | enum { |
| 52 | kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF , kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100 }; |
| 53 | extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding); |
| 54 | typedef double CFTimeInterval; |
| 55 | typedef CFTimeInterval CFAbsoluteTime; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 56 | extern CFAbsoluteTime CFAbsoluteTimeGetCurrent(void); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 57 | typedef const struct __CFDate * CFDateRef; |
| 58 | extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at); |
| 59 | extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate); |
| 60 | typedef __darwin_natural_t natural_t; |
| 61 | typedef natural_t mach_port_name_t; |
| 62 | typedef mach_port_name_t mach_port_t; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 63 | typedef int kern_return_t; |
| 64 | typedef kern_return_t mach_error_t; |
| 65 | enum { |
| 66 | kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 }; |
| 67 | typedef CFIndex CFNumberType; |
| 68 | typedef const struct __CFNumber * CFNumberRef; |
| 69 | extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr); |
| 70 | typedef const struct __CFAttributedString *CFAttributedStringRef; |
| 71 | typedef struct __CFAttributedString *CFMutableAttributedStringRef; |
| 72 | extern CFAttributedStringRef CFAttributedStringCreate(CFAllocatorRef alloc, CFStringRef str, CFDictionaryRef attributes) ; |
| 73 | extern CFMutableAttributedStringRef CFAttributedStringCreateMutableCopy(CFAllocatorRef alloc, CFIndex maxLength, CFAttributedStringRef aStr) ; |
| 74 | extern void CFAttributedStringSetAttribute(CFMutableAttributedStringRef aStr, CFRange range, CFStringRef attrName, CFTypeRef value) ; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 75 | typedef signed char BOOL; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 76 | typedef unsigned long NSUInteger; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 77 | @class NSString, Protocol; |
| 78 | extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2))); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 79 | typedef struct _NSZone NSZone; |
| 80 | @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 81 | @protocol NSObject |
| 82 | - (BOOL)isEqual:(id)object; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 83 | - (id)retain; |
| 84 | - (oneway void)release; |
| 85 | - (id)autorelease; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 86 | - (Class)class; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 87 | @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 88 | @end @protocol NSMutableCopying - (id)mutableCopyWithZone:(NSZone *)zone; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 89 | @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 90 | @end |
| 91 | @interface NSObject <NSObject> {} |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 92 | + (id)allocWithZone:(NSZone *)zone; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 93 | + (id)alloc; |
| 94 | - (void)dealloc; |
Ted Kremenek | 54cb7cc | 2009-11-03 08:03:59 +0000 | [diff] [blame] | 95 | - (void)release; |
Ted Kremenek | 7f50c17 | 2009-11-20 01:20:12 +0000 | [diff] [blame] | 96 | - (id)copy; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 97 | @end |
| 98 | @interface NSObject (NSCoderMethods) |
| 99 | - (id)awakeAfterUsingCoder:(NSCoder *)aDecoder; |
| 100 | @end |
| 101 | extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); |
| 102 | typedef struct { |
| 103 | } |
| 104 | NSFastEnumerationState; |
| 105 | @protocol NSFastEnumeration - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len; |
| 106 | @end @class NSString, NSDictionary; |
| 107 | @interface NSValue : NSObject <NSCopying, NSCoding> - (void)getValue:(void *)value; |
| 108 | @end @interface NSNumber : NSValue - (char)charValue; |
| 109 | - (id)initWithInt:(int)value; |
| 110 | @end @class NSString; |
| 111 | @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count; |
| 112 | @end @interface NSArray (NSArrayCreation) + (id)array; |
| 113 | @end @interface NSAutoreleasePool : NSObject { |
| 114 | } |
| 115 | - (void)drain; |
| 116 | @end extern NSString * const NSBundleDidLoadNotification; |
| 117 | typedef double NSTimeInterval; |
| 118 | @interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate; |
| 119 | @end typedef unsigned short unichar; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 120 | @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 121 | - ( const char *)UTF8String; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 122 | - (id)initWithUTF8String:(const char *)nullTerminatedCString; |
| 123 | + (id)stringWithUTF8String:(const char *)nullTerminatedCString; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 124 | @end @class NSString, NSURL, NSError; |
| 125 | @interface NSData : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length; |
| 126 | + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length; |
| 127 | + (id)dataWithBytesNoCopy:(void *)bytes length:(NSUInteger)length freeWhenDone:(BOOL)b; |
| 128 | @end @class NSLocale, NSDate, NSCalendar, NSTimeZone, NSError, NSArray, NSMutableDictionary; |
| 129 | @interface NSDictionary : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration> - (NSUInteger)count; |
| 130 | @end @interface NSMutableDictionary : NSDictionary - (void)removeObjectForKey:(id)aKey; |
| 131 | - (void)setObject:(id)anObject forKey:(id)aKey; |
| 132 | @end @interface NSMutableDictionary (NSMutableDictionaryCreation) + (id)dictionaryWithCapacity:(NSUInteger)numItems; |
| 133 | @end typedef double CGFloat; |
| 134 | struct CGSize { |
| 135 | }; |
| 136 | typedef struct CGSize CGSize; |
| 137 | struct CGRect { |
| 138 | }; |
| 139 | typedef struct CGRect CGRect; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 140 | typedef mach_port_t io_object_t; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 141 | typedef char io_name_t[128]; |
| 142 | typedef io_object_t io_iterator_t; |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 143 | typedef io_object_t io_service_t; |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 144 | typedef struct IONotificationPort * IONotificationPortRef; |
| 145 | typedef void (*IOServiceMatchingCallback)( void * refcon, io_iterator_t iterator ); |
| 146 | io_service_t IOServiceGetMatchingService( mach_port_t masterPort, CFDictionaryRef matching ); |
| 147 | kern_return_t IOServiceGetMatchingServices( mach_port_t masterPort, CFDictionaryRef matching, io_iterator_t * existing ); |
| 148 | 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)); |
| 149 | kern_return_t IOServiceAddMatchingNotification( IONotificationPortRef notifyPort, const io_name_t notificationType, CFDictionaryRef matching, IOServiceMatchingCallback callback, void * refCon, io_iterator_t * notification ); |
| 150 | CFMutableDictionaryRef IOServiceMatching( const char * name ); |
| 151 | CFMutableDictionaryRef IOServiceNameMatching( const char * name ); |
| 152 | CFMutableDictionaryRef IOBSDNameMatching( mach_port_t masterPort, uint32_t options, const char * bsdName ); |
| 153 | CFMutableDictionaryRef IOOpenFirmwarePathMatching( mach_port_t masterPort, uint32_t options, const char * path ); |
| 154 | CFMutableDictionaryRef IORegistryEntryIDMatching( uint64_t entryID ); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 155 | typedef struct __DASession * DASessionRef; |
| 156 | extern DASessionRef DASessionCreate( CFAllocatorRef allocator ); |
| 157 | typedef struct __DADisk * DADiskRef; |
| 158 | extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name ); |
| 159 | extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media ); |
| 160 | extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk ); |
| 161 | extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk ); |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 162 | @interface NSTask : NSObject - (id)init; |
| 163 | @end typedef struct CGColorSpace *CGColorSpaceRef; |
| 164 | typedef struct CGImage *CGImageRef; |
| 165 | typedef struct CGLayer *CGLayerRef; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 166 | @interface NSResponder : NSObject <NSCoding> { |
| 167 | } |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 168 | @end @protocol NSAnimatablePropertyContainer - (id)animator; |
| 169 | @end extern NSString *NSAnimationTriggerOrderIn ; |
| 170 | @interface NSView : NSResponder <NSAnimatablePropertyContainer> { |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 171 | } |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 172 | @end @protocol NSValidatedUserInterfaceItem - (SEL)action; |
| 173 | @end @protocol NSUserInterfaceValidations - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem; |
| 174 | @end @class NSDate, NSDictionary, NSError, NSException, NSNotification; |
| 175 | @interface NSApplication : NSResponder <NSUserInterfaceValidations> { |
| 176 | } |
| 177 | @end enum { |
| 178 | NSTerminateCancel = 0, NSTerminateNow = 1, NSTerminateLater = 2 }; |
| 179 | typedef NSUInteger NSApplicationTerminateReply; |
| 180 | @protocol NSApplicationDelegate <NSObject> @optional - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; |
| 181 | @end @class NSAttributedString, NSEvent, NSFont, NSFormatter, NSImage, NSMenu, NSText, NSView, NSTextView; |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 182 | @interface NSCell : NSObject <NSCopying, NSCoding> { |
| 183 | } |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 184 | @end @class NSTextField, NSPanel, NSArray, NSWindow, NSImage, NSButton, NSError; |
| 185 | typedef struct { |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 186 | } |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 187 | CVTimeStamp; |
| 188 | @interface CIImage : NSObject <NSCoding, NSCopying> { |
| 189 | } |
| 190 | typedef int CIFormat; |
| 191 | @end enum { |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 192 | kDAReturnSuccess = 0, kDAReturnError = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x01, kDAReturnBusy = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x02, kDAReturnBadArgument = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x03, kDAReturnExclusiveAccess = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x04, kDAReturnNoResources = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x05, kDAReturnNotFound = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x06, kDAReturnNotMounted = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x07, kDAReturnNotPermitted = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x08, kDAReturnNotPrivileged = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x09, kDAReturnNotReady = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0A, kDAReturnNotWritable = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0B, kDAReturnUnsupported = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0C }; |
| 193 | typedef mach_error_t DAReturn; |
| 194 | typedef const struct __DADissenter * DADissenterRef; |
| 195 | extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string ); |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 196 | @interface CIContext: NSObject { |
| 197 | } |
| 198 | - (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r; |
| 199 | - (CGImageRef)createCGImage:(CIImage *)im fromRect:(CGRect)r format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs; |
| 200 | - (CGLayerRef)createCGLayerWithSize:(CGSize)size info:(CFDictionaryRef)d; |
| 201 | @end extern NSString* const QCRendererEventKey; |
| 202 | @protocol QCCompositionRenderer - (NSDictionary*) attributes; |
| 203 | @end @interface QCRenderer : NSObject <QCCompositionRenderer> { |
| 204 | } |
| 205 | - (id) createSnapshotImageOfType:(NSString*)type; |
| 206 | @end extern NSString* const QCViewDidStartRenderingNotification; |
| 207 | @interface QCView : NSView <QCCompositionRenderer> { |
| 208 | } |
| 209 | - (id) createSnapshotImageOfType:(NSString*)type; |
| 210 | @end enum { |
| 211 | ICEXIFOrientation1 = 1, ICEXIFOrientation2 = 2, ICEXIFOrientation3 = 3, ICEXIFOrientation4 = 4, ICEXIFOrientation5 = 5, ICEXIFOrientation6 = 6, ICEXIFOrientation7 = 7, ICEXIFOrientation8 = 8, }; |
| 212 | @class ICDevice; |
| 213 | @protocol ICDeviceDelegate <NSObject> @required - (void)didRemoveDevice:(ICDevice*)device; |
| 214 | @end extern NSString *const ICScannerStatusWarmingUp; |
| 215 | @class ICScannerDevice; |
| 216 | @protocol ICScannerDeviceDelegate <ICDeviceDelegate> @optional - (void)scannerDeviceDidBecomeAvailable:(ICScannerDevice*)scanner; |
| 217 | @end |
Ted Kremenek | e798e7c | 2009-04-27 19:14:45 +0000 | [diff] [blame] | 218 | CFTypeRef CFMakeCollectable(CFTypeRef cf) ; |
| 219 | |
Ted Kremenek | 56db7e8 | 2009-06-03 19:19:06 +0000 | [diff] [blame] | 220 | static __inline__ __attribute__((always_inline)) id NSMakeCollectable(CFTypeRef |
| 221 | cf) { |
| 222 | return cf ? (id)CFMakeCollectable(cf) : ((void*)0); |
| 223 | } |
| 224 | |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 225 | //===----------------------------------------------------------------------===// |
| 226 | // Test cases. |
| 227 | //===----------------------------------------------------------------------===// |
| 228 | |
| 229 | void f1() { |
Ted Kremenek | b2b14d7 | 2009-02-18 22:11:23 +0000 | [diff] [blame] | 230 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 231 | id x = [(id) A autorelease]; |
Ted Kremenek | b2b14d7 | 2009-02-18 22:11:23 +0000 | [diff] [blame] | 232 | CFRelease((CFMutableArrayRef) x); |
| 233 | } |
| 234 | |
| 235 | void f2() { |
| 236 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}} |
| 237 | id x = [(id) A retain]; |
| 238 | [x release]; |
| 239 | [x release]; |
| 240 | } |
| 241 | |
| 242 | void f3() { |
| 243 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}} |
| 244 | CFMakeCollectable(A); |
| 245 | CFRetain(A); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 246 | } |
Ted Kremenek | 4064de9 | 2009-04-27 18:27:22 +0000 | [diff] [blame] | 247 | |
Ted Kremenek | 56db7e8 | 2009-06-03 19:19:06 +0000 | [diff] [blame] | 248 | void f3b() { |
| 249 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning |
| 250 | CFMakeCollectable(A); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void f4() { |
| 255 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}} |
| 256 | NSMakeCollectable(A); |
| 257 | CFRetain(A); |
| 258 | } |
| 259 | |
| 260 | void f4b() { |
| 261 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning |
| 262 | NSMakeCollectable(A); |
| 263 | } |
| 264 | |
| 265 | void f5() { |
| 266 | id x = [NSMakeCollectable(CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks)) autorelease]; // no-warning |
| 267 | } |
| 268 | |
| 269 | void f5b() { |
| 270 | id x = [(id) CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks) autorelease]; // expected-warning{{leak}} |
| 271 | } |
| 272 | |
Ted Kremenek | e8720ce | 2009-05-10 06:25:57 +0000 | [diff] [blame] | 273 | // Test return of non-owned objects in contexts where an owned object |
| 274 | // is expected. |
| 275 | @interface TestReturnNotOwnedWhenExpectedOwned |
| 276 | - (NSString*)newString; |
Ted Kremenek | 82f2be5 | 2009-05-10 16:52:15 +0000 | [diff] [blame] | 277 | - (CFMutableArrayRef)newArray; |
Ted Kremenek | e8720ce | 2009-05-10 06:25:57 +0000 | [diff] [blame] | 278 | @end |
| 279 | |
| 280 | @implementation TestReturnNotOwnedWhenExpectedOwned |
| 281 | - (NSString*)newString { |
Ted Kremenek | 56db7e8 | 2009-06-03 19:19:06 +0000 | [diff] [blame] | 282 | NSString *s = [NSString stringWithUTF8String:"hello"]; // expected-warning{{Potential leak (when using garbage collection) of an object allocated}} |
Ted Kremenek | 82f2be5 | 2009-05-10 16:52:15 +0000 | [diff] [blame] | 283 | CFRetain(s); |
| 284 | return s; |
| 285 | } |
| 286 | - (CFMutableArrayRef)newArray{ |
| 287 | return CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning |
Ted Kremenek | e8720ce | 2009-05-10 06:25:57 +0000 | [diff] [blame] | 288 | } |
| 289 | @end |
| 290 | |
Ted Kremenek | 8c6096e | 2009-05-09 03:10:32 +0000 | [diff] [blame] | 291 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 547d495 | 2009-06-05 23:18:01 +0000 | [diff] [blame] | 292 | // <rdar://problem/6948053> False positive: object substitution during -init* |
| 293 | // methods warns about returning +0 when using -fobjc-gc-only |
| 294 | //===----------------------------------------------------------------------===// |
| 295 | |
| 296 | @interface MyClassRdar6948053 : NSObject |
| 297 | - (id) init; |
| 298 | + (id) shared; |
| 299 | @end |
| 300 | |
| 301 | @implementation MyClassRdar6948053 |
| 302 | +(id) shared { |
| 303 | return (id) 0; |
| 304 | } |
| 305 | - (id) init |
| 306 | { |
| 307 | Class myClass = [self class]; |
| 308 | [self release]; |
| 309 | return [[myClass shared] retain]; // no-warning |
| 310 | } |
| 311 | @end |
| 312 | |
| 313 | //===----------------------------------------------------------------------===// |
Ted Kremenek | a834fb4 | 2009-08-28 19:52:12 +0000 | [diff] [blame] | 314 | // <rdar://problem/7174400> 'ciContext createCGImage:outputImage fromRect:' returns a retained CF object (not GC'ed)//===----------------------------------------------------------------------===// |
| 315 | //===----------------------------------------------------------------------===// |
| 316 | |
| 317 | void rdar_7174400(QCView *view, QCRenderer *renderer, CIContext *context, |
| 318 | NSString *str, CIImage *img, CGRect rect, |
| 319 | CIFormat form, CGColorSpaceRef cs) { |
| 320 | [view createSnapshotImageOfType:str]; // no-warning |
| 321 | [renderer createSnapshotImageOfType:str]; // no-warning |
| 322 | [context createCGImage:img fromRect:rect]; // expected-warning{{leak}} |
| 323 | [context createCGImage:img fromRect:rect format:form colorSpace:cs]; // expected-warning{{leak}} |
| 324 | } |
| 325 | |
| 326 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 54cb7cc | 2009-11-03 08:03:59 +0000 | [diff] [blame] | 327 | // <rdar://problem/6250216> Warn against using -[NSAutoreleasePool release] in |
| 328 | // GC mode |
| 329 | //===----------------------------------------------------------------------===// |
| 330 | |
| 331 | void rdar_6250216(void) { |
| 332 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
| 333 | [pool release]; // expected-warning{{Use -drain instead of -release when using NSAutoreleasePool and garbage collection}} |
| 334 | } |
| 335 | |
Ted Kremenek | 71a5e28 | 2009-11-20 00:12:36 +0000 | [diff] [blame] | 336 | |
| 337 | //===----------------------------------------------------------------------===// |
| 338 | // <rdar://problem/7407273> Don't crash when analyzing messages sent to blocks |
| 339 | //===----------------------------------------------------------------------===// |
| 340 | |
| 341 | @class RDar7407273; |
| 342 | typedef void (^RDar7407273Block)(RDar7407273 *operation); |
| 343 | void rdar7407273(RDar7407273Block b) { |
| 344 | [b copy]; |
| 345 | } |
| 346 | |
Ted Kremenek | 54cb7cc | 2009-11-03 08:03:59 +0000 | [diff] [blame] | 347 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 8c6096e | 2009-05-09 03:10:32 +0000 | [diff] [blame] | 348 | // Tests of ownership attributes. |
| 349 | //===----------------------------------------------------------------------===// |
| 350 | |
| 351 | @interface TestOwnershipAttr : NSObject |
| 352 | - (NSString*) returnsAnOwnedString __attribute__((ns_returns_retained)); |
| 353 | - (NSString*) returnsAnOwnedCFString __attribute__((cf_returns_retained)); |
| 354 | @end |
| 355 | |
| 356 | void test_attr_1(TestOwnershipAttr *X) { |
| 357 | NSString *str = [X returnsAnOwnedString]; // no-warning |
| 358 | } |
| 359 | |
| 360 | void test_attr_1b(TestOwnershipAttr *X) { |
| 361 | NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}} |
| 362 | } |
| 363 | |
Ted Kremenek | b9d8db8 | 2009-06-05 23:00:33 +0000 | [diff] [blame] | 364 | @interface MyClassTestCFAttr : NSObject {} |
| 365 | - (NSDate*) returnsCFRetained __attribute__((cf_returns_retained)); |
| 366 | - (NSDate*) alsoReturnsRetained; |
| 367 | - (NSDate*) returnsNSRetained __attribute__((ns_returns_retained)); |
| 368 | @end |
| 369 | |
| 370 | __attribute__((cf_returns_retained)) |
| 371 | CFDateRef returnsRetainedCFDate() { |
| 372 | return CFDateCreate(0, CFAbsoluteTimeGetCurrent()); |
| 373 | } |
| 374 | |
| 375 | @implementation MyClassTestCFAttr |
| 376 | - (NSDate*) returnsCFRetained { |
| 377 | return (NSDate*) returnsRetainedCFDate(); // No leak. |
| 378 | } |
| 379 | |
| 380 | - (NSDate*) alsoReturnsRetained { |
| 381 | return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} |
| 382 | } |
| 383 | |
| 384 | - (NSDate*) returnsNSRetained { |
| 385 | return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}} |
| 386 | } |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 387 | @end |