From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-optimization/107867 - failed abnormal cleanup in forwprop
Date: Mon, 28 Nov 2022 08:59:43 +0100 (CET) [thread overview]
Message-ID: <20221128075944.239B11326E@imap2.suse-dmz.suse.de> (raw)
The following makes sure to perform abnormal cleanup when forwprop
propagates into a call.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/107867
* tree-ssa-forwprop.cc (pass_forwprop::execute): Handle
abnormal cleanup after substitution.
* g++.dg/pr107867.C: New testcase.
---
gcc/testsuite/g++.dg/pr107867.C | 19 +++++++++++++++++++
gcc/tree-ssa-forwprop.cc | 10 ++++++++++
2 files changed, 29 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/pr107867.C
diff --git a/gcc/testsuite/g++.dg/pr107867.C b/gcc/testsuite/g++.dg/pr107867.C
new file mode 100644
index 00000000000..16c7499cf7b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr107867.C
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-Os -fno-tree-ccp -Wuninitialized" }
+
+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-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 429f77f199c..160e49e097e 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -3367,6 +3367,7 @@ pass_forwprop::execute (function *fun)
auto_vec<gimple *, 4> to_fixup;
auto_vec<gimple *, 32> to_remove;
to_purge = BITMAP_ALLOC (NULL);
+ bitmap need_ab_cleanup = BITMAP_ALLOC (NULL);
for (int i = 0; i < postorder_num; ++i)
{
gimple_stmt_iterator gsi;
@@ -3682,6 +3683,9 @@ pass_forwprop::execute (function *fun)
/* Mark stmt as potentially needing revisiting. */
gimple_set_plf (stmt, GF_PLF_1, false);
+ bool can_make_abnormal_goto = (is_gimple_call (stmt)
+ && stmt_can_make_abnormal_goto (stmt));
+
/* Substitute from our lattice. We need to do so only once. */
bool substituted_p = false;
use_operand_p usep;
@@ -3700,6 +3704,10 @@ pass_forwprop::execute (function *fun)
&& is_gimple_assign (stmt)
&& gimple_assign_rhs_code (stmt) == ADDR_EXPR)
recompute_tree_invariant_for_addr_expr (gimple_assign_rhs1 (stmt));
+ if (substituted_p
+ && can_make_abnormal_goto
+ && !stmt_can_make_abnormal_goto (stmt))
+ bitmap_set_bit (need_ab_cleanup, bb->index);
bool changed;
do
@@ -3901,7 +3909,9 @@ pass_forwprop::execute (function *fun)
}
cfg_changed |= gimple_purge_all_dead_eh_edges (to_purge);
+ cfg_changed |= gimple_purge_all_dead_abnormal_call_edges (need_ab_cleanup);
BITMAP_FREE (to_purge);
+ BITMAP_FREE (need_ab_cleanup);
if (cfg_changed)
todoflags |= TODO_cleanup_cfg;
--
2.35.3
reply other threads:[~2022-11-28 7:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221128075944.239B11326E@imap2.suse-dmz.suse.de \
--to=rguenther@suse.de \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).