r16-5250-g88db06d7da393f901 changed which block was doing the
check on the label being a non-local dest or an eh landing pad.
Which is fine except then when we move labels we moved them to
before the label for the non-local dest/eh landing pad.
This can be fixed a few different ways.
Add back the check for the dest block or change where the other
labels are placed.
Since this case does not happen enough to care either way, I added
back the check for the dest block. This means there is no changes
from GCC 15 to now.
Bootstrapped and tested on x86_64-linux-gnu.
PR tree-optimization/123110
gcc/ChangeLog:
* tree-cfgcleanup.cc (maybe_remove_forwarder_block): Add back
check for eh landing pad or non-local dest on the dest.
gcc/testsuite/ChangeLog:
* gcc.dg/pr123110-1.c: New test.
Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Os -fexceptions -finstrument-functions-once" } */
+/* PR tree-optimization/123110 */
+
+/* Make sure forwarder blocks (with labels) to eh landing pads are handled
+ correctly. */
+
+void baz ();
+
+int g, h;
+
+static inline __attribute__((__always_inline__)) void
+bar (int *out_base)
+{
+ if (!g)
+ {
+ baz ();
+ switch (h)
+ ;
+ return;
+ }
+fail:
+ *out_base = 0;
+}
+
+void
+foo ()
+{
+ unsigned base;
+ bar (&base);
+}
bool has_phi = !gimple_seq_empty_p (phi_nodes (bb));
basic_block dest = single_succ_edge (bb)->dest;
+ /* If the destination block consists of a nonlocal label or is a
+ EH landing pad, do not merge it. */
+ if (glabel *label_stmt = safe_dyn_cast <glabel *> (first_stmt (dest)))
+ if (DECL_NONLOCAL (gimple_label_label (label_stmt))
+ || EH_LANDING_PAD_NR (gimple_label_label (label_stmt)))
+ return false;
+
/* If there is an abnormal edge to basic block BB, but not into
dest, problems might occur during removal of the phi node at out
of ssa due to overlapping live ranges of registers.