aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/addrtmp.c
blob: 3de0175e70a7eb7a050d85f6ffe36fd972c1f0b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* { dg-do compile } */
/* { dg-options "-O2" } */
/* { dg-add-options bind_pic_locally } */

typedef struct A { int a,b; } A;
int*g(int*x){return x;}
int*f1(){
  A x[2]={{1,2},{3,4}};
  return g(&x[1].a); // { dg-warning "returns address of local variable" }
}
int*f2(int n){
  A x[2]={{1,2},{3,4}};
  return n?0:g(&x[1].a); // { dg-warning "may return address of local variable" }
}
A y[2]={{1,2},{3,4}};
int*h(){
  return g(&y[1].a);
}
int*j(int n){
  A x[2]={{1,2},{3,4}};
  int*p=g(&y[1].a);
  if(n==1)p=g(&x[1].a);
  if(n==2)p=g(&x[0].b);
  return p; // { dg-warning "may return address of local variable" }
}
int*s()
{
  static int i;
  return &i;
}