]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Analysis/nil-receiver-undefined-larger-than-voidptr-ret.m
Vendor import of clang release_32 branch r168974 (effectively, 3.2 RC2):
[FreeBSD/FreeBSD.git] / test / Analysis / nil-receiver-undefined-larger-than-voidptr-ret.m
1 // RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,alpha.core -analyzer-constraints=range -analyzer-store=region -Wno-objc-root-class %s > %t.1 2>&1
2 // RUN: FileCheck -input-file=%t.1 -check-prefix=darwin8 %s
3 // RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,alpha.core -analyzer-constraints=range -analyzer-store=region -Wno-objc-root-class %s > %t.2 2>&1
4 // RUN: FileCheck -input-file=%t.2 -check-prefix=darwin9 %s
5 // RUN: %clang_cc1 -triple thumbv6-apple-ios4.0 -analyze -analyzer-checker=core,alpha.core -analyzer-constraints=range -analyzer-store=region -Wno-objc-root-class %s > %t.3 2>&1
6 // RUN: FileCheck -input-file=%t.3 -check-prefix=darwin9 %s
7
8 @interface MyClass {}
9 - (void *)voidPtrM;
10 - (int)intM;
11 - (long long)longlongM;
12 - (unsigned long long)unsignedLongLongM;
13 - (double)doubleM;
14 - (long double)longDoubleM;
15 - (void)voidM;
16 @end
17 @implementation MyClass
18 - (void *)voidPtrM { return (void *)0; }
19 - (int)intM { return 0; }
20 - (long long)longlongM { return 0; }
21 - (unsigned long long)unsignedLongLongM { return 0; }
22 - (double)doubleM { return 0.0; }
23 - (long double)longDoubleM { return 0.0; }
24 - (void)voidM {}
25 @end
26
27 void createFoo() {
28   MyClass *obj = 0;  
29   
30   void *v = [obj voidPtrM]; // no-warning
31   int i = [obj intM]; // no-warning
32 }
33
34 void createFoo2() {
35   MyClass *obj = 0;  
36   
37   long double ld = [obj longDoubleM];
38 }
39
40 void createFoo3() {
41   MyClass *obj;
42   obj = 0;  
43   
44   long long ll = [obj longlongM];
45 }
46
47 void createFoo4() {
48   MyClass *obj = 0;  
49   
50   double d = [obj doubleM];
51 }
52
53 void createFoo5() {
54   MyClass *obj = (id)@"";  
55   
56   double d = [obj doubleM]; // no-warning
57 }
58
59 void createFoo6() {
60   MyClass *obj;
61   obj = 0;  
62   
63   unsigned long long ull = [obj unsignedLongLongM];
64 }
65
66 void handleNilPruneLoop(MyClass *obj) {
67   if (!!obj)
68     return;
69   
70   // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
71   for (int i = 0; i < [obj intM]; i++) {
72     long long j = [obj longlongM];
73   }
74   
75   long long j = [obj longlongM];
76 }
77
78 int handleVoidInComma() {
79   MyClass *obj = 0;
80   return [obj voidM], 0;
81 }
82
83 int marker(void) { // control reaches end of non-void function
84 }
85
86 // CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
87 // CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
88 // CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
89 // CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
90 // CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
91
92 // CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
93 // CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
94 // CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
95 // CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
96 // CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
97 // CHECK-darwin9: 1 warning generated
98