1// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.unix,core.uninitialized -analyzer-store=region -verify %s
2typedef __typeof(sizeof(int)) size_t;
3void *malloc(size_t);
4void free(void *);
5
6char stackBased1 () {
7  char buf[2];
8  buf[0] = 'a';
9  return buf[1]; // expected-warning{{Undefined}}
10}
11
12char stackBased2 () {
13  char buf[2];
14  buf[1] = 'a';
15  return buf[0]; // expected-warning{{Undefined}}
16}
17
18// Exercise the conditional visitor. Radar://10105448
19char stackBased3 (int *x) {
20  char buf[2];
21  int *y;
22  buf[0] = 'a';
23  if (!(y = x)) {
24    return buf[1]; // expected-warning{{Undefined}}
25  }
26  return buf[0];
27}
28
29char heapBased1 () {
30  char *buf = malloc(2);
31  buf[0] = 'a';
32  char result = buf[1]; // expected-warning{{undefined}}
33  free(buf);
34  return result;
35}
36
37char heapBased2 () {
38  char *buf = malloc(2);
39  buf[1] = 'a';
40  char result = buf[0]; // expected-warning{{undefined}}
41  free(buf);
42  return result;
43}
44