blob: 2b8242f0d019d02aa5291148a9556dd6ec26121e [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// 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
Ted Kremenek6bcd5a02009-12-09 23:29:55 +00005// XFAIL: *
6
7//===----------------------------------------------------------------------===//
8// The following code is reduced using delta-debugging from
9// Foundation.h (Mac OS X).
10//
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//===----------------------------------------------------------------------===//
15
16#ifdef TEST_64
17typedef long long int64_t;
18_Bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue, int64_t __newValue, volatile int64_t *__theValue );
19#define COMPARE_SWAP_BARRIER OSAtomicCompareAndSwap64Barrier
20typedef int64_t intptr_t;
21#else
22typedef int int32_t;
23_Bool OSAtomicCompareAndSwap32Barrier( int32_t __oldValue, int32_t __newValue, volatile int32_t *__theValue );
24#define COMPARE_SWAP_BARRIER OSAtomicCompareAndSwap32Barrier
25typedef int32_t intptr_t;
26#endif
27
28typedef const void * CFTypeRef;
29typedef const struct __CFString * CFStringRef;
30typedef const struct __CFAllocator * CFAllocatorRef;
31extern const CFAllocatorRef kCFAllocatorDefault;
32extern CFTypeRef CFRetain(CFTypeRef cf);
33void CFRelease(CFTypeRef cf);
34typedef const struct __CFDictionary * CFDictionaryRef;
35const void *CFDictionaryGetValue(CFDictionaryRef theDict, const void *key);
36extern CFStringRef CFStringCreateWithFormat(CFAllocatorRef alloc, CFDictionaryRef formatOptions, CFStringRef format, ...);
37typedef signed char BOOL;
38typedef int NSInteger;
39typedef unsigned int NSUInteger;
40@class NSString, Protocol;
41extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
42typedef NSInteger NSComparisonResult;
43typedef struct _NSZone NSZone;
44@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
45@protocol NSObject
46- (BOOL)isEqual:(id)object;
47- (oneway void)release;
48- (id)retain;
49- (id)autorelease;
50@end
51@protocol NSCopying
52- (id)copyWithZone:(NSZone *)zone;
53@end
54@protocol NSMutableCopying
55- (id)mutableCopyWithZone:(NSZone *)zone;
56@end
57@protocol NSCoding
58- (void)encodeWithCoder:(NSCoder *)aCoder;
59@end
60@interface NSObject <NSObject> {}
61- (id)init;
62+ (id)alloc;
63@end
64extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
65typedef struct {} NSFastEnumerationState;
66@protocol NSFastEnumeration
67- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len;
68@end
69@class NSString;
70typedef struct _NSRange {} NSRange;
71@interface NSArray : NSObject <NSCopying, NSMutableCopying, NSCoding, NSFastEnumeration>
72- (NSUInteger)count;
73@end
74@interface NSMutableArray : NSArray
75- (void)addObject:(id)anObject;
76- (id)initWithCapacity:(NSUInteger)numItems;
77@end
78typedef unsigned short unichar;
79@class NSData, NSArray, NSDictionary, NSCharacterSet, NSData, NSURL, NSError, NSLocale;
80typedef 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)));
89@end
90@interface NSSimpleCString : NSString {} @end
91@interface NSConstantString : NSSimpleCString @end
92extern void *_NSConstantStringClassReference;
93
94//===----------------------------------------------------------------------===//
95// Test cases. These should all be merged into NSString.m once these tests
96// stop reporting leaks.
97//===----------------------------------------------------------------------===//
98
99// FIXME: THIS TEST CASE INCORRECTLY REPORTS A LEAK.
100void 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))
103 [s release];
104 else
105 [*old release];
106}
107
108// FIXME: THIS TEST CASE INCORRECTLY REPORTS A LEAK.
109void 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))
112 return;
113 else
114 [*old release];
115}