diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2025-03-15 16:37:41 -0700 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2025-03-16 11:46:06 -0700 |
commit | c5ca45b8069229b6ad9bc845f03f46340f6316d7 (patch) | |
tree | 7ffdc9cd857477ea8db9cd7c32c1e9f80fff0e09 /gcc | |
parent | 5ed0564f2879db35106272556ba91f028177c5cd (diff) | |
download | gcc-c5ca45b8069229b6ad9bc845f03f46340f6316d7.zip gcc-c5ca45b8069229b6ad9bc845f03f46340f6316d7.tar.gz gcc-c5ca45b8069229b6ad9bc845f03f46340f6316d7.tar.bz2 |
discriminators: Fix assigning discriminators on edge [PR113546]
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_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/c-c++-common/torture/pr113546-1.c | 8 | ||||
-rw-r--r-- | gcc/tree-cfg.cc | 13 |
2 files changed, 14 insertions, 7 deletions
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 0000000..74989e9 --- /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 22d43bec..2fa5678 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -168,7 +168,7 @@ static edge gimple_try_redirect_by_replacing_jump (edge, basic_block); static inline bool stmt_starts_bb_p (gimple *, gimple *); static bool 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 *); @@ -1263,7 +1263,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_nondebug_stmt (e->dest); gimple *stmt_on_same_line = NULL; @@ -2948,14 +2948,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; } |