blob: 3fcbc55044eaa38448b455d7a39bfd931fba42de [file] [log] [blame]
Argyrios Kyrtzidisc4d2c902011-02-28 19:49:42 +00001// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin8 %s
2// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s
3// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s
4// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s
5// RUN: %clang_cc1 -triple thumbv6-apple-darwin4.0.0-iphoneos -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s
6// RUN: %clang_cc1 -triple thumbv6-apple-darwin4.0.0-iphoneos -analyze -analyzer-checker=core,core.experimental -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=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() {
54 MyClass *obj = @"";
55
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 Kremenek61238742010-09-30 00:37:10 +000086
Ted Kremenek7e08dca2009-11-24 22:56:53 +000087// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
88// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
89// CHECK-darwin8: 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 +000090// CHECK-darwin8: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
Ted Kremenek7e08dca2009-11-24 22:56:53 +000091// CHECK-darwin8: 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 +000092// CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
93// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type '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 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' that will be garbage
96// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' 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