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