stack-addr-ps.c revision beb62c5836450dcdda53dca85399273acdf7104d
1// RUN: clang -checker-simple -verify %s
2
3int* f1() {
4  int x = 0;
5  return &x; // expected-warning{{Address of stack memory associated with local variable 'x' returned.}} expected-warning{{address of stack memory associated with local variable 'x' returned}}
6}
7
8int* f2(int y) {
9  return &y;  // expected-warning{{Address of stack memory associated with local variable 'y' returned.}} expected-warning{{address of stack memory associated with local variable 'y' returned}}
10}
11
12int* f3(int x, int *y) {
13  int w = 0;
14
15  if (x)
16    y = &w;
17
18  return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}}
19}
20
21void* compound_literal(int x, int y) {
22  if (x)
23    return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}} expected-warning{{braces around scalar initializer}}
24
25  int* array[] = {};
26  struct s { int z; double y; int w; };
27
28  if (y)
29    return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of stack memory}}
30
31
32  void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });
33  return p; // expected-warning{{Address of stack memory}}
34}
35
36