blob: 43a527be19070aa11d6adee561e1aec60919946c [file] [log] [blame]
Ted Kremenek0187a1b2012-09-08 04:26:37 +00001// 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
Tim Northover931a4fe2013-08-12 12:51:05 +00002// RUN: FileCheck -input-file=%t.1 -check-prefix=CHECK-darwin8 %s
Ted Kremenek0187a1b2012-09-08 04:26:37 +00003// 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
Tim Northover931a4fe2013-08-12 12:51:05 +00004// RUN: FileCheck -input-file=%t.2 -check-prefix=CHECK-darwin9 %s
Ted Kremenek0187a1b2012-09-08 04:26:37 +00005// 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
Tim Northover931a4fe2013-08-12 12:51:05 +00006// RUN: FileCheck -input-file=%t.3 -check-prefix=CHECK-darwin9 %s
Ted Kremenek899b3de2009-04-08 03:07:17 +00007
8@interface MyClass {}
9- (void *)voidPtrM;
10- (int)intM;
11- (long long)longlongM;
Ted Kremenek61238742010-09-30 00:37:10 +000012- (unsigned long long)unsignedLongLongM;
Ted Kremenek899b3de2009-04-08 03:07:17 +000013- (double)doubleM;
14- (long double)longDoubleM;
Ted Kremenekfe630b92009-04-09 05:45:56 +000015- (void)voidM;
Ted Kremenek899b3de2009-04-08 03:07:17 +000016@end
17@implementation MyClass
18- (void *)voidPtrM { return (void *)0; }
19- (int)intM { return 0; }
20- (long long)longlongM { return 0; }
Ted Kremenek61238742010-09-30 00:37:10 +000021- (unsigned long long)unsignedLongLongM { return 0; }
Ted Kremenek899b3de2009-04-08 03:07:17 +000022- (double)doubleM { return 0.0; }
23- (long double)longDoubleM { return 0.0; }
Ted Kremenekfe630b92009-04-09 05:45:56 +000024- (void)voidM {}
Ted Kremenek899b3de2009-04-08 03:07:17 +000025@end
26
27void createFoo() {
28 MyClass *obj = 0;
29
30 void *v = [obj voidPtrM]; // no-warning
31 int i = [obj intM]; // no-warning
32}
33
34void createFoo2() {
35 MyClass *obj = 0;
36
Ted Kremenek61238742010-09-30 00:37:10 +000037 long double ld = [obj longDoubleM];
Ted Kremenek899b3de2009-04-08 03:07:17 +000038}
39
40void createFoo3() {
Ted Kremenek0c313172009-05-13 19:16:35 +000041 MyClass *obj;
42 obj = 0;
Ted Kremenek899b3de2009-04-08 03:07:17 +000043
Ted Kremenek61238742010-09-30 00:37:10 +000044 long long ll = [obj longlongM];
Ted Kremenek899b3de2009-04-08 03:07:17 +000045}
46
47void createFoo4() {
48 MyClass *obj = 0;
49
Ted Kremenek61238742010-09-30 00:37:10 +000050 double d = [obj doubleM];
Ted Kremenek899b3de2009-04-08 03:07:17 +000051}
52
53void createFoo5() {
Fariborz Jahanianf64bc202012-02-23 22:51:36 +000054 MyClass *obj = (id)@"";
Ted Kremenek899b3de2009-04-08 03:07:17 +000055
56 double d = [obj doubleM]; // no-warning
57}
58
Ted Kremenek61238742010-09-30 00:37:10 +000059void createFoo6() {
60 MyClass *obj;
61 obj = 0;
62
63 unsigned long long ull = [obj unsignedLongLongM];
64}
65
Ted Kremenekda9ae602009-04-08 18:51:08 +000066void 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++) {
Ted Kremenek61238742010-09-30 00:37:10 +000072 long long j = [obj longlongM];
Ted Kremenekda9ae602009-04-08 18:51:08 +000073 }
74
Ted Kremenek61238742010-09-30 00:37:10 +000075 long long j = [obj longlongM];
Ted Kremenekda9ae602009-04-08 18:51:08 +000076}
Ted Kremenekfe630b92009-04-09 05:45:56 +000077
78int handleVoidInComma() {
79 MyClass *obj = 0;
80 return [obj voidM], 0;
81}
Ted Kremenek7e08dca2009-11-24 22:56:53 +000082
83int marker(void) { // control reaches end of non-void function
84}
85
Ted Kremenek371b4772012-07-02 20:21:48 +000086// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
Ted Kremenekc4bac8e2012-08-16 17:45:23 +000087// 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
Anna Zaksb990d032012-03-13 19:32:19 +000091
Ted Kremenek61238742010-09-30 00:37:10 +000092// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
Ted Kremenek61238742010-09-30 00:37:10 +000093// CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
Anna Zaksb990d032012-03-13 19:32:19 +000094// CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
Ted Kremenek61238742010-09-30 00:37:10 +000095// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
Anna Zaksb990d032012-03-13 19:32:19 +000096// CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
Chris Lattner53eee7b2010-04-07 18:47:42 +000097// CHECK-darwin9: 1 warning generated
Ted Kremenek61238742010-09-30 00:37:10 +000098