xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/cfref_PR2519.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.cocoa.RetainCount,alpha.core -analyzer-store=region -analyzer-constraints=range -verify %s
2*f4a2713aSLionel Sambuc // expected-no-diagnostics
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc typedef unsigned char Boolean;
5*f4a2713aSLionel Sambuc typedef signed long CFIndex;
6*f4a2713aSLionel Sambuc typedef const void * CFTypeRef;
7*f4a2713aSLionel Sambuc typedef const struct __CFString * CFStringRef;
8*f4a2713aSLionel Sambuc typedef const struct __CFAllocator * CFAllocatorRef;
9*f4a2713aSLionel Sambuc extern const CFAllocatorRef kCFAllocatorDefault;
10*f4a2713aSLionel Sambuc typedef struct {} CFAllocatorContext;
11*f4a2713aSLionel Sambuc extern void CFRelease(CFTypeRef cf);
12*f4a2713aSLionel Sambuc typedef struct {}
13*f4a2713aSLionel Sambuc CFDictionaryKeyCallBacks;
14*f4a2713aSLionel Sambuc extern const CFDictionaryKeyCallBacks kCFTypeDictionaryKeyCallBacks;
15*f4a2713aSLionel Sambuc typedef struct {}
16*f4a2713aSLionel Sambuc CFDictionaryValueCallBacks;
17*f4a2713aSLionel Sambuc extern const CFDictionaryValueCallBacks kCFTypeDictionaryValueCallBacks;
18*f4a2713aSLionel Sambuc typedef const struct __CFDictionary * CFDictionaryRef;
19*f4a2713aSLionel Sambuc extern CFDictionaryRef CFDictionaryCreate(CFAllocatorRef allocator, const void **keys, const void **values, CFIndex numValues, const CFDictionaryKeyCallBacks *keyCallBacks, const CFDictionaryValueCallBacks *valueCallBacks);
20*f4a2713aSLionel Sambuc enum { 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    };
21*f4a2713aSLionel Sambuc typedef CFIndex CFNumberType;
22*f4a2713aSLionel Sambuc typedef const struct __CFNumber * CFNumberRef;
23*f4a2713aSLionel Sambuc extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
24*f4a2713aSLionel Sambuc typedef struct __CFNotificationCenter * CFNotificationCenterRef;
25*f4a2713aSLionel Sambuc extern CFNotificationCenterRef CFNotificationCenterGetDistributedCenter(void);
26*f4a2713aSLionel Sambuc extern void CFNotificationCenterPostNotification(CFNotificationCenterRef center, CFStringRef name, const void *object, CFDictionaryRef userInfo, Boolean deliverImmediately);
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc // This test case was reported in PR2519 as a false positive (_value was
29*f4a2713aSLionel Sambuc // reported as being leaked).
30*f4a2713aSLionel Sambuc 
main(int argc,char ** argv)31*f4a2713aSLionel Sambuc int main(int argc, char **argv) {
32*f4a2713aSLionel Sambuc  CFStringRef _key = ((CFStringRef) __builtin___CFStringMakeConstantString ("" "Process identifier" ""));
33*f4a2713aSLionel Sambuc  int pid = 42;
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc  CFNumberRef _value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid);
36*f4a2713aSLionel Sambuc  CFDictionaryRef userInfo = CFDictionaryCreate(kCFAllocatorDefault, (const void **)&_key, (const void **)&_value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
37*f4a2713aSLionel Sambuc  CFRelease(_value); // no-warning
38*f4a2713aSLionel Sambuc  CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
39*f4a2713aSLionel Sambuc            ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlPreferencesChanged" "")),
40*f4a2713aSLionel Sambuc            ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlUserDefaults" "")),
41*f4a2713aSLionel Sambuc            userInfo, 0);
42*f4a2713aSLionel Sambuc  CFRelease(userInfo); // no-warning
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc  return 0;
45*f4a2713aSLionel Sambuc }
46*f4a2713aSLionel Sambuc 
47