public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/106422 - verify block copying in forward threading
@ 2022-07-29  8:47 Richard Biener
  2022-07-30 15:31 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Biener @ 2022-07-29  8:47 UTC (permalink / raw)
  To: gcc-patches

The forward threader failed to check whether it can actually duplicate
blocks.  The following adds this in a similar place the backwards threader
performs this check.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/106422
	* tree-ssa-threadupdate.cc (fwd_jt_path_registry::update_cfg):
	Check whether we can copy thread blocks and cancel the thread if not.

	* gcc.dg/torture/pr106422.c: New testcase.
---
 gcc/testsuite/gcc.dg/torture/pr106422.c | 14 ++++++++++++++
 gcc/tree-ssa-threadupdate.cc            |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr106422.c

diff --git a/gcc/testsuite/gcc.dg/torture/pr106422.c b/gcc/testsuite/gcc.dg/torture/pr106422.c
new file mode 100644
index 00000000000..a2cef1aecb6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr106422.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+
+void vfork() __attribute__((__leaf__));
+void semanage_reload_policy(char *arg, void cb(void))
+{
+  if (!arg)
+    {
+      cb();
+      return;
+    }
+  vfork();
+  if (arg)
+    __builtin_free(arg);
+}
diff --git a/gcc/tree-ssa-threadupdate.cc b/gcc/tree-ssa-threadupdate.cc
index f901c7759e3..0f2b319d44a 100644
--- a/gcc/tree-ssa-threadupdate.cc
+++ b/gcc/tree-ssa-threadupdate.cc
@@ -2678,7 +2678,9 @@ fwd_jt_path_registry::update_cfg (bool may_peel_loop_headers)
 	for (j = 0; j < path->length (); j++)
 	  {
 	    edge e = (*path)[j]->e;
-	    if (m_removed_edges->find_slot (e, NO_INSERT))
+	    if (m_removed_edges->find_slot (e, NO_INSERT)
+		|| ((*path)[j]->type == EDGE_COPY_SRC_BLOCK
+		    && !can_duplicate_block_p (e->src)))
 	      break;
 	  }
 
-- 
2.35.3

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] tree-optimization/106422 - verify block copying in forward threading
  2022-07-29  8:47 [PATCH] tree-optimization/106422 - verify block copying in forward threading Richard Biener
@ 2022-07-30 15:31 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2022-07-30 15:31 UTC (permalink / raw)
  To: gcc-patches



On 7/29/2022 2:47 AM, Richard Biener via Gcc-patches wrote:
> The forward threader failed to check whether it can actually duplicate
> blocks.  The following adds this in a similar place the backwards threader
> performs this check.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
>
> 	PR tree-optimization/106422
> 	* tree-ssa-threadupdate.cc (fwd_jt_path_registry::update_cfg):
> 	Check whether we can copy thread blocks and cancel the thread if not.
>
> 	* gcc.dg/torture/pr106422.c: New testcase.
I'm back from PTO.  This looks obviously correct to me.

jeff


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-30 15:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29  8:47 [PATCH] tree-optimization/106422 - verify block copying in forward threading Richard Biener
2022-07-30 15:31 ` Jeff Law

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).