public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4229] tree-optimization/107803 - abnormal cleanup from the SSA propagator
@ 2022-11-22 11:05 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2022-11-22 11:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e4faee8d02ec5d65bf418612f7181823eb08c078

commit r13-4229-ge4faee8d02ec5d65bf418612f7181823eb08c078
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Nov 22 10:16:14 2022 +0100

    tree-optimization/107803 - abnormal cleanup from the SSA propagator
    
    The SSA propagator is missing abnormal cleanup which shows in a
    sanity check in the uninit engine (and missed CFG verification).
    The following adds that.
    
            PR tree-optimization/107803
            * tree-ssa-propagate.cc (substitute_and_fold_dom_walker): Add
            need_ab_cleanup member.
            (substitute_and_fold_dom_walker::before_dom_children): When
            a stmt can no longer transfer control flow abnormally set
            need_ab_cleanup.
            (substitute_and_fold_engine::substitute_and_fold): Cleanup
            abnormal control flow.
    
            * g++.dg/pr107803.C: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/pr107803.C | 19 +++++++++++++++++++
 gcc/tree-ssa-propagate.cc       | 20 ++++++++++++++++++--
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/gcc/testsuite/g++.dg/pr107803.C b/gcc/testsuite/g++.dg/pr107803.C
new file mode 100644
index 00000000000..f814e968b69
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr107803.C
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-O -fno-tree-dominator-opts -fno-tree-fre -Wmaybe-uninitialized" }
+
+void printf(...);
+void __sigsetjmp_cancel() __attribute__((__returns_twice__));
+int z, main_ret;
+void func(void *) {}
+
+int
+main()
+{
+  int x;
+  void (*__cancel_routine)(void *)(func);
+  __sigsetjmp_cancel();
+  __cancel_routine(0);
+  if (main_ret)
+    x = z;
+  printf(x);
+}
diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc
index 9dc4bfd85bf..d8b0aed4564 100644
--- a/gcc/tree-ssa-propagate.cc
+++ b/gcc/tree-ssa-propagate.cc
@@ -671,12 +671,14 @@ public:
       stmts_to_remove.create (0);
       stmts_to_fixup.create (0);
       need_eh_cleanup = BITMAP_ALLOC (NULL);
+      need_ab_cleanup = BITMAP_ALLOC (NULL);
     }
     ~substitute_and_fold_dom_walker ()
     {
       stmts_to_remove.release ();
       stmts_to_fixup.release ();
       BITMAP_FREE (need_eh_cleanup);
+      BITMAP_FREE (need_ab_cleanup);
     }
 
     edge before_dom_children (basic_block) final override;
@@ -689,6 +691,7 @@ public:
     vec<gimple *> stmts_to_remove;
     vec<gimple *> stmts_to_fixup;
     bitmap need_eh_cleanup;
+    bitmap need_ab_cleanup;
 
     class substitute_and_fold_engine *substitute_and_fold_engine;
 
@@ -838,8 +841,13 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
 	 folded.  */
       did_replace = false;
       gimple *old_stmt = stmt;
-      bool was_noreturn = (is_gimple_call (stmt)
-			   && gimple_call_noreturn_p (stmt));
+      bool was_noreturn = false;
+      bool can_make_abnormal_goto = false;
+      if (is_gimple_call (stmt))
+	{
+	  was_noreturn = gimple_call_noreturn_p (stmt);
+	  can_make_abnormal_goto = stmt_can_make_abnormal_goto (stmt);
+	}
 
       /* Replace real uses in the statement.  */
       did_replace |= substitute_and_fold_engine->replace_uses_in (stmt);
@@ -905,6 +913,12 @@ substitute_and_fold_dom_walker::before_dom_children (basic_block bb)
 	  if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
 	    bitmap_set_bit (need_eh_cleanup, bb->index);
 
+	  /* If we turned a call with possible abnormal control transfer
+	     into one that doesn't, remove abnormal edges.  */
+	  if (can_make_abnormal_goto
+	      && !stmt_can_make_abnormal_goto (stmt))
+	    bitmap_set_bit (need_ab_cleanup, bb->index);
+
 	  /* If we turned a not noreturn call into a noreturn one
 	     schedule it for fixup.  */
 	  if (!was_noreturn
@@ -1012,6 +1026,8 @@ substitute_and_fold_engine::substitute_and_fold (basic_block block)
 
   if (!bitmap_empty_p (walker.need_eh_cleanup))
     gimple_purge_all_dead_eh_edges (walker.need_eh_cleanup);
+  if (!bitmap_empty_p (walker.need_ab_cleanup))
+    gimple_purge_all_dead_abnormal_call_edges (walker.need_ab_cleanup);
 
   /* Fixup stmts that became noreturn calls.  This may require splitting
      blocks and thus isn't possible during the dominator walk.  Do this

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

only message in thread, other threads:[~2022-11-22 11:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 11:05 [gcc r13-4229] tree-optimization/107803 - abnormal cleanup from the SSA propagator Richard Biener

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