public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r9-9423] tree-cfg: Fix up gimple_merge_blocks FORCED_LABEL handling [PR99034]
@ 2021-04-20 23:32 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-20 23:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8a6114146001eafc1921b60e40bf5c0e4f4b8e64

commit r9-9423-g8a6114146001eafc1921b60e40bf5c0e4f4b8e64
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Feb 19 12:14:39 2021 +0100

    tree-cfg: Fix up gimple_merge_blocks FORCED_LABEL handling [PR99034]
    
    The verifiers require that DECL_NONLOCAL or EH_LANDING_PAD_NR
    labels are always the first label if there is more than one label.
    
    When merging blocks, we don't honor that though.
    On the following testcase, we try to merge blocks:
    <bb 13> [count: 0]:
    <L2>:
    S::~S (&s);
    
    and
    <bb 15> [count: 0]:
    <L0>:
    resx 1
    
    where <L2> is landing pad and <L0> is FORCED_LABEL.  And the code puts
    the FORCED_LABEL before the landing pad label, violating the verification
    requirements.
    
    The following patch fixes it by moving the FORCED_LABEL after the
    DECL_NONLOCAL or EH_LANDING_PAD_NR label if it is the first label.
    
    2021-02-19  Jakub Jelinek  <jakub@redhat.com>
    
            PR ipa/99034
            * tree-cfg.c (gimple_merge_blocks): If bb a starts with eh landing
            pad or non-local label, put FORCED_LABELs from bb b after that label
            rather than before it.
    
            * g++.dg/opt/pr99034.C: New test.
    
    (cherry picked from commit 33be24d77d3d8f0c992eb344ce63f78e14cf753d)

Diff:
---
 gcc/testsuite/g++.dg/opt/pr99034.C | 23 +++++++++++++++++++++++
 gcc/tree-cfg.c                     | 12 +++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/opt/pr99034.C b/gcc/testsuite/g++.dg/opt/pr99034.C
new file mode 100644
index 00000000000..d791a14b136
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr99034.C
@@ -0,0 +1,23 @@
+// PR ipa/99034
+// { dg-do compile }
+// { dg-options "-O2" }
+
+void *b[5];
+void foo (void);
+struct S { ~S (); };
+
+static inline void
+__attribute__((always_inline))
+bar (int d)
+{
+  S s;
+  while (d)
+    foo ();
+}
+
+void
+baz (void)
+{
+  bar (2);
+  __builtin_setjmp (b);
+}
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index d72e60edd0a..d52ea2c8438 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -2128,7 +2128,17 @@ gimple_merge_blocks (basic_block a, basic_block b)
 	  if (FORCED_LABEL (label))
 	    {
 	      gimple_stmt_iterator dest_gsi = gsi_start_bb (a);
-	      gsi_insert_before (&dest_gsi, stmt, GSI_NEW_STMT);
+	      tree first_label = NULL_TREE;
+	      if (!gsi_end_p (dest_gsi))
+		if (glabel *first_label_stmt
+		    = dyn_cast <glabel *> (gsi_stmt (dest_gsi)))
+		  first_label = gimple_label_label (first_label_stmt);
+	      if (first_label
+		  && (DECL_NONLOCAL (first_label)
+		      || EH_LANDING_PAD_NR (first_label) != 0))
+		gsi_insert_after (&dest_gsi, stmt, GSI_NEW_STMT);
+	      else
+		gsi_insert_before (&dest_gsi, stmt, GSI_NEW_STMT);
 	    }
 	  /* Other user labels keep around in a form of a debug stmt.  */
 	  else if (!DECL_ARTIFICIAL (label) && MAY_HAVE_DEBUG_BIND_STMTS)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-04-20 23:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 23:32 [gcc r9-9423] tree-cfg: Fix up gimple_merge_blocks FORCED_LABEL handling [PR99034] Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).