1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -analyze -analyzer-checker=core,osx.coreFoundation.CFNumber,osx.cocoa.RetainCount -analyzer-store=region -analyzer-constraints=range -verify -triple x86_64-apple-darwin9 %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc typedef signed long CFIndex;
4*f4a2713aSLionel Sambuc typedef const struct __CFAllocator * CFAllocatorRef;
5*f4a2713aSLionel Sambuc enum { kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2,
6*f4a2713aSLionel Sambuc kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4,
7*f4a2713aSLionel Sambuc kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6,
8*f4a2713aSLionel Sambuc kCFNumberCharType = 7, kCFNumberShortType = 8,
9*f4a2713aSLionel Sambuc kCFNumberIntType = 9, kCFNumberLongType = 10,
10*f4a2713aSLionel Sambuc kCFNumberLongLongType = 11, kCFNumberFloatType = 12,
11*f4a2713aSLionel Sambuc kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14,
12*f4a2713aSLionel Sambuc kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16,
13*f4a2713aSLionel Sambuc kCFNumberMaxType = 16 };
14*f4a2713aSLionel Sambuc typedef CFIndex CFNumberType;
15*f4a2713aSLionel Sambuc typedef const struct __CFNumber * CFNumberRef;
16*f4a2713aSLionel Sambuc extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
17*f4a2713aSLionel Sambuc
f1(unsigned char x)18*f4a2713aSLionel Sambuc CFNumberRef f1(unsigned char x) {
19*f4a2713aSLionel Sambuc return CFNumberCreate(0, kCFNumberSInt16Type, &x); // expected-warning{{An 8 bit integer is used to initialize a CFNumber object that represents a 16 bit integer. 8 bits of the CFNumber value will be garbage}}
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc
f2(unsigned short x)22*f4a2713aSLionel Sambuc __attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
23*f4a2713aSLionel Sambuc return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{A 16 bit integer is used to initialize a CFNumber object that represents an 8 bit integer. 8 bits of the input integer will be lost}}
24*f4a2713aSLionel Sambuc }
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel Sambuc // test that the attribute overrides the naming convention.
CreateNum(unsigned char x)27*f4a2713aSLionel Sambuc __attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x) {
28*f4a2713aSLionel Sambuc return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{leak}}
29*f4a2713aSLionel Sambuc }
30*f4a2713aSLionel Sambuc
f3(unsigned i)31*f4a2713aSLionel Sambuc CFNumberRef f3(unsigned i) {
32*f4a2713aSLionel Sambuc return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer}}
33*f4a2713aSLionel Sambuc }
34