From patchwork Thu Sep 8 14:04:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp263431wrt; Thu, 8 Sep 2022 07:05:53 -0700 (PDT) X-Google-Smtp-Source: AA6agR6yN4hjG2XWKHri34XOtx53KYDzai9pe1jXKwme8eFyzy4lqn8zRr3LZ+ZFzyDSlBjf0szI X-Received: by 2002:a05:6402:274e:b0:447:4e9d:69e8 with SMTP id z14-20020a056402274e00b004474e9d69e8mr7184114edd.295.1662645953323; Thu, 08 Sep 2022 07:05:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662645953; cv=none; d=google.com; s=arc-20160816; b=zChYZYOjNN9o893ZhXDwRiZXoVFQSl64PuSC1y37o62D9Nu7H+Gs3R2Wn4+W1P6TkQ T8AEZwabl2z1/zcnlngpV5d839ebf3fyUcBFmgP4xmIe2gQ9Ve9JlcrIuwwaPWs5Rr8B zyH3fXtnElMYfF87GYTfojrh4KzbFTmJw/szzTrvVpUVlHEqJZ+324edT7t2AcOmYLJV eG3zv2+UDiU43e/XOwIyW+C9u1aMADrUBgSlaL2al/AmlHuLPswlXvblgQTy3MeAiJN+ ZAZzYCVnIXxI2cZBoeJVscxTOzd5PyA6+gKg4eKZxw2IoBTN7eMXKji4r846xCtZWdbi fuhg== 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=olX324TotYGmUi9IhZrO/f6LAVw4Srya76qWjRBDQYY=; b=FqiLvkKh6+a/EX2/UmIqPwWTmqxjwpGd9YprM2OCwCCgiSvINpCnb117dY4lWLaN98 wrXVuZOCDpNN0tHQQwOdbfLxd4KIbcr2k/eyVofPdRaU2q+/x8/78P/XFNrXyxkRSnNb F1s2SKGS1VtqqCu0Ot/tHhQJIKcgXEdgu1gxHfqFFwcW2gjPD3HoWusLUsBFDLdz1oEh dO9wAGCjzDnowHjOadZ5anf76j82EJc5QUPlTNDfNe359/HQQXkafuqYEKkQRx9jfgOS TLXl8/SnjrgMfNuh4rFFEF8wQ9lPQ0UwnJ7tZcVg3ocMDvRG43pPvOyPSi3vbZ8Nnpye GgqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pBts2D8w; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g11-20020a056402180b00b0044fc3c0e53csi1982589edy.462.2022.09.08.07.05.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 07:05:53 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=pBts2D8w; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 989FA38582BE for ; Thu, 8 Sep 2022 14:05:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 989FA38582BE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662645947; bh=olX324TotYGmUi9IhZrO/f6LAVw4Srya76qWjRBDQYY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pBts2D8wqAYOg9ZqoKBIaPTbTgE4Xs5vBnxodH+dLNTwDoZL0iCV59qezFtpqd7+p KiIDfE4kCvrkstprJmpa4zzTWukWz7JDQzwCOHUqjw31wkrl+0+SA5oeYiF9vo4vpD jAa12Ywiv+g3hNNiRkWcpPfxhI6RGxUNn/cMPNZM= 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 [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E9F4038582A1 for ; Thu, 8 Sep 2022 14:04:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E9F4038582A1 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 CD5AC336AE for ; Thu, 8 Sep 2022 14:04:56 +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 B1D2113A6D for ; Thu, 8 Sep 2022 14:04:56 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GezOKYj2GWPWTQAAMHmgww (envelope-from ) for ; Thu, 08 Sep 2022 14:04:56 +0000 Date: Thu, 8 Sep 2022 16:04:56 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix some gimple_ctrl_altering_p mistakes MIME-Version: 1.0 Message-Id: <20220908140456.B1D2113A6D@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, T_SCC_BODY_TEXT_LINE 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?1743410643371050004?= X-GMAIL-MSGID: =?utf-8?q?1743410643371050004?= CFG cleanup resets the control altering flag for noreturn functions when they are ECF_LEAF (like __builtin_unreachable ()). The .ABNORMAL_DISPATCHER call built during CFG construction is not marked as control altering. Several passes inserting traps or unreachables fail to set the flag. And more. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/106870 * gimple-harden-conditionals.cc (insert_check_and_trap): Set the control-altering flag on the built IFN_TRAP. * gimple.cc (gimple_build_builtin_unreachable): Likewise. * tree-cfg.cc (handle_abnormal_edges): Set the control-altering flag on the .ABNORMAL_DISPATCHER call. * tree-cfgcleanup.cc (cleanup_call_ctrl_altering_flag): Avoid resetting the control altering flag for ECF_NORETURN calls. (cleanup_control_flow_bb): Set the control altering flag on discovered noreturn calls. * symtab-thunks.cc (expand_thunk): Set the control altering flag for the noreturn tailcall case. * tree-eh.cc (lower_resx): Likewisw for trap and unwind_resume calls. --- gcc/gimple-harden-conditionals.cc | 1 + gcc/gimple.cc | 1 + gcc/symtab-thunks.cc | 1 + gcc/tree-cfg.cc | 3 ++- gcc/tree-cfgcleanup.cc | 11 ++++++++--- gcc/tree-eh.cc | 4 +++- 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gcc/gimple-harden-conditionals.cc b/gcc/gimple-harden-conditionals.cc index 4ca6776fca7..1b3dd563baa 100644 --- a/gcc/gimple-harden-conditionals.cc +++ b/gcc/gimple-harden-conditionals.cc @@ -238,6 +238,7 @@ insert_check_and_trap (location_t loc, gimple_stmt_iterator *gsip, gimple_stmt_iterator gsit = gsi_after_labels (trp); gcall *trap = gimple_build_call (builtin_decl_explicit (BUILT_IN_TRAP), 0); + gimple_call_set_ctrl_altering (trap, true); gimple_set_location (trap, loc); gsi_insert_before (&gsit, trap, GSI_SAME_STMT); diff --git a/gcc/gimple.cc b/gcc/gimple.cc index cd5ad0c718b..4d45311b45c 100644 --- a/gcc/gimple.cc +++ b/gcc/gimple.cc @@ -440,6 +440,7 @@ gimple_build_builtin_unreachable (location_t loc) gcc_checking_assert (data == NULL_TREE); g = gimple_build_call_internal (IFN_TRAP, 0); } + gimple_call_set_ctrl_altering (g, true); gimple_set_location (g, loc); return g; } diff --git a/gcc/symtab-thunks.cc b/gcc/symtab-thunks.cc index b0439702230..bd50c689761 100644 --- a/gcc/symtab-thunks.cc +++ b/gcc/symtab-thunks.cc @@ -635,6 +635,7 @@ expand_thunk (cgraph_node *node, bool output_asm_thunks, } else { + gimple_call_set_ctrl_altering (call, true); gimple_call_set_tail (call, true); cfun->tail_call_marked = true; remove_edge (single_succ_edge (bb)); diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 3e2d0adf4a2..a939a11d8bb 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -821,8 +821,9 @@ handle_abnormal_edges (basic_block *dispatcher_bbs, basic_block for_bb, else { tree arg = inner ? boolean_true_node : boolean_false_node; - gimple *g = gimple_build_call_internal (IFN_ABNORMAL_DISPATCHER, + gcall *g = gimple_build_call_internal (IFN_ABNORMAL_DISPATCHER, 1, arg); + gimple_call_set_ctrl_altering (g, true); gimple_stmt_iterator gsi = gsi_after_labels (*dispatcher); gsi_insert_after (&gsi, g, GSI_NEW_STMT); diff --git a/gcc/tree-cfgcleanup.cc b/gcc/tree-cfgcleanup.cc index 3535a7e28a4..b4869aee78d 100644 --- a/gcc/tree-cfgcleanup.cc +++ b/gcc/tree-cfgcleanup.cc @@ -220,9 +220,10 @@ cleanup_call_ctrl_altering_flag (basic_block bb, gimple *bb_end) return; int flags = gimple_call_flags (bb_end); - if (((flags & (ECF_CONST | ECF_PURE)) - && !(flags & ECF_LOOPING_CONST_OR_PURE)) - || (flags & ECF_LEAF)) + if (!(flags & ECF_NORETURN) + && (((flags & (ECF_CONST | ECF_PURE)) + && !(flags & ECF_LOOPING_CONST_OR_PURE)) + || (flags & ECF_LEAF))) gimple_call_set_ctrl_altering (bb_end, false); else { @@ -328,6 +329,10 @@ cleanup_control_flow_bb (basic_block bb) gsi_remove (&gsi, true); if (remove_fallthru_edge (bb->succs)) retval = true; + tree lhs = gimple_call_lhs (stmt); + if (!lhs + || !should_remove_lhs_p (lhs)) + gimple_call_set_ctrl_altering (stmt, true); } return retval; diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc index 076ecd3ec9a..ae8fa21d9a3 100644 --- a/gcc/tree-eh.cc +++ b/gcc/tree-eh.cc @@ -3321,7 +3321,7 @@ lower_resx (basic_block bb, gresx *stmt, int lp_nr; eh_region src_r, dst_r; gimple_stmt_iterator gsi; - gimple *x; + gcall *x; tree fn, src_nr; bool ret = false; @@ -3346,6 +3346,7 @@ lower_resx (basic_block bb, gresx *stmt, fn = builtin_decl_implicit (BUILT_IN_TRAP); x = gimple_build_call (fn, 0); + gimple_call_set_ctrl_altering (x, true); gsi_insert_before (&gsi, x, GSI_SAME_STMT); while (EDGE_COUNT (bb->succs) > 0) @@ -3463,6 +3464,7 @@ lower_resx (basic_block bb, gresx *stmt, fn = builtin_decl_implicit (BUILT_IN_UNWIND_RESUME); x = gimple_build_call (fn, 1, var); + gimple_call_set_ctrl_altering (x, true); gsi_insert_before (&gsi, x, GSI_SAME_STMT); }