1 // RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s
2 // RUN: %clang_cc1 -triple i386-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
3 // RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=basic -verify %s
4 // RUN: %clang_cc1 -DTEST_64 -triple x86_64-apple-darwin10 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
7 //===----------------------------------------------------------------------===//
8 // The following code is reduced using delta-debugging from
9 // Foundation.h (Mac OS X).
11 // It includes the basic definitions for the test cases below.
12 // Not directly including Foundation.h directly makes this test case
13 // both svelte and portable to non-Mac platforms.
14 //===----------------------------------------------------------------------===//
17 typedef long long int64_t;
18 _Bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue );
19 #define COMPARE_SWAP_BARRIER OSAtomicCompareAndSwap64Barrier
20 typedef int64_t intptr_t;
23 _Bool OSAtomicCompareAndSwap32Barrier( int32_t __oldValue, int32_t __newValue, volatile int32_t *__theValue );
24 #define COMPARE_SWAP_BARRIER OSAtomicCompareAndSwap32Barrier
25 typedef int32_t intptr_t;
28 typedef const void * CFTypeRef;
29 typedef const struct __CFString * CFStringRef;
30 typedef const struct __CFAllocator * CFAllocatorRef;
31 extern const CFAllocatorRef kCFAllocatorDefault;
32 extern CFTypeRef CFRetain(CFTypeRef cf);
33 void CFRelease(CFTypeRef cf);
34 typedef const struct __CFDictionary * CFDictionaryRef;
35 const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key);
36 extern CFStringRef CFStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, ...);
37 typedef signed char BOOL;
38 typedef int NSInteger;
39 typedef unsigned int NSUInteger;
40 @class NSString, Protocol;
41 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
42 typedef NSInteger NSComparisonResult;
43 typedef struct _NSZone NSZone;
44 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
46 - (BOOL)isEqual:(id)object;
47 - (oneway void)release;
52 - (id)copyWithZone:(NSZone *)zone;
54 @protocol NSMutableCopying
55 - (id)mutableCopyWithZone:(NSZone *)zone;
58 - (void)encodeWithCoder:(NSCoder *)aCoder;
60 @interface NSObject <NSObject> {}
64 extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
65 typedef struct {} NSFastEnumerationState;
66 @protocol NSFastEnumeration
67 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
70 typedef struct _NSRange {} NSRange;
71 @interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
74 @interface NSMutableArray : NSArray
75 - (void)addObject:(id)anObject;
76 - (id)initWithCapacity:(NSUInteger)numItems;
78 typedef unsigned short unichar;
79 @class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale;
80 typedef NSUInteger NSStringCompareOptions;
81 @interface NSString : NSObject <NSCopying, NSMutableCopying, NSCoding> - (NSUInteger)length;
82 - (NSComparisonResult)compare:(NSString *)string;
83 - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask;
84 - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange;
85 - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)compareRange locale:(id)locale;
86 - (NSComparisonResult)caseInsensitiveCompare:(NSString *)string;
87 - (NSArray *)componentsSeparatedByCharactersInSet:(NSCharacterSet *)separator;
88 + (id)stringWithFormat:(NSString *)format, ... __attribute__((format(__NSString__, 1, 2)));
90 @interface NSSimpleCString : NSString {} @end
91 @interface NSConstantString : NSSimpleCString @end
92 extern void *_NSConstantStringClassReference;
94 //===----------------------------------------------------------------------===//
95 // Test cases. These should all be merged into NSString.m once these tests
96 // stop reporting leaks.
97 //===----------------------------------------------------------------------===//
99 // FIXME: THIS TEST CASE INCORRECTLY REPORTS A LEAK.
100 void testOSCompareAndSwapXXBarrier_parameter(NSString **old) {
101 NSString *s = [[NSString alloc] init]; // no-warning
102 if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) old))
108 // FIXME: THIS TEST CASE INCORRECTLY REPORTS A LEAK.
109 void testOSCompareAndSwapXXBarrier_parameter_no_direct_release(NSString **old) {
110 NSString *s = [[NSString alloc] init]; // no-warning
111 if (!COMPARE_SWAP_BARRIER((intptr_t) 0, (intptr_t) s, (intptr_t*) old))