From: Jakub Jelinek Date: Sat, 5 Jan 2019 11:14:12 +0000 (+0100) Subject: re PR middle-end/82564 (ICE at -O1 and above: in assign_stack_temp_for_type, at funct... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=23141e52419417d34eab8a2976fe417a6041e15e;p=gcc.git re PR middle-end/82564 (ICE at -O1 and above: in assign_stack_temp_for_type, at function.c:783) PR middle-end/82564 PR target/88620 * expr.c (expand_assignment): For calls returning VLA structures if to_rtx is not a MEM, force it into a stack temporary. * gcc.dg/nested-func-12.c: New test. * gcc.c-torture/compile/pr82564.c: New test. From-SVN: r267595 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e6992b0e982..91c55fae6ad 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2019-01-05 Jakub Jelinek + PR middle-end/82564 + PR target/88620 + * expr.c (expand_assignment): For calls returning VLA structures + if to_rtx is not a MEM, force it into a stack temporary. + PR debug/88635 * dwarf2out.c (const_ok_for_output_1): Reject MINUS that contains SYMBOL_REF, CODE_LABEL or UNSPEC in subexpressions of second argument. diff --git a/gcc/expr.c b/gcc/expr.c index 450486e24b0..818ee2deaa1 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -5254,6 +5254,21 @@ expand_assignment (tree to, tree from, bool nontemporal) emit_move_insn (XEXP (to_rtx, 1), read_complex_part (temp, true)); } } + /* For calls to functions returning variable length structures, if TO_RTX + is not a MEM, go through a MEM because we must not create temporaries + of the VLA type. */ + else if (!MEM_P (to_rtx) + && TREE_CODE (from) == CALL_EXPR + && COMPLETE_TYPE_P (TREE_TYPE (from)) + && TREE_CODE (TYPE_SIZE (TREE_TYPE (from))) != INTEGER_CST) + { + rtx temp = assign_stack_temp (GET_MODE (to_rtx), + GET_MODE_SIZE (GET_MODE (to_rtx))); + result = store_field (temp, bitsize, bitpos, bitregion_start, + bitregion_end, mode1, from, get_alias_set (to), + nontemporal, reversep); + emit_move_insn (to_rtx, temp); + } else { if (MEM_P (to_rtx)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index af59095b05b..0a783ce1b77 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2019-01-05 Jakub Jelinek + PR middle-end/82564 + PR target/88620 + * gcc.dg/nested-func-12.c: New test. + * gcc.c-torture/compile/pr82564.c: New test. + PR debug/88635 * gcc.dg/debug/dwarf2/pr88635.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/compile/pr82564.c b/gcc/testsuite/gcc.c-torture/compile/pr82564.c new file mode 100644 index 00000000000..039f55a3985 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr82564.c @@ -0,0 +1,15 @@ +/* PR middle-end/82564 */ +/* { dg-require-effective-target alloca } */ + +int +main () +{ + int t = 8, i; + typedef struct { char v[t]; } B; + B a, b; + B __attribute__ ((noinline)) f () { return b; } + for (i = 0; i < 8; i++) + b.v[i] = i; + a = f (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/nested-func-12.c b/gcc/testsuite/gcc.dg/nested-func-12.c new file mode 100644 index 00000000000..d617d7e4487 --- /dev/null +++ b/gcc/testsuite/gcc.dg/nested-func-12.c @@ -0,0 +1,48 @@ +/* PR target/88620 */ +/* { dg-do run } */ +/* { dg-options "-Ofast --param ipa-cp-eval-threshold=0 -fno-guess-branch-probability -fno-inline-small-functions" } */ +/* { dg-require-effective-target alloca } */ + +void +foo (int n) +{ + struct S { int a[n]; }; + + struct S + fn (void) + { + struct S s; + s.a[0] = 42; + return s; + } + + auto struct S + fn2 (void) + { + return fn (); + } + + struct S x; + fn (); + fn2 (); + x = fn (); + + if (x.a[0] != 42) + __builtin_abort (); + + if (fn ().a[0] != 42) + __builtin_abort (); + + __typeof__ (fn ()) *p = &x; + if (p->a[0] != 42) + __builtin_abort (); + + if (fn2 ().a[0] != 42) + __builtin_abort (); +} + +int +main (void) +{ + foo (1); +}