nil-receiver-undefined-larger-than-voidptr-ret.m revision 0c31317a8d031227d6f1726e555f3e1bb044af17
1// RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify
2
3@interface MyClass {}
4- (void *)voidPtrM;
5- (int)intM;
6- (long long)longlongM;
7- (double)doubleM;
8- (long double)longDoubleM;
9- (void)voidM;
10@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; }
17- (void)voidM {}
18@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;
35  obj = 0;  
36  
37  long long ll = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
38}
39
40void createFoo4() {
41  MyClass *obj = 0;  
42  
43  double d = [obj doubleM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
44}
45
46void createFoo5() {
47  MyClass *obj = @"";  
48  
49  double d = [obj doubleM]; // no-warning
50}
51
52void handleNilPruneLoop(MyClass *obj) {
53  if (!!obj)
54    return;
55  
56  // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
57  for (int i = 0; i < [obj intM]; i++) {
58    long long j = [obj longlongM]; // no-warning
59  }
60  
61  long long j = [obj longlongM]; // expected-warning{{The receiver in the message expression is 'nil' and results in the returned value}}
62}
63
64int handleVoidInComma() {
65  MyClass *obj = 0;
66  return [obj voidM], 0;
67}
68