https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86076
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |rguenth at gcc dot gnu.org --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- I have a patch. diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 5f6defa6fe7..e7d16ca0a14 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -6742,7 +6742,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)