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