stack-addr-ps.c revision dac5bd4f15681062c2e11538d59197f9952c0703
1// RUN: clang-cc -analyze -checker-cfref -analyzer-store=basic -verify %s
2
3// NOWORK: clang-cc -analyze -checker-cfref -analyzer-store=region -verify %s
4
5#include <stdlib.h>
6
7int* f1() {
8  int x = 0;
9  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}}
10}
11
12int* f2(int y) {
13  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}}
14}
15
16int* f3(int x, int *y) {
17  int w = 0;
18
19  if (x)
20    y = &w;
21
22  return y; // expected-warning{{Address of stack memory associated with local variable 'w' returned.}}
23}
24
25void* compound_literal(int x, int y) {
26  if (x)
27    return &(unsigned short){((unsigned short)0x22EF)}; // expected-warning{{Address of stack memory}}
28
29  int* array[] = {};
30  struct s { int z; double y; int w; };
31
32  if (y)
33    return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of stack memory}}
34
35
36  void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });
37  return p; // expected-warning{{Address of stack memory}}
38}
39
40void* alloca_test() {
41  void* p = __builtin_alloca(10);
42  return p; // expected-warning{{Address of stack memory}}
43}
44
45int array_test(int x[2]) {
46  return x[0]; // no-warning
47}
48
49struct baz { int x; };
50
51int struct_test(struct baz byVal) {
52  return byVal.x; // no-warning;
53}
54
55