Ted Kremenek | 88739bf | 2008-06-16 18:46:17 +0000 | [diff] [blame] | 1 | // RUN: clang -checker-cfref -verify -fobjc-gc %s |
| 2 | |
| 3 | //===----------------------------------------------------------------------===// |
| 4 | // The following code is reduced using delta-debugging from |
| 5 | // Foundation.h and CoreFoundation.h (Mac OS X). |
| 6 | // |
| 7 | // It includes the basic definitions for the test cases below. |
| 8 | // Not directly including [Core]Foundation.h directly makes this test case |
Ted Kremenek | dfc996c | 2008-06-16 19:51:41 +0000 | [diff] [blame] | 9 | // both svelte and portable to non-Mac platforms. |
Ted Kremenek | 88739bf | 2008-06-16 18:46:17 +0000 | [diff] [blame] | 10 | //===----------------------------------------------------------------------===// |
| 11 | |
| 12 | typedef const void * CFTypeRef; |
| 13 | typedef const struct __CFAllocator * CFAllocatorRef; |
| 14 | typedef double CFTimeInterval; |
| 15 | typedef CFTimeInterval CFAbsoluteTime; |
| 16 | typedef const struct __CFDate * CFDateRef; |
| 17 | extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at); |
| 18 | typedef signed char BOOL; |
| 19 | typedef unsigned int NSUInteger; |
| 20 | typedef struct _NSZone NSZone; |
| 21 | static __inline__ __attribute__((always_inline)) id NSMakeCollectable(CFTypeRef cf) {} |
| 22 | @protocol NSObject - (BOOL)isEqual:(id)object; - (oneway void)release; @end |
| 23 | extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); |
Ted Kremenek | 2eff0f9 | 2008-11-05 22:17:39 +0000 | [diff] [blame] | 24 | CFTypeRef CFMakeCollectable(CFTypeRef cf); |
Ted Kremenek | 88739bf | 2008-06-16 18:46:17 +0000 | [diff] [blame] | 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // Test cases. |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
| 30 | CFAbsoluteTime f1() { |
| 31 | CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); |
| 32 | CFDateRef date = CFDateCreate(0, t); |
| 33 | CFRetain(date); |
| 34 | [NSMakeCollectable(date) release]; |
| 35 | CFDateGetAbsoluteTime(date); // no-warning |
| 36 | CFRelease(date); |
| 37 | t = CFDateGetAbsoluteTime(date); // expected-warning{{Reference-counted object is used after it is released.}} |
| 38 | return t; |
| 39 | } |
| 40 | |
Ted Kremenek | 2eff0f9 | 2008-11-05 22:17:39 +0000 | [diff] [blame] | 41 | CFAbsoluteTime f1b() { |
| 42 | CFAbsoluteTime t = CFAbsoluteTimeGetCurrent(); |
| 43 | CFDateRef date = CFDateCreate(0, t); |
| 44 | CFRetain(date); |
| 45 | [(id) CFMakeCollectable(date) release]; |
| 46 | CFDateGetAbsoluteTime(date); // no-warning |
| 47 | t = CFDateGetAbsoluteTime(date); // no-warning |
| 48 | CFRelease(date); // no-warning |
| 49 | return t; |
| 50 | } |
| 51 | |
| 52 | |