1// RUN: %clang_analyze_cc1 -x objective-c -analyzer-checker=core -analyzer-output=text -Wno-objc-root-class -fblocks -verify %s
2
3@interface I
4- (int)initVar:(int *)var param:(int)param;
5@end
6
7@implementation I
8- (int)initVar:(int *)var param:(int)param {
9  if (param) { // expected-note{{Taking false branch}}
10    *var = 1;
11    return 0;
12  }
13  return 1; // expected-note{{Returning without writing to '*var'}}
14}
15@end
16
17int foo(I *i) {
18  int x;                            //expected-note{{'x' declared without an initial value}}
19  int out = [i initVar:&x param:0]; //expected-note{{Calling 'initVar:param:'}}
20                                    //expected-note@-1{{Returning from 'initVar:param:'}}
21  if (out)                          // expected-note{{Taking true branch}}
22    return x;                       //expected-warning{{Undefined or garbage value returned to caller}}
23                                    //expected-note@-1{{Undefined or garbage value returned to caller}}
24  return 0;
25}
26
27int initializer1(int *p, int x) {
28  if (x) { // expected-note{{Taking false branch}}
29    *p = 1;
30    return 0;
31  } else {
32    return 1; // expected-note {{Returning without writing to '*p'}}
33  }
34}
35
36int initFromBlock() {
37  __block int z;
38  ^{                     // expected-note {{Calling anonymous block}}
39    int p;               // expected-note{{'p' declared without an initial value}}
40    initializer1(&p, 0); // expected-note{{Calling 'initializer1'}}
41                         // expected-note@-1{{Returning from 'initializer1'}}
42    z = p;               // expected-warning{{Assigned value is garbage or undefined}}
43                         // expected-note@-1{{Assigned value is garbage or undefined}}
44  }();
45  return z;
46}
47