]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
discriminators: Fix assigning discriminators on edge [PR113546]
authorAndrew Pinski <quic_apinski@quicinc.com>
Sat, 15 Mar 2025 23:37:41 +0000 (16:37 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Sun, 16 Mar 2025 18:46:06 +0000 (11:46 -0700)
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>
gcc/testsuite/c-c++-common/torture/pr113546-1.c [new file with mode: 0644]
gcc/tree-cfg.cc

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 (file)
index 0000000..74989e9
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-fcompare-debug" } */
+
+int x;
+void f() {
+fail:
+  switch (x) { case 0: goto fail;; }
+}
index 22d43becfd4831cd2a367954b32b452332745c7c..2fa5678051add868b6498e32e7c9ee25afc41257 100644 (file)
@@ -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;
 }