nil-receiver-undefined-larger-than-voidptr-ret.m revision c037eac3bda3c636c961aab6377beea3242e81e4
1// RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s -verify &&
2// RUN: clang-cc -triple i386-apple-darwin9 -analyze -checker-cfref -analyzer-constraints=basic -analyzer-store=basic-old-cast %s -verify
3
4@interface MyClass {}
5- (void *)voidPtrM;
6- (int)intM;
7- (long long)longlongM;
8- (double)doubleM;
9- (long double)longDoubleM;
10- (void)voidM;
11@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; }
18- (void)voidM {}
19@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() {
35  MyClass *obj;
36  obj = 0;  
37  
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
53void 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}
64
65int handleVoidInComma() {
66  MyClass *obj = 0;
67  return [obj voidM], 0;
68}
69