From b4fddbe9592e9feb37ce567d90af822b75995531 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 12 Dec 2022 17:52:46 +0100 Subject: tree-optimization/108076 - if-conversion and forced labels When doing if-conversion we simply throw away labels without checking whether they are possibly targets of non-local gotos or have their address taken. The following rectifies this and refuses to if-convert such loops. PR tree-optimization/108076 * tree-if-conv.cc (if_convertible_loop_p_1): Reject blocks with non-local or forced labels that we later remove labels from. * gcc.dg/torture/pr108076.c: New testcase. --- gcc/tree-if-conv.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'gcc/tree-if-conv.cc') diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 64b20b4..0807201 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -1433,10 +1433,20 @@ if_convertible_loop_p_1 (class loop *loop, vec *refs) basic_block bb = ifc_bbs[i]; gimple_stmt_iterator gsi; + bool may_have_nonlocal_labels + = bb_with_exit_edge_p (loop, bb) || bb == loop->latch; for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) switch (gimple_code (gsi_stmt (gsi))) { case GIMPLE_LABEL: + if (!may_have_nonlocal_labels) + { + tree label + = gimple_label_label (as_a (gsi_stmt (gsi))); + if (DECL_NONLOCAL (label) || FORCED_LABEL (label)) + return false; + } + /* Fallthru. */ case GIMPLE_ASSIGN: case GIMPLE_CALL: case GIMPLE_DEBUG: @@ -2627,8 +2637,8 @@ remove_conditions_and_labels (loop_p loop) basic_block bb = ifc_bbs[i]; if (bb_with_exit_edge_p (loop, bb) - || bb == loop->latch) - continue; + || bb == loop->latch) + continue; for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); ) switch (gimple_code (gsi_stmt (gsi))) -- cgit v1.1