blob: 751dca0ce30b4c0b518e566877b142c72639d5c6 [file] [log] [blame]
Ted Kremenek565e4652010-02-05 02:06:54 +00001// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem -analyzer-store=basic -verify %s
Ted Kremenek0964a062009-01-21 06:57:53 +00002
3//===----------------------------------------------------------------------===//
4// The following code is reduced using delta-debugging from
5// Foundation.h (Mac OS X).
6//
7// It includes the basic definitions for the test cases below.
8// Not including Foundation.h directly makes this test case both svelte and
9// portable to non-Mac platforms.
10//===----------------------------------------------------------------------===//
11
12typedef unsigned int __darwin_natural_t;
13typedef unsigned long UInt32;
14typedef signed long CFIndex;
15typedef const void * CFTypeRef;
16typedef const struct __CFString * CFStringRef;
17typedef const struct __CFAllocator * CFAllocatorRef;
18extern const CFAllocatorRef kCFAllocatorDefault;
19extern CFTypeRef CFRetain(CFTypeRef cf);
20extern void CFRelease(CFTypeRef cf);
21typedef struct {
22}
23CFArrayCallBacks;
24extern const CFArrayCallBacks kCFTypeArrayCallBacks;
25typedef const struct __CFArray * CFArrayRef;
26typedef struct __CFArray * CFMutableArrayRef;
27extern CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks *callBacks);
28extern const void *CFArrayGetValueAtIndex(CFArrayRef theArray, CFIndex idx);
29typedef const struct __CFDictionary * CFDictionaryRef;
30typedef UInt32 CFStringEncoding;
31enum {
32kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, kCFStringEncodingISOLatin1 = 0x0201, kCFStringEncodingNextStepLatin = 0x0B01, kCFStringEncodingASCII = 0x0600, kCFStringEncodingUnicode = 0x0100, kCFStringEncodingUTF8 = 0x08000100, kCFStringEncodingNonLossyASCII = 0x0BFF , kCFStringEncodingUTF16 = 0x0100, kCFStringEncodingUTF16BE = 0x10000100, kCFStringEncodingUTF16LE = 0x14000100, kCFStringEncodingUTF32 = 0x0c000100, kCFStringEncodingUTF32BE = 0x18000100, kCFStringEncodingUTF32LE = 0x1c000100 };
33extern CFStringRef CFStringCreateWithCString(CFAllocatorRef alloc, const char *cStr, CFStringEncoding encoding);
34typedef double CFTimeInterval;
35typedef CFTimeInterval CFAbsoluteTime;
36typedef const struct __CFDate * CFDateRef;
37extern CFDateRef CFDateCreate(CFAllocatorRef allocator, CFAbsoluteTime at);
38extern CFAbsoluteTime CFDateGetAbsoluteTime(CFDateRef theDate);
39typedef __darwin_natural_t natural_t;
40typedef natural_t mach_port_name_t;
41typedef mach_port_name_t mach_port_t;
42typedef signed char BOOL;
43typedef struct _NSZone NSZone;
44@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
45@protocol NSObject - (BOOL)isEqual:(id)object;
46- (id)retain;
47- (oneway void)release;
48@end @protocol NSCopying - (id)copyWithZone:(NSZone *)zone;
49@end @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
50@end @interface NSObject <NSObject> {
51}
52@end typedef float CGFloat;
53typedef double NSTimeInterval;
54@interface NSDate : NSObject <NSCopying, NSCoding> - (NSTimeInterval)timeIntervalSinceReferenceDate;
55@end enum {
56NSObjCNoType = 0, NSObjCVoidType = 'v', NSObjCCharType = 'c', NSObjCShortType = 's', NSObjCLongType = 'l', NSObjCLonglongType = 'q', NSObjCFloatType = 'f', NSObjCDoubleType = 'd', NSObjCBoolType = 'B', NSObjCSelectorType = ':', NSObjCObjectType = '@', NSObjCStructType = '{', NSObjCPointerType = '^', NSObjCStringType = '*', NSObjCArrayType = '[', NSObjCUnionType = '(', NSObjCBitfield = 'b' }
57__attribute__((deprecated));
58typedef int kern_return_t;
59typedef kern_return_t mach_error_t;
60typedef mach_port_t io_object_t;
61typedef io_object_t io_service_t;
62typedef struct __DASession * DASessionRef;
63extern DASessionRef DASessionCreate( CFAllocatorRef allocator );
64typedef struct __DADisk * DADiskRef;
65extern DADiskRef DADiskCreateFromBSDName( CFAllocatorRef allocator, DASessionRef session, const char * name );
66extern DADiskRef DADiskCreateFromIOMedia( CFAllocatorRef allocator, DASessionRef session, io_service_t media );
67extern CFDictionaryRef DADiskCopyDescription( DADiskRef disk );
68extern DADiskRef DADiskCopyWholeDisk( DADiskRef disk );
69@interface NSAppleEventManager : NSObject {
70}
71@end enum {
72kDAReturnSuccess = 0, kDAReturnError = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x01, kDAReturnBusy = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x02, kDAReturnBadArgument = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x03, kDAReturnExclusiveAccess = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x04, kDAReturnNoResources = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x05, kDAReturnNotFound = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x06, kDAReturnNotMounted = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x07, kDAReturnNotPermitted = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x08, kDAReturnNotPrivileged = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x09, kDAReturnNotReady = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0A, kDAReturnNotWritable = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0B, kDAReturnUnsupported = (((0x3e)&0x3f)<<26) | (((0x368)&0xfff)<<14) | 0x0C };
73typedef mach_error_t DAReturn;
74typedef const struct __DADissenter * DADissenterRef;
75extern DADissenterRef DADissenterCreate( CFAllocatorRef allocator, DAReturn status, CFStringRef string );
76
77//===----------------------------------------------------------------------===//
78// Test cases.
79//===----------------------------------------------------------------------===//
80
81// Test to see if we supresss an error when we store the pointer
82// to a struct. This is because the value "escapes" the basic reasoning
83// of basic store.
84
85struct foo {
86 NSDate* f;
87};
88
Chris Lattnere0303582010-01-09 20:43:19 +000089CFAbsoluteTime CFAbsoluteTimeGetCurrent(void);
90
Ted Kremenek0964a062009-01-21 06:57:53 +000091CFAbsoluteTime f4() {
92 struct foo x;
93
94 CFAbsoluteTime t = CFAbsoluteTimeGetCurrent();
95 CFDateRef date = CFDateCreate(0, t);
96 [((NSDate*) date) retain];
97 CFRelease(date);
98 CFDateGetAbsoluteTime(date); // no-warning
99 x.f = (NSDate*) date;
100 [((NSDate*) date) release];
101 t = CFDateGetAbsoluteTime(date); // no-warning
102 return t;
103}
104