Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 1 | // RUN: clang -analyze -checker-cfref -verify -fobjc-gc-only %s && |
Ted Kremenek | be1fe1e | 2009-02-17 04:27:41 +0000 | [diff] [blame] | 2 | // RUN: clang -analyze -checker-cfref -analyzer-store=region -fobjc-gc-only -verify %s |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 3 | |
| 4 | //===----------------------------------------------------------------------===// |
| 5 | // Header stuff. |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | typedef unsigned int __darwin_natural_t; |
| 8 | typedef unsigned long UInt32; |
| 9 | typedef signed long CFIndex; |
| 10 | typedef const void * CFTypeRef; |
| 11 | typedef const struct __CFString * CFStringRef; |
| 12 | typedef const struct __CFAllocator * CFAllocatorRef; |
| 13 | extern const CFAllocatorRef kCFAllocatorDefault; |
| 14 | extern CFTypeRef CFRetain(CFTypeRef cf); |
| 15 | extern void CFRelease(CFTypeRef cf); |
Ted Kremenek | b2b14d7 | 2009-02-18 22:11:23 +0000 | [diff] [blame^] | 16 | CFTypeRef CFMakeCollectable(CFTypeRef cf); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 17 | typedef struct { |
| 18 | } |
| 19 | CFArrayCallBacks; |
| 20 | extern const CFArrayCallBacks kCFTypeArrayCallBacks; |
| 21 | typedef const struct __CFArray * CFArrayRef; |
| 22 | typedef struct __CFArray * CFMutableArrayRef; |
| 23 | extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks); |
| 24 | extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx); |
| 25 | typedef const struct __CFDictionary * CFDictionaryRef; |
| 26 | typedef UInt32 CFStringEncoding; |
| 27 | enum { |
| 28 | 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 }; |
| 29 | extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding); |
| 30 | typedef double CFTimeInterval; |
| 31 | typedef CFTimeInterval CFAbsoluteTime; |
| 32 | typedef const struct __CFDate * CFDateRef; |
| 33 | extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at); |
| 34 | extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate); |
| 35 | typedef __darwin_natural_t natural_t; |
| 36 | typedef natural_t mach_port_name_t; |
| 37 | typedef mach_port_name_t mach_port_t; |
| 38 | typedef signed char BOOL; |
| 39 | typedef struct _NSZone NSZone; |
| 40 | @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; |
| 41 | @protocol NSObject - (BOOL)isEqual:(id)object; |
| 42 | - (id)retain; |
| 43 | - (oneway void)release; |
| 44 | - (id)autorelease; |
| 45 | @end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone; |
| 46 | @end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; |
| 47 | @end @interface NSObject <NSObject> { |
| 48 | } |
| 49 | @end typedef float CGFloat; |
| 50 | typedef double NSTimeInterval; |
| 51 | @interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate; |
| 52 | @end enum { |
| 53 | NSObjCNoType = 0, NSObjCVoidType = 'v', NSObjCCharType = 'c', NSObjCShortType = 's', NSObjCLongType = 'l', NSObjCLonglongType = 'q', NSObjCFloatType = 'f', NSObjCDoubleType = 'd', NSObjCBoolType = 'B', NSObjCSelectorType = ':', NSObjCObjectType = '@', NSObjCStructType = '{', NSObjCPointerType = '^', NSObjCStringType = '*', NSObjCArrayType = '[', NSObjCUnionType = '(', NSObjCBitfield = 'b' } |
| 54 | __attribute__((deprecated)); |
| 55 | typedef int kern_return_t; |
| 56 | typedef kern_return_t mach_error_t; |
| 57 | typedef mach_port_t io_object_t; |
| 58 | typedef io_object_t io_service_t; |
| 59 | typedef struct __DASession * DASessionRef; |
| 60 | extern DASessionRef DASessionCreate( CFAllocatorRef allocator ); |
| 61 | typedef struct __DADisk * DADiskRef; |
| 62 | extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name ); |
| 63 | extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media ); |
| 64 | extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk ); |
| 65 | extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk ); |
| 66 | @interface NSAppleEventManager : NSObject { |
| 67 | } |
| 68 | @end enum { |
| 69 | 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 }; |
| 70 | typedef mach_error_t DAReturn; |
| 71 | typedef const struct __DADissenter * DADissenterRef; |
| 72 | extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string ); |
| 73 | |
| 74 | //===----------------------------------------------------------------------===// |
| 75 | // Test cases. |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | |
| 78 | void f1() { |
Ted Kremenek | b2b14d7 | 2009-02-18 22:11:23 +0000 | [diff] [blame^] | 79 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 80 | id x = [(id) A autorelease]; |
Ted Kremenek | b2b14d7 | 2009-02-18 22:11:23 +0000 | [diff] [blame^] | 81 | CFRelease((CFMutableArrayRef) x); |
| 82 | } |
| 83 | |
| 84 | void f2() { |
| 85 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}} |
| 86 | id x = [(id) A retain]; |
| 87 | [x release]; |
| 88 | [x release]; |
| 89 | } |
| 90 | |
| 91 | void f3() { |
| 92 | CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}} |
| 93 | CFMakeCollectable(A); |
| 94 | CFRetain(A); |
Ted Kremenek | abf4397 | 2009-01-28 21:44:40 +0000 | [diff] [blame] | 95 | } |