The problem here is there was a compare debug since the discriminators would still take into account debug statements. For the edge we would look at the first statement after the labels and that might have been a debug statement. So we need to skip over debug statements otherwise we could get different discriminators # with and without -g.
Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR middle-end/113546 gcc/ChangeLog: * tree-cfg.cc (first_non_label_stmt): Rename to ... (first_non_label_nondebug_stmt): This and use gsi_start_nondebug_after_labels_bb. (assign_discriminators): Update call to first_non_label_nondebug_stmt. gcc/testsuite/ChangeLog: * c-c++-common/torture/pr113546-1.c: New test. Signed-off-by: Andrew Pinski <quic_apin...@quicinc.com> (cherry picked from commit c5ca45b8069229b6ad9bc845f03f46340f6316d7) --- gcc/testsuite/c-c++-common/torture/pr113546-1.c | 8 ++++++++ gcc/tree-cfg.cc | 13 ++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/torture/pr113546-1.c diff --git a/gcc/testsuite/c-c++-common/torture/pr113546-1.c b/gcc/testsuite/c-c++-common/torture/pr113546-1.c new file mode 100644 index 00000000000..74989e992cd --- /dev/null +++ b/gcc/testsuite/c-c++-common/torture/pr113546-1.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-fcompare-debug" } */ + +int x; +void f() { +fail: + switch (x) { case 0: goto fail;; } +} diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 98c6a0d06b8..180eceac7c9 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -167,7 +167,7 @@ static edge gimple_try_redirect_by_replacing_jump (edge, basic_block); static inline bool stmt_starts_bb_p (gimple *, gimple *); static int gimple_verify_flow_info (void); static void gimple_make_forwarder_block (edge); -static gimple *first_non_label_stmt (basic_block); +static gimple *first_non_label_nondebug_stmt (basic_block); static bool verify_gimple_transaction (gtransaction *); static bool call_can_make_abnormal_goto (gimple *); @@ -1246,7 +1246,7 @@ assign_discriminators (void) FOR_EACH_EDGE (e, ei, bb->succs) { - gimple *first = first_non_label_stmt (e->dest); + gimple *first = first_non_label_nondebug_stmt (e->dest); gimple *last = last_stmt (e->dest); gimple *stmt_on_same_line = NULL; @@ -2936,14 +2936,13 @@ first_stmt (basic_block bb) return stmt; } -/* Return the first non-label statement in basic block BB. */ +/* Return the first non-label/non-debug statement in basic block BB. */ static gimple * -first_non_label_stmt (basic_block bb) +first_non_label_nondebug_stmt (basic_block bb) { - gimple_stmt_iterator i = gsi_start_bb (bb); - while (!gsi_end_p (i) && gimple_code (gsi_stmt (i)) == GIMPLE_LABEL) - gsi_next (&i); + gimple_stmt_iterator i; + i = gsi_start_nondebug_after_labels_bb (bb); return !gsi_end_p (i) ? gsi_stmt (i) : NULL; } -- 2.43.0