Ted Kremenek | b87f66c | 2009-01-21 07:10:01 +0000 | [diff] [blame] | 1 | // 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 Kremenek | 04bc876 | 2008-06-26 23:59:48 +0000 | [diff] [blame] | 3 | |
| 4 | typedef signed long CFIndex; |
| 5 | typedef const struct __CFAllocator * CFAllocatorRef; |
| 6 | enum { 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 }; |
| 15 | typedef CFIndex CFNumberType; |
| 16 | typedef const struct __CFNumber * CFNumberRef; |
| 17 | extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr); |
| 18 | |
Daniel Dunbar | d24d255 | 2009-01-20 01:27:09 +0000 | [diff] [blame] | 19 | CFNumberRef f1(unsigned char x) { |
Ted Kremenek | 04bc876 | 2008-06-26 23:59:48 +0000 | [diff] [blame] | 20 | 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 Dunbar | d24d255 | 2009-01-20 01:27:09 +0000 | [diff] [blame] | 23 | CFNumberRef f2(unsigned short x) { |
Ted Kremenek | 04bc876 | 2008-06-26 23:59:48 +0000 | [diff] [blame] | 24 | 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 Kremenek | 91985ae | 2008-09-18 00:28:23 +0000 | [diff] [blame] | 26 | |
| 27 | CFNumberRef 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 Dunbar | d24d255 | 2009-01-20 01:27:09 +0000 | [diff] [blame] | 29 | } |