blob: 231eec9aa69260aabb22c37c8e271704d80684d6 [file] [log] [blame]
Ted Kremenekabf43972009-01-28 21:44:40 +00001// RUN: clang -analyze -checker-cfref -verify -fobjc-gc-only %s &&
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +00002// RUN: clang -analyze -checker-cfref -analyzer-store=region -fobjc-gc-only -verify %s
Ted Kremenekabf43972009-01-28 21:44:40 +00003
4//===----------------------------------------------------------------------===//
5// Header stuff.
6//===----------------------------------------------------------------------===//
7typedef unsigned int __darwin_natural_t;
8typedef unsigned long UInt32;
9typedef signed long CFIndex;
10typedef const void * CFTypeRef;
11typedef const struct __CFString * CFStringRef;
12typedef const struct __CFAllocator * CFAllocatorRef;
13extern const CFAllocatorRef kCFAllocatorDefault;
14extern CFTypeRef CFRetain(CFTypeRef cf);
15extern void CFRelease(CFTypeRef cf);
Ted Kremenekb2b14d72009-02-18 22:11:23 +000016CFTypeRef CFMakeCollectable(CFTypeRef cf);
Ted Kremenekabf43972009-01-28 21:44:40 +000017typedef struct {
18}
19 CFArrayCallBacks;
20extern const CFArrayCallBacks kCFTypeArrayCallBacks;
21typedef const struct __CFArray * CFArrayRef;
22typedef struct __CFArray * CFMutableArrayRef;
23extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks);
24extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
25typedef const struct __CFDictionary * CFDictionaryRef;
26typedef UInt32 CFStringEncoding;
27enum {
28kCFStringEncodingMacRoman = 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 };
29extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
30typedef double CFTimeInterval;
31typedef CFTimeInterval CFAbsoluteTime;
32typedef const struct __CFDate * CFDateRef;
33extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
34extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate);
35typedef __darwin_natural_t natural_t;
36typedef natural_t mach_port_name_t;
37typedef mach_port_name_t mach_port_t;
38typedef signed char BOOL;
39typedef 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;
50typedef double NSTimeInterval;
51@interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate;
52@end enum {
53NSObjCNoType = 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));
55typedef int kern_return_t;
56typedef kern_return_t mach_error_t;
57typedef mach_port_t io_object_t;
58typedef io_object_t io_service_t;
59typedef struct __DASession * DASessionRef;
60extern DASessionRef DASessionCreate( CFAllocatorRef allocator );
61typedef struct __DADisk * DADiskRef;
62extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name );
63extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media );
64extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk );
65extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk );
66@interface NSAppleEventManager : NSObject {
67}
68@end enum {
69kDAReturnSuccess = 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 };
70typedef mach_error_t DAReturn;
71typedef const struct __DADissenter * DADissenterRef;
72extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string );
73
74//===----------------------------------------------------------------------===//
75// Test cases.
76//===----------------------------------------------------------------------===//
77
78void f1() {
Ted Kremenekb2b14d72009-02-18 22:11:23 +000079 CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // no-warning
Ted Kremenekabf43972009-01-28 21:44:40 +000080 id x = [(id) A autorelease];
Ted Kremenekb2b14d72009-02-18 22:11:23 +000081 CFRelease((CFMutableArrayRef) x);
82}
83
84void 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
91void f3() {
92 CFMutableArrayRef A = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{leak}}
93 CFMakeCollectable(A);
94 CFRetain(A);
Ted Kremenekabf43972009-01-28 21:44:40 +000095}