| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "-O2 -fdump-tree-sra" } */ |
| 3 |
/* { dg-require-effective-target indirect_jumps } */ |
| 4 |
|
| 5 |
#include <setjmp.h> |
| 6 |
|
| 7 |
struct S { |
| 8 |
long *b; |
| 9 |
int c; |
| 10 |
int s; |
| 11 |
}; |
| 12 |
|
| 13 |
static jmp_buf the_jmpbuf; |
| 14 |
volatile short vs = 0; |
| 15 |
long buf[16]; |
| 16 |
long * volatile pbuf = (long *) &buf; |
| 17 |
|
| 18 |
static void __attribute__((noinline)) |
| 19 |
crazy_alloc_s (struct S *p) |
| 20 |
{ |
| 21 |
int s = p->c ? p->c * 2 : 16; |
| 22 |
|
| 23 |
long *b = pbuf; |
| 24 |
if (!b || s > 16) |
| 25 |
{ |
| 26 |
p->s = -p->s; |
| 27 |
vs = 127; |
| 28 |
longjmp (the_jmpbuf, 1); |
| 29 |
} |
| 30 |
|
| 31 |
__builtin_memcpy (b, p->b, p->c); |
| 32 |
p->b = b; |
| 33 |
p->s = s; |
| 34 |
pbuf = 0; |
| 35 |
return; |
| 36 |
} |
| 37 |
|
| 38 |
long __attribute__((noipa)) |
| 39 |
process (long v) |
| 40 |
{ |
| 41 |
return v + 1; |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
foo (void) |
| 46 |
{ |
| 47 |
struct S stack; |
| 48 |
|
| 49 |
if (setjmp (the_jmpbuf)) |
| 50 |
return; |
| 51 |
|
| 52 |
stack.c = 0; |
| 53 |
crazy_alloc_s (&stack); |
| 54 |
stack.b[0] = 1; |
| 55 |
stack.c = 1; |
| 56 |
|
| 57 |
while (stack.c) |
| 58 |
{ |
| 59 |
long l = stack.b[--stack.c]; |
| 60 |
|
| 61 |
if (l > 0) |
| 62 |
{ |
| 63 |
for (int i = 0; i < 4; i++) |
| 64 |
{ |
| 65 |
if (stack.s <= stack.c + 1) |
| 66 |
crazy_alloc_s (&stack); |
| 67 |
l = process (l); |
| 68 |
stack.b[stack.c++] = l; |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
int main (int argc, char **argv) |
| 77 |
{ |
| 78 |
vs = 0; |
| 79 |
pbuf = (long *) &buf; |
| 80 |
foo (); |
| 81 |
if (vs != 127) |
| 82 |
__builtin_abort (); |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |
| 86 |
|
| 87 |
/* { dg-final { scan-tree-dump-not "Created a replacement for stack offset" "sra"} } */ |