cfref_PR2519.c revision e1cea75e70d76f55157749a7bcad319050492945
1// RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=basic -verify %s &&
2// RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic-new-cast -analyzer-constraints=basic -verify %s &&
3// RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic -analyzer-constraints=range -verify %s &&
4// RUN: clang-cc -analyze -checker-cfref --analyzer-store=basic-new-cast -analyzer-constraints=range -verify %s &&
5// RUN: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=basic -verify %s &&
6// RUN: clang-cc -analyze -checker-cfref --analyzer-store=region -analyzer-constraints=range -verify %s
7
8typedef unsigned char Boolean;
9typedef signed long CFIndex;
10typedef const void * CFTypeRef;
11typedef const struct __CFString * CFStringRef;
12typedef const struct __CFAllocator * CFAllocatorRef;
13extern const CFAllocatorRef kCFAllocatorDefault;
14typedef struct {} CFAllocatorContext;
15extern void CFRelease(CFTypeRef cf);
16typedef struct {}
17CFDictionaryKeyCallBacks;
18extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;
19typedef struct {}
20CFDictionaryValueCallBacks;
21extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks;
22typedef const struct __CFDictionary * CFDictionaryRef;
23extern CFDictionaryRef CFDictionaryCreate(CFAllocatorRef allocator, const void **keys, const void **values, CFIndex numValues, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
24enum { kCFNumberSInt8Type = 1,     kCFNumberSInt16Type = 2,     kCFNumberSInt32Type = 3,     kCFNumberSInt64Type = 4,     kCFNumberFloat32Type = 5,     kCFNumberFloat64Type = 6,      kCFNumberCharType = 7,     kCFNumberShortType = 8,     kCFNumberIntType = 9,     kCFNumberLongType = 10,     kCFNumberLongLongType = 11,     kCFNumberFloatType = 12,     kCFNumberDoubleType = 13,      kCFNumberCFIndexType = 14,      kCFNumberNSIntegerType = 15,     kCFNumberCGFloatType = 16,     kCFNumberMaxType = 16    };
25typedef CFIndex CFNumberType;
26typedef const struct __CFNumber * CFNumberRef;
27extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
28typedef struct __CFNotificationCenter * CFNotificationCenterRef;
29extern CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
30extern void CFNotificationCenterPostNotification(CFNotificationCenterRef center, CFStringRef name, const void *object, CFDictionaryRef userInfo, Boolean deliverImmediately);
31
32// This test case was reported in PR2519 as a false positive (_value was
33// reported as being leaked).
34
35int main(int argc, char **argv) {
36 CFStringRef _key = ((CFStringRef) __builtin___CFStringMakeConstantString ("" "Process identifier" ""));
37 int pid = 42;
38
39 CFNumberRef _value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid);
40 CFDictionaryRef userInfo = CFDictionaryCreate(kCFAllocatorDefault, (const void **)&_key, (const void **)&_value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
41 CFRelease(_value); // no-warning
42 CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
43           ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlPreferencesChanged" "")),
44           ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlUserDefaults" "")),
45           userInfo, 0);
46 CFRelease(userInfo); // no-warning
47
48 return 0;
49}
50
51