blob: 536c4a1b6731b0820bc139e17220d571e177d870 [file] [log] [blame]
Ted Kremenek8382cf52009-11-13 18:46:29 +00001// RUN: clang-cc -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify
2// RUN: clang-cc -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s -verify
Ted Kremenek899b3de2009-04-08 03:07:17 +00003
4@interface MyClass {}
5- (void *)voidPtrM;
6- (int)intM;
7- (long long)longlongM;
8- (double)doubleM;
9- (long double)longDoubleM;
Ted Kremenekfe630b92009-04-09 05:45:56 +000010- (void)voidM;
Ted Kremenek899b3de2009-04-08 03:07:17 +000011@end
12@implementation MyClass
13- (void *)voidPtrM { return (void *)0; }
14- (int)intM { return 0; }
15- (long long)longlongM { return 0; }
16- (double)doubleM { return 0.0; }
17- (long double)longDoubleM { return 0.0; }
Ted Kremenekfe630b92009-04-09 05:45:56 +000018- (void)voidM {}
Ted Kremenek899b3de2009-04-08 03:07:17 +000019@end
20
21void createFoo() {
22 MyClass *obj = 0;
23
24 void *v = [obj voidPtrM]; // no-warning
25 int i = [obj intM]; // no-warning
26}
27
28void createFoo2() {
29 MyClass *obj = 0;
30
31 long double ld = [obj longDoubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
32}
33
34void createFoo3() {
Ted Kremenek0c313172009-05-13 19:16:35 +000035 MyClass *obj;
36 obj = 0;
Ted Kremenek899b3de2009-04-08 03:07:17 +000037
38 long long ll = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
39}
40
41void createFoo4() {
42 MyClass *obj = 0;
43
44 double d = [obj doubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
45}
46
47void createFoo5() {
48 MyClass *obj = @"";
49
50 double d = [obj doubleM]; // no-warning
51}
52
Ted Kremenekda9ae602009-04-08 18:51:08 +000053void handleNilPruneLoop(MyClass *obj) {
54 if (!!obj)
55 return;
56
57 // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
58 for (int i = 0; i < [obj intM]; i++) {
59 long long j = [obj longlongM]; // no-warning
60 }
61
62 long long j = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
63}
Ted Kremenekfe630b92009-04-09 05:45:56 +000064
65int handleVoidInComma() {
66 MyClass *obj = 0;
67 return [obj voidM], 0;
68}