blob: 311371399a463bfb24ca707c138bd2bb758d53bf [file] [log] [blame]
Ted Kremenek88739bf2008-06-16 18:46:17 +00001// 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 Kremenekdfc996c2008-06-16 19:51:41 +00009// both svelte and portable to non-Mac platforms.
Ted Kremenek88739bf2008-06-16 18:46:17 +000010//===----------------------------------------------------------------------===//
11
12typedef const void * CFTypeRef;
13typedef const struct __CFAllocator * CFAllocatorRef;
14typedef double CFTimeInterval;
15typedef CFTimeInterval CFAbsoluteTime;
16typedef const struct __CFDate * CFDateRef;
17extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
18typedef signed char BOOL;
19typedef unsigned int NSUInteger;
20typedef struct _NSZone NSZone;
21static __inline__ __attribute__((always_inline)) id NSMakeCollectable(CFTypeRef cf) {}
22@protocol NSObject - (BOOL)isEqual:(id)object; - (oneway void)release; @end
23extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
Ted Kremenek2eff0f92008-11-05 22:17:39 +000024CFTypeRef CFMakeCollectable(CFTypeRef cf);
Ted Kremenek88739bf2008-06-16 18:46:17 +000025
26//===----------------------------------------------------------------------===//
27// Test cases.
28//===----------------------------------------------------------------------===//
29
30CFAbsoluteTime 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 Kremenek2eff0f92008-11-05 22:17:39 +000041CFAbsoluteTime 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