| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O2 -fdump-tree-sra" } */ |
| 3 |
|
| 4 |
struct D |
| 5 |
{ |
| 6 |
long a; |
| 7 |
short b; |
| 8 |
}; |
| 9 |
|
| 10 |
struct S { |
| 11 |
struct D *b; |
| 12 |
int c; |
| 13 |
int s; |
| 14 |
}; |
| 15 |
|
| 16 |
struct D * __attribute__((malloc)) some_realloc_function (int c); |
| 17 |
|
| 18 |
static void __attribute__((noinline)) |
| 19 |
realloc_s (struct S *p) |
| 20 |
{ |
| 21 |
int s = p->c ? p->c * 2 : 16; |
| 22 |
p->b = some_realloc_function (s); |
| 23 |
p->s = s; |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
void modify (struct D *d); |
| 28 |
int test (struct D *d); |
| 29 |
|
| 30 |
static struct D gd; |
| 31 |
|
| 32 |
int |
| 33 |
foo (void) |
| 34 |
{ |
| 35 |
struct S stack; |
| 36 |
|
| 37 |
stack.c = 1; |
| 38 |
stack.s = 0; |
| 39 |
realloc_s (&stack); |
| 40 |
stack.b[0] = gd; |
| 41 |
stack.c = 1; |
| 42 |
|
| 43 |
while (stack.c) |
| 44 |
{ |
| 45 |
struct D d = stack.b[--stack.c]; |
| 46 |
if (test (&d)) |
| 47 |
{ |
| 48 |
for (int i = 0; i < 8; i++) |
| 49 |
{ |
| 50 |
if (stack.s <= stack.c + 1) |
| 51 |
realloc_s (&stack); |
| 52 |
modify(&d); |
| 53 |
stack.b[stack.c++] = d; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
return 0; |
| 58 |
} |
| 59 |
|
| 60 |
/* { dg-final { scan-tree-dump "Created a replacement for stack offset" "sra"} } */ |