Hi! The following testcase ICEs, because ARRAY_REF on lhs of op= has a statement list with no side-effects as index (containing DEBUG_BEGIN_STMT and integer_zero_node), stabilize_reference does nothing to it (as it has no side-effects), then the array ref is unshared in unshare_body (mostly_copy_tree_r, which copies ARRAY_REF, but doesn't copy STATEMENT_LIST) and finally gimplifier when processing the first ARRAY_REF destroys the STATEMENT_LIST (moves the 0; out of it and voidifies the rest) and finally when gimplifying the second ARRAY_REF we ICE because the index has void type.
The following patch fixes it by forcing SAVE_EXPR for STATEMENT_LIST even when it doesn't have side-effects, that way even the DEBUG_BEGIN_STMTs are emitted just once rather than multiple times and we don't really need to unshare it specially. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-03-05 Jakub Jelinek <ja...@redhat.com> PR c++/84704 * tree.c (stabilize_reference_1): Return save_expr (e) for STATEMENT_LIST even if it doesn't have side-effects. * g++.dg/debug/pr84704.C: New test. --- gcc/tree.c.jj 2018-02-22 12:37:02.634387690 +0100 +++ gcc/tree.c 2018-03-05 10:50:54.355557537 +0100 @@ -4352,6 +4352,11 @@ stabilize_reference_1 (tree e) switch (TREE_CODE_CLASS (code)) { case tcc_exceptional: + /* Always wrap STATEMENT_LIST into SAVE_EXPR, even if it doesn't + have side-effects. */ + if (code == STATEMENT_LIST) + return save_expr (e); + /* FALLTHRU */ case tcc_type: case tcc_declaration: case tcc_comparison: --- gcc/testsuite/g++.dg/debug/pr84704.C.jj 2018-03-05 11:52:37.558715635 +0100 +++ gcc/testsuite/g++.dg/debug/pr84704.C 2018-03-05 11:53:17.794720038 +0100 @@ -0,0 +1,11 @@ +// PR c++/84704 +// { dg-do compile } +// { dg-options "-g -fcompare-debug -O2" } + +int a[1] = { 0 }; + +void +foo () +{ + a[({ 0; })] %= 5; +} Jakub