nil-receiver-undefined-larger-than-voidptr-ret.m revision 7e08dca61835c8f0cd99c9f4d364e2adcc339a0b
1// RUN: clang-cc -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s  2>&1 | FileCheck -check-prefix=darwin8 %s
2// RUN: clang-cc -triple i386-apple-darwin8 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin8 %s
3// RUN: clang-cc -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=basic %s 2>&1 | FileCheck -check-prefix=darwin9 %s
4// RUN: clang-cc -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -checker-cfref -analyzer-constraints=basic -analyzer-store=region %s 2>&1 | FileCheck -check-prefix=darwin9 %s
5
6@interface MyClass {}
7- (void *)voidPtrM;
8- (int)intM;
9- (long long)longlongM;
10- (double)doubleM;
11- (long double)longDoubleM;
12- (void)voidM;
13@end
14@implementation MyClass
15- (void *)voidPtrM { return (void *)0; }
16- (int)intM { return 0; }
17- (long long)longlongM { return 0; }
18- (double)doubleM { return 0.0; }
19- (long double)longDoubleM { return 0.0; }
20- (void)voidM {}
21@end
22
23void createFoo() {
24  MyClass *obj = 0;  
25  
26  void *v = [obj voidPtrM]; // no-warning
27  int i = [obj intM]; // no-warning
28}
29
30void createFoo2() {
31  MyClass *obj = 0;  
32  
33  long double ld = [obj longDoubleM]; // expected-warning{{The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage}}
34}
35
36void createFoo3() {
37  MyClass *obj;
38  obj = 0;  
39  
40  long long ll = [obj longlongM]; // expected-warning{{The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage}}
41}
42
43void createFoo4() {
44  MyClass *obj = 0;  
45  
46  double d = [obj doubleM]; // expected-warning{{The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage}}
47}
48
49void createFoo5() {
50  MyClass *obj = @"";  
51  
52  double d = [obj doubleM]; // no-warning
53}
54
55void handleNilPruneLoop(MyClass *obj) {
56  if (!!obj)
57    return;
58  
59  // Test if [obj intM] evaluates to 0, thus pruning the entire loop.
60  for (int i = 0; i < [obj intM]; i++) {
61    long long j = [obj longlongM]; // no-warning
62  }
63  
64  long long j = [obj longlongM]; // expected-warning{{The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage}}
65}
66
67int handleVoidInComma() {
68  MyClass *obj = 0;
69  return [obj voidM], 0;
70}
71
72int marker(void) { // control reaches end of non-void function
73}
74
75// CHECK-darwin8: warning: The receiver of message 'longDoubleM' is nil and returns a value of type 'long double' that will be garbage
76// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
77// CHECK-darwin8: warning: The receiver of message 'doubleM' is nil and returns a value of type 'double' that will be garbage
78// CHECK-darwin8: warning: The receiver of message 'longlongM' is nil and returns a value of type 'long long' that will be garbage
79// CHECK-darwin8: control reaches end of non-void function
80// CHECK-darwin8: 5 diagnostics generated
81// CHECK-darwin9: control reaches end of non-void function
82// CHECK-darwin9: 1 diagnostic generated
83