blob: e0d3c3ad03dfc397755e7b12397e06eca1d3423f [file] [log] [blame]
Ted Kremenekb87f66c2009-01-21 07:10:01 +00001// RUN: clang -analyze -checker-cfref -analyzer-store-basic -verify -triple x86_64-apple-darwin9 %s &&
2// RUN: clang -analyze -checker-cfref -analyzer-store-region -verify -triple x86_64-apple-darwin9 %s
Ted Kremenek04bc8762008-06-26 23:59:48 +00003
4typedef signed long CFIndex;
5typedef const struct __CFAllocator * CFAllocatorRef;
6enum { kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2,
7 kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4,
8 kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6,
9 kCFNumberCharType = 7, kCFNumberShortType = 8,
10 kCFNumberIntType = 9, kCFNumberLongType = 10,
11 kCFNumberLongLongType = 11, kCFNumberFloatType = 12,
12 kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14,
13 kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16,
14 kCFNumberMaxType = 16 };
15typedef CFIndex CFNumberType;
16typedef const struct __CFNumber * CFNumberRef;
17extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
18
Daniel Dunbard24d2552009-01-20 01:27:09 +000019CFNumberRef f1(unsigned char x) {
Ted Kremenek04bc8762008-06-26 23:59:48 +000020 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.}}
21}
22
Daniel Dunbard24d2552009-01-20 01:27:09 +000023CFNumberRef f2(unsigned short x) {
Ted Kremenek04bc8762008-06-26 23:59:48 +000024 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.}}
25}
Ted Kremenek91985ae2008-09-18 00:28:23 +000026
27CFNumberRef f3(unsigned i) {
28 return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32 bit integer is used to initialize a CFNumber object that represents a 64 bit integer.}}
Daniel Dunbard24d2552009-01-20 01:27:09 +000029}