| 1 |
/* PR tree-optimization/119493 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-O2 -fdump-tree-tailr1" } */ |
| 4 |
/* { dg-final { scan-tree-dump-times " = foo \\\(\[^\n\r;]*\\\);" 4 "tailr1" } } */ |
| 5 |
/* { dg-final { scan-tree-dump-times " = bar \\\(\[^\n\r;]*\\\);" 4 "tailr1" } } */ |
| 6 |
/* { dg-final { scan-tree-dump-not " = foo \\\(\[^\n\r;]*\\\); \\\[must tail call\\\]" "tailr1" } } */ |
| 7 |
/* { dg-final { scan-tree-dump-not " = bar \\\(\[^\n\r;]*\\\); \\\[must tail call\\\]" "tailr1" } } */ |
| 8 |
|
| 9 |
struct S { unsigned s; }; |
| 10 |
struct T { struct S t[2]; }; |
| 11 |
|
| 12 |
[[gnu::noinline, gnu::noclone]] struct S |
| 13 |
foo (struct S m) |
| 14 |
{ |
| 15 |
if (m.s == 0 || m.s == 42) |
| 16 |
return m; |
| 17 |
[[gnu::musttail]] return foo ((struct S) { m.s - 1 }); |
| 18 |
} |
| 19 |
|
| 20 |
[[gnu::noinline, gnu::noclone]] struct S |
| 21 |
bar (struct T m, struct S n, int o, int p, int q) |
| 22 |
{ |
| 23 |
struct T r; |
| 24 |
if (m.t[1].s != o || n.s != o) |
| 25 |
__builtin_abort (); |
| 26 |
if (o == 0 || o == 42) |
| 27 |
return n; |
| 28 |
r = m; |
| 29 |
m.t[1].s -= p; |
| 30 |
r.t[1].s -= q; |
| 31 |
[[gnu::musttail]] return bar (r, m.t[1], o - 1, p, q); |
| 32 |
} |
| 33 |
|
| 34 |
int |
| 35 |
main () |
| 36 |
{ |
| 37 |
if (foo ((struct S) { 0 }).s != 0) |
| 38 |
__builtin_abort (); |
| 39 |
if (foo ((struct S) { 4 }).s != 0) |
| 40 |
__builtin_abort (); |
| 41 |
if (foo ((struct S) { 42 }).s != 42) |
| 42 |
__builtin_abort (); |
| 43 |
if (foo ((struct S) { 51 }).s != 42) |
| 44 |
__builtin_abort (); |
| 45 |
if (bar ((struct T) { { { 0 }, { 0 } } }, (struct S) { 0 }, 0, 1, 1).s != 0) |
| 46 |
__builtin_abort (); |
| 47 |
if (bar ((struct T) { { { 7 }, { 7 } } }, (struct S) { 7 }, 7, 1, 1).s != 0) |
| 48 |
__builtin_abort (); |
| 49 |
if (bar ((struct T) { { { 42 }, { 42 } } }, |
| 50 |
(struct S) { 42 }, 42, 1, 1).s != 42) |
| 51 |
__builtin_abort (); |
| 52 |
if (bar ((struct T) { { { 48 }, { 48 } } }, |
| 53 |
(struct S) { 48 }, 48, 1, 1).s != 42) |
| 54 |
__builtin_abort (); |
| 55 |
} |