blob: f926a9f26af124afa466ee9a3deaba549049e1e4 [file] [log] [blame]
Ted Kremeneke1cea752009-07-06 21:58:46 +00001// RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify &&
Ted Kremenek988dc7e2009-07-10 21:45:10 +00002// RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic-old-cast %s -verify &&
3// RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s -verify
Ted Kremenek899b3de2009-04-08 03:07:17 +00004
5@interface MyClass {}
6- (void *)voidPtrM;
7- (int)intM;
8- (long long)longlongM;
9- (double)doubleM;
10- (long double)longDoubleM;
Ted Kremenekfe630b92009-04-09 05:45:56 +000011- (void)voidM;
Ted Kremenek899b3de2009-04-08 03:07:17 +000012@end
13@implementation MyClass
14- (void *)voidPtrM { return (void *)0; }
15- (int)intM { return 0; }
16- (long long)longlongM { return 0; }
17- (double)doubleM { return 0.0; }
18- (long double)longDoubleM { return 0.0; }
Ted Kremenekfe630b92009-04-09 05:45:56 +000019- (void)voidM {}
Ted Kremenek899b3de2009-04-08 03:07:17 +000020@end
21
22void createFoo() {
23 MyClass *obj = 0;
24
25 void *v = [obj voidPtrM]; // no-warning
26 int i = [obj intM]; // no-warning
27}
28
29void createFoo2() {
30 MyClass *obj = 0;
31
32 long double ld = [obj longDoubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
33}
34
35void createFoo3() {
Ted Kremenek0c313172009-05-13 19:16:35 +000036 MyClass *obj;
37 obj = 0;
Ted Kremenek899b3de2009-04-08 03:07:17 +000038
39 long long ll = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
40}
41
42void createFoo4() {
43 MyClass *obj = 0;
44
45 double d = [obj doubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
46}
47
48void createFoo5() {
49 MyClass *obj = @"";
50
51 double d = [obj doubleM]; // no-warning
52}
53
Ted Kremenekda9ae602009-04-08 18:51:08 +000054void handleNilPruneLoop(MyClass *obj) {
55 if (!!obj)
56 return;
57
58 // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
59 for (int i = 0; i < [obj intM]; i++) {
60 long long j = [obj longlongM]; // no-warning
61 }
62
63 long long j = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
64}
Ted Kremenekfe630b92009-04-09 05:45:56 +000065
66int handleVoidInComma() {
67 MyClass *obj = 0;
68 return [obj voidM], 0;
69}