| Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 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 |
| Ted Kremenek | 6bcd5a0 | 2009-12-09 23:29:55 +0000 | [diff] [blame] | 5 | // 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 |
| 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; |
| 21 | #else |
| 22 | typedef int int32_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; |
| 26 | #endif |
| 27 | |
| 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; |
| 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 |
| 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; |
| 68 | @end |
| 69 | @class NSString; |
| 70 | typedef 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 |
| 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))); |
| 89 | @end |
| 90 | @interface NSSimpleCString : NSString {} @end |
| 91 | @interface NSConstantString : NSSimpleCString @end |
| 92 | extern 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. |
| 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)) |
| 103 | [s release]; |
| 104 | else |
| 105 | [*old release]; |
| 106 | } |
| 107 | |
| 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)) |
| 112 | return; |
| 113 | else |
| 114 | [*old release]; |
| 115 | } |