blob: 75cdf6ed39329cbe15670ed79dd0dc8b31eb81f1 [file] [log] [blame]
Ted Kremenek7e08dca2009-11-24 22:56:53 +00001// RUN: clang-cc -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin8 %s
2// RUN: clang-cc -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s
3// RUN: clang-cc -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s
4// RUN: clang-cc -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s
Ted Kremenek899b3de2009-04-08 03:07:17 +00005
6@interface MyClass {}
7- (void *)voidPtrM;
8- (int)intM;
9- (long long)longlongM;
10- (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; }
18- (double)doubleM { return 0.0; }
19- (long double)longDoubleM { return 0.0; }
Ted Kremenekfe630b92009-04-09 05:45:56 +000020- (void)voidM {}
Ted Kremenek899b3de2009-04-08 03:07:17 +000021@end
22
23void createFoo() {
24 MyClass *obj = 0;
25
26 void *v = [obj voidPtrM]; // no-warning
27 int i = [obj intM]; // no-warning
28}
29
30void createFoo2() {
31 MyClass *obj = 0;
32
Ted Kremenekfee96e02009-11-24 21:41:28 +000033 long double ld = [obj longDoubleM]; // expected-warning{{The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage}}
Ted Kremenek899b3de2009-04-08 03:07:17 +000034}
35
36void createFoo3() {
Ted Kremenek0c313172009-05-13 19:16:35 +000037 MyClass *obj;
38 obj = 0;
Ted Kremenek899b3de2009-04-08 03:07:17 +000039
Ted Kremenekfee96e02009-11-24 21:41:28 +000040 long long ll = [obj longlongM]; // expected-warning{{The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage}}
Ted Kremenek899b3de2009-04-08 03:07:17 +000041}
42
43void createFoo4() {
44 MyClass *obj = 0;
45
Ted Kremenekfee96e02009-11-24 21:41:28 +000046 double d = [obj doubleM]; // expected-warning{{The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage}}
Ted Kremenek899b3de2009-04-08 03:07:17 +000047}
48
49void createFoo5() {
50 MyClass *obj = @"";
51
52 double d = [obj doubleM]; // no-warning
53}
54
Ted Kremenekda9ae602009-04-08 18:51:08 +000055void handleNilPruneLoop(MyClass *obj) {
56 if (!!obj)
57 return;
58
59 // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
60 for (int i = 0; i < [obj intM]; i++) {
61 long long j = [obj longlongM]; // no-warning
62 }
63
Ted Kremenekfee96e02009-11-24 21:41:28 +000064 long long j = [obj longlongM]; // expected-warning{{The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage}}
Ted Kremenekda9ae602009-04-08 18:51:08 +000065}
Ted Kremenekfe630b92009-04-09 05:45:56 +000066
67int handleVoidInComma() {
68 MyClass *obj = 0;
69 return [obj voidM], 0;
70}
Ted Kremenek7e08dca2009-11-24 22:56:53 +000071
72int marker(void) { // control reaches end of non-void function
73}
74
75// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
76// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
77// CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
78// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
79// CHECK-darwin8: control reaches end of non-void function
80// CHECK-darwin8: 5 diagnostics generated
81// CHECK-darwin9: control reaches end of non-void function
82// CHECK-darwin9: 1 diagnostic generated