From patchwork Mon Nov 28 07:59:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 26575 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp5498978wrr; Mon, 28 Nov 2022 00:00:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf7xzsdEJ29OYrWni38jpMnH/v1vKNkLP9YE0ruqvbV3uIjS5ZfZNyux6MaGyEpIMresYaCS X-Received: by 2002:a17:906:eb17:b0:7ae:87ef:d9a6 with SMTP id mb23-20020a170906eb1700b007ae87efd9a6mr26450515ejb.397.1669622428205; Mon, 28 Nov 2022 00:00:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669622428; cv=none; d=google.com; s=arc-20160816; b=zhY3MMM2nDfFMPbHx7zEH5BPrhsouTv8DVn/IXfIO5nTNrF6eudEMVDE4gaeJV4G8G qU0ELA7zYljurePTicXBBx9kzdFGe6IW/GimgDumVZzMP8FykM4iSPiKkcgKFH94K6SU k2vRdPGAOI7gp0gRLXaqxfgF96jqVoBuFF5vZWQQFdBVZWqEoxbmzsiqWWEZV7t3sWgm u3FHWHBPZxhx1DCAhT8r0y27va+c8Pu+3QDTw3xcpTFBMVQv/UeJNLbXBah61Xf0STpy jjpyB24olfO2Z0lipNpYA1ZMr/xZVbms77CpCRzQCoMUpRqsj3J8SKEP/OzyfpHNgNFS db2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=NVfS5LgX7s3Mds8deM320oRCJVEY/RC+RDPhzG4v+Ss=; b=x7G4WXuS9X9zTtCRptJ0ug7Xe3s5+gQMAVXf/A8KAKcIVOpf+cGDq/3LAgbCwzobVJ SBzt192I58OnR8VylYwy/A+XPtcgGBDhuhM5LbxOk7F5VZl5Hs0LFrk1q09Y65NCmT5y DcDuZMFtcLrxAp2PJUHSfyW0Q9xrEPHv2vtTED+R0HacouTQ1E7AmaedSELjefd6JHHT 5GuDCxu9Uo/Okdy0Zif8roq0xUYai2CpWiFb9oW7kBMjFtu42YrCrruQks87o3TlL9Va UBJHG5/5yZq9bHM/29wVpXF0EYWVyA6yUem50X34fZwD5u93BWbC8jedzqL5n0RU7POe OKvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="EFzJ/MgV"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hs4-20020a1709073e8400b0078db3ce1e59si9897518ejc.38.2022.11.28.00.00.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 00:00:28 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="EFzJ/MgV"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3C902385842B for ; Mon, 28 Nov 2022 08:00:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C902385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669622427; bh=NVfS5LgX7s3Mds8deM320oRCJVEY/RC+RDPhzG4v+Ss=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=EFzJ/MgVNm9LgB+ZHMj9ifxBtdqrt8hzFxv+CFZWugl3yyrmcZe5U3TBaISSLCOlR +A9whmpqB0ADkL3oDoIyjfCouY1kmNyMAOUr8ofsIKDoRppbYVPmfvAZU33AfUZsBI hQnVkdbZo0tJKkGxyfzH0dMM3QWwRrg3UMntVNFc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 6B08F3858CDB for ; Mon, 28 Nov 2022 07:59:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6B08F3858CDB Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3675C21A54 for ; Mon, 28 Nov 2022 07:59:44 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 239B11326E for ; Mon, 28 Nov 2022 07:59:44 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id /ctxB3BqhGN6TwAAMHmgww (envelope-from ) for ; Mon, 28 Nov 2022 07:59:44 +0000 Date: Mon, 28 Nov 2022 08:59:43 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107867 - failed abnormal cleanup in forwprop MIME-Version: 1.0 Message-Id: <20221128075944.239B11326E@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750726007373122925?= X-GMAIL-MSGID: =?utf-8?q?1750726007373122925?= 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 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;