From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id C01E8385B18D; Mon, 28 Nov 2022 08:00:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C01E8385B18D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669622440; bh=xb3iGdAeUuHA4+UEyML+GXer3/4Kv2cRrzJvRaS8XWk=; h=From:To:Subject:Date:From; b=dX1XNLPdzWoCiDh+G+ZKV9Fc2/oT0TxmeIYUH1m1IMcsvwRZCaLNEK4rxdUHo50JU drSCEGKkfmoPehZRXYONUqUnllmnVwCLiT3FWIxB5rLGBgJubU6Dnw/2xO3pyLJyTD ssPetw5jdOERsVG+W3ha08noxuaW64j+edX7xQWU= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4316] tree-optimization/107867 - failed abnormal cleanup in forwprop X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: be591d00ed6cf8ac13850d5490749651acf10139 X-Git-Newrev: 0976b012d89e3d819d83cdaf0dab05925b3eb3a0 Message-Id: <20221128080040.C01E8385B18D@sourceware.org> Date: Mon, 28 Nov 2022 08:00:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0976b012d89e3d819d83cdaf0dab05925b3eb3a0 commit r13-4316-g0976b012d89e3d819d83cdaf0dab05925b3eb3a0 Author: Richard Biener Date: Fri Nov 25 13:53:14 2022 +0100 tree-optimization/107867 - failed abnormal cleanup in forwprop The following makes sure to perform abnormal cleanup when forwprop propagates into a call. PR tree-optimization/107867 * tree-ssa-forwprop.cc (pass_forwprop::execute): Handle abnormal cleanup after substitution. * g++.dg/pr107867.C: New testcase. Diff: --- gcc/testsuite/g++.dg/pr107867.C | 19 +++++++++++++++++++ gcc/tree-ssa-forwprop.cc | 10 ++++++++++ 2 files changed, 29 insertions(+) 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 to_fixup; auto_vec 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;