blob: eba72bac9f7120c61ad2b2fff6d516dc7f89ad57 [file] [log] [blame]
Ted Kremenek033a07e2011-08-03 23:14:55 +00001// RUN: %clang_cc1 -triple i386-apple-darwin8 -analyze -analyzer-checker=core,experimental.core -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s
2// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-checker=core,experimental.core -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s
Bob Wilson48b68a02012-01-31 23:52:58 +00003// RUN: %clang_cc1 -triple thumbv6-apple-ios4.0 -analyze -analyzer-checker=core,experimental.core -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s
Ted Kremenek899b3de2009-04-08 03:07:17 +00004
5@interface MyClass {}
6- (void *)voidPtrM;
7- (int)intM;
8- (long long)longlongM;
Ted Kremenek61238742010-09-30 00:37:10 +00009- (unsigned long long)unsignedLongLongM;
Ted Kremenek899b3de2009-04-08 03:07:17 +000010- (double)doubleM;
11- (long double)longDoubleM;
Ted Kremenekfe630b92009-04-09 05:45:56 +000012- (void)voidM;
Ted Kremenek899b3de2009-04-08 03:07:17 +000013@end
14@implementation MyClass
15- (void *)voidPtrM { return (void *)0; }
16- (int)intM { return 0; }
17- (long long)longlongM { return 0; }
Ted Kremenek61238742010-09-30 00:37:10 +000018- (unsigned long long)unsignedLongLongM { return 0; }
Ted Kremenek899b3de2009-04-08 03:07:17 +000019- (double)doubleM { return 0.0; }
20- (long double)longDoubleM { return 0.0; }
Ted Kremenekfe630b92009-04-09 05:45:56 +000021- (void)voidM {}
Ted Kremenek899b3de2009-04-08 03:07:17 +000022@end
23
24void createFoo() {
25 MyClass *obj = 0;
26
27 void *v = [obj voidPtrM]; // no-warning
28 int i = [obj intM]; // no-warning
29}
30
31void createFoo2() {
32 MyClass *obj = 0;
33
Ted Kremenek61238742010-09-30 00:37:10 +000034 long double ld = [obj longDoubleM];
Ted Kremenek899b3de2009-04-08 03:07:17 +000035}
36
37void createFoo3() {
Ted Kremenek0c313172009-05-13 19:16:35 +000038 MyClass *obj;
39 obj = 0;
Ted Kremenek899b3de2009-04-08 03:07:17 +000040
Ted Kremenek61238742010-09-30 00:37:10 +000041 long long ll = [obj longlongM];
Ted Kremenek899b3de2009-04-08 03:07:17 +000042}
43
44void createFoo4() {
45 MyClass *obj = 0;
46
Ted Kremenek61238742010-09-30 00:37:10 +000047 double d = [obj doubleM];
Ted Kremenek899b3de2009-04-08 03:07:17 +000048}
49
50void createFoo5() {
51 MyClass *obj = @"";
52
53 double d = [obj doubleM]; // no-warning
54}
55
Ted Kremenek61238742010-09-30 00:37:10 +000056void createFoo6() {
57 MyClass *obj;
58 obj = 0;
59
60 unsigned long long ull = [obj unsignedLongLongM];
61}
62
Ted Kremenekda9ae602009-04-08 18:51:08 +000063void handleNilPruneLoop(MyClass *obj) {
64 if (!!obj)
65 return;
66
67 // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
68 for (int i = 0; i < [obj intM]; i++) {
Ted Kremenek61238742010-09-30 00:37:10 +000069 long long j = [obj longlongM];
Ted Kremenekda9ae602009-04-08 18:51:08 +000070 }
71
Ted Kremenek61238742010-09-30 00:37:10 +000072 long long j = [obj longlongM];
Ted Kremenekda9ae602009-04-08 18:51:08 +000073}
Ted Kremenekfe630b92009-04-09 05:45:56 +000074
75int handleVoidInComma() {
76 MyClass *obj = 0;
77 return [obj voidM], 0;
78}
Ted Kremenek7e08dca2009-11-24 22:56:53 +000079
80int marker(void) { // control reaches end of non-void function
81}
82
Ted Kremenek61238742010-09-30 00:37:10 +000083
Ted Kremenek7e08dca2009-11-24 22:56:53 +000084// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
85// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
86// 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 +000087// 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 +000088// 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 +000089// CHECK-darwin9-NOT: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
90// CHECK-darwin9-NOT: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
91// CHECK-darwin9-NOT: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
92// CHECK-darwin9-NOT: warning: The receiver of message 'unsignedLongLongM' is nil and returns a value of type 'unsigned long long' 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
Chris Lattner53eee7b2010-04-07 18:47:42 +000094// CHECK-darwin9: 1 warning generated
Ted Kremenek61238742010-09-30 00:37:10 +000095