CFDateGC.m revision 2eff0f9e4fe5b7e130dae5edd51cbadad4b348e1
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 9// both svelte and portable to non-Mac platforms. 10//===----------------------------------------------------------------------===// 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); 24CFTypeRef CFMakeCollectable(CFTypeRef cf); 25 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 41CFAbsoluteTime 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 53