diff --git a/gcc/testsuite/gcc.dg/torture/pr108076.c b/gcc/testsuite/gcc.dg/torture/pr108076.c new file mode 100644 index 0000000000000000000000000000000000000000..ebe2e51bee052fce50c0fbd1d7a14d406cd3a98f --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108076.c @@ -0,0 +1,17 @@ +/* { dg-do link } */ + +static void *j; +int v, g; +__attribute__((__leaf__)) int atoi (const char *); + +int +main () +{ + j = &&lab1; + &&lab2; + atoi ("42"); +lab1: +lab2: + if (v) + goto *j; +} diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 64b20b4a9e11fe53d7a4bd188c514fdf759b3f3b..0807201cefbdb0f9889a5e4cda56d9f2477c2071 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<data_reference_p> *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 <glabel *> (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)))