From 5b32ec103973c3b8f537c6e50fc8d954f27286de Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 15 Jun 2018 07:25:13 +0000 Subject: [PATCH] re PR tree-optimization/86076 (ICE: verify_gimple failed (error: location references block not in block tree)) 2018-06-15 Richard Biener PR middle-end/86076 * tree-cfg.c (move_stmt_op): unshare invariant addresses before adjusting their block. * gcc.dg/pr86076.c: New testcase. From-SVN: r261620 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr86076.c | 26 ++++++++++++++++++++++++++ gcc/tree-cfg.c | 11 ++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr86076.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e9499b24d79..8f95eb582f7 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-06-15 Richard Biener + + PR middle-end/86076 + * tree-cfg.c (move_stmt_op): unshare invariant addresses + before adjusting their block. + 2018-06-15 Sebastian Huber * config.gcc (riscv*-*-elf* | riscv*-*-rtems*): Use custom diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 94c4fcaa11f..04278c6dcf0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-15 Richard Biener + + PR middle-end/86076 + * gcc.dg/pr86076.c: New testcase. + 2018-06-14 Marek Polacek PR c++/86063 diff --git a/gcc/testsuite/gcc.dg/pr86076.c b/gcc/testsuite/gcc.dg/pr86076.c new file mode 100644 index 00000000000..019ced3cbf5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr86076.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-parallelize-loops=2 -fno-tree-dce -fno-tree-pre -fno-tree-vrp --param max-loop-header-insns=1" } */ + +int __attribute__ ((noinline)) +lv (int tm) +{ + (void) tm; + + return 0; +} + +void +o7 (int uu) +{ + while (uu < 1) + while (uu != 0) + { + short int ca; + + ca = lv (0); + (void) ca; + ++uu; + } + + lv (lv (0)); +} diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 21b3fdffa59..78d80b00045 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -6745,7 +6745,16 @@ move_stmt_op (tree *tp, int *walk_subtrees, void *data) ; else if (block == p->orig_block || p->orig_block == NULL_TREE) - TREE_SET_BLOCK (t, p->new_block); + { + /* tree_node_can_be_shared says we can share invariant + addresses but unshare_expr copies them anyways. Make sure + to unshare before adjusting the block in place - we do not + always see a copy here. */ + if (TREE_CODE (t) == ADDR_EXPR + && is_gimple_min_invariant (t)) + *tp = t = unshare_expr (t); + TREE_SET_BLOCK (t, p->new_block); + } else if (flag_checking) { while (block && TREE_CODE (block) == BLOCK && block != p->orig_block) -- 2.30.2