[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / Analysis / CFNumber.c
blob8c1b229f36e2663f6e0e2be0f75a7cfb97210a1c
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,osx.coreFoundation.CFNumber,osx.cocoa.RetainCount -verify -triple x86_64-apple-darwin9 %s
3 typedef signed long CFIndex;
4 typedef const struct __CFAllocator * CFAllocatorRef;
5 enum { kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2,
6 kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4,
7 kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6,
8 kCFNumberCharType = 7, kCFNumberShortType = 8,
9 kCFNumberIntType = 9, kCFNumberLongType = 10,
10 kCFNumberLongLongType = 11, kCFNumberFloatType = 12,
11 kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14,
12 kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16,
13 kCFNumberMaxType = 16 };
14 typedef CFIndex CFNumberType;
15 typedef const struct __CFNumber * CFNumberRef;
16 typedef unsigned char Boolean;
17 extern CFNumberRef CFNumberCreate(CFAllocatorRef allocator, CFNumberType theType, const void *valuePtr);
18 Boolean CFNumberGetValue(CFNumberRef number, CFNumberType theType, void *valuePtr);
20 __attribute__((cf_returns_retained)) CFNumberRef f1(unsigned char x) {
21 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}}
24 __attribute__((cf_returns_retained)) CFNumberRef f2(unsigned short x) {
25 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 integer value will be lost}}
28 // test that the attribute overrides the naming convention.
29 __attribute__((cf_returns_not_retained)) CFNumberRef CreateNum(unsigned char x) {
30 return CFNumberCreate(0, kCFNumberSInt8Type, &x); // expected-warning{{leak}}
33 __attribute__((cf_returns_retained)) CFNumberRef f3(unsigned i) {
34 return CFNumberCreate(0, kCFNumberLongType, &i); // expected-warning{{A 32-bit integer is used to initialize a CFNumber object that represents a 64-bit integer}}
37 unsigned char getValueTest1(CFNumberRef x) {
38 unsigned char scalar = 0;
39 CFNumberGetValue(x, kCFNumberSInt16Type, &scalar); // expected-warning{{A CFNumber object that represents a 16-bit integer is used to initialize an 8-bit integer; 8 bits of the CFNumber value will overwrite adjacent storage}}
40 return scalar;
43 unsigned char getValueTest2(CFNumberRef x) {
44 unsigned short scalar = 0;
45 CFNumberGetValue(x, kCFNumberSInt8Type, &scalar); // expected-warning{{A CFNumber object that represents an 8-bit integer is used to initialize a 16-bit integer; 8 bits of the integer value will be garbage}}
46 return scalar;