The following fixes gimple_assign_set_rhs_with_ops to transfer EH info so that the stale stmts are not left in the EH tables.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk. Richard. 2018-12-10 Richard Biener <rguent...@suse.de> PR middle-end/88415 * gimple.c (gimple_assign_set_rhs_with_ops): Transfer EH info to a newly allocated stmt. * gcc.dg/gomp/pr88415.c: New testcase. Index: gcc/gimple.c =================================================================== --- gcc/gimple.c (revision 266945) +++ gcc/gimple.c (working copy) @@ -1729,16 +1729,15 @@ gimple_assign_set_rhs_with_ops (gimple_s { unsigned new_rhs_ops = get_gimple_rhs_num_ops (code); gimple *stmt = gsi_stmt (*gsi); + gimple *old_stmt = stmt; /* If the new CODE needs more operands, allocate a new statement. */ if (gimple_num_ops (stmt) < new_rhs_ops + 1) { - tree lhs = gimple_assign_lhs (stmt); - gimple *new_stmt = gimple_alloc (gimple_code (stmt), new_rhs_ops + 1); - memcpy (new_stmt, stmt, gimple_size (gimple_code (stmt))); - gimple_init_singleton (new_stmt); - gsi_replace (gsi, new_stmt, false); - stmt = new_stmt; + tree lhs = gimple_assign_lhs (old_stmt); + stmt = gimple_alloc (gimple_code (old_stmt), new_rhs_ops + 1); + memcpy (stmt, old_stmt, gimple_size (gimple_code (old_stmt))); + gimple_init_singleton (stmt); /* The LHS needs to be reset as this also changes the SSA name on the LHS. */ @@ -1752,6 +1751,8 @@ gimple_assign_set_rhs_with_ops (gimple_s gimple_assign_set_rhs2 (stmt, op2); if (new_rhs_ops > 2) gimple_assign_set_rhs3 (stmt, op3); + if (stmt != old_stmt) + gsi_replace (gsi, stmt, true); } Index: gcc/testsuite/gcc.dg/gomp/pr88415.c =================================================================== --- gcc/testsuite/gcc.dg/gomp/pr88415.c (nonexistent) +++ gcc/testsuite/gcc.dg/gomp/pr88415.c (working copy) @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fexceptions -fnon-call-exceptions -fopenmp -fsignaling-nans -funsafe-math-optimizations -fno-associative-math" } */ + +void +lx (_Complex int *yn) +{ + int mj; + +#pragma omp for + for (mj = 0; mj < 1; ++mj) + yn[mj] += 1; +}