From patchwork Fri Jul 14 08:35:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 120329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp2357979vqm; Fri, 14 Jul 2023 01:36:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlFvEYb4VkJo1DlIQCavcFlk1ijOEUsCgNeDrRPavkjce0QJ5eMAMoBC+FADv8ABak0VDKtv X-Received: by 2002:a17:906:20d1:b0:987:e23f:6d7a with SMTP id c17-20020a17090620d100b00987e23f6d7amr3948369ejc.25.1689323781063; Fri, 14 Jul 2023 01:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689323781; cv=none; d=google.com; s=arc-20160816; b=yQ6YCADAZpVCGBKO84N1X2ebPWt5blwsV8U/HtEA1WXiztYyX6vHtTG2KAXGwgvFka K8pRaHGwUImv6ofWIokWarHyTFb6C35SAEJv8TPmoYRYYPfbPALlfoSHbjD1Foh1jyqR jG8gCbiIY6X/cSP4krtqUma1ZCJqXnavdFhh6+8d0D6VJbaGq9+FldakQPQcTX93cNXU uwMPTAVU8/zTvIxgbKcItztoSPhgl1eBfzlb93bQj9xy8AGlUGZbx1KZYvOTbAHKyQxK 44StbyQ4Rowh9S6N2KA6GBaFKkTCiEenfAynFIWBwa+TwkdjoOKg4J4/D5nEnUS1NgiL sB6w== 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=ST3QFFYVRAYgytb8DAyibODHTKp6d7WSm/eflHeiGwg=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=tKFyCe00Yc12tEWftuIMBu4vU+bYQEIVM/3pxvyookEcxDfj+aNiROBQ5k9TxKEIes xkbeopvsvQwH2MQm+z3k+mA5L0+p3Sskw3vj5o0nMdTeinJYhUuPqGr/oSEkVrTwymH9 A6gK70LZN1vi8vEfEy1V3KeUmXQRzo/KF6tamajiBD6cBx/3B39dKcKrdWcAeYZLjVE3 Q+nvQ4TxQVepm6ljY0FflKbw9Hd1nAOcQENTVczrDDoJWfJ8xi4TGhsDTQ+fBzYONbby 0/6kJUJ5eQ888pLGYBTf4U5vW8UlRB5ja/OX7AskVxUFfO4aJsDehcivb7fkC4qGPrxj gZxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vKlGhqdh; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hh15-20020a170906a94f00b009930253bc69si1804554ejb.1011.2023.07.14.01.36.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 01:36:21 -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=vKlGhqdh; 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 EC2473858417 for ; Fri, 14 Jul 2023 08:36:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC2473858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689323780; bh=ST3QFFYVRAYgytb8DAyibODHTKp6d7WSm/eflHeiGwg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vKlGhqdhVSf6ZUvj1/DfgJZestfF212xeTXL0xb87PNbxtxl53ga5pFhc7fY6pEVe a2YDhmV4K0+a0x85QjYOhITKrYJdr2L0Knwe5yy9so6gk9zSkNDkgamR7/3b0vxZ7E fEwAYpPtmP3zLwa74nd2gKMsGMeuYd/NRcH2IOtw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id DBDE23858CDB for ; Fri, 14 Jul 2023 08:35:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DBDE23858CDB 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-out2.suse.de (Postfix) with ESMTPS id 11E901FDAB for ; Fri, 14 Jul 2023 08:35:31 +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 F2E79138F8 for ; Fri, 14 Jul 2023 08:35:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id hYUaOtIIsWREWQAAMHmgww (envelope-from ) for ; Fri, 14 Jul 2023 08:35:30 +0000 Date: Fri, 14 Jul 2023 10:35:30 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Provide extra checking for phi argument access from edge MIME-Version: 1.0 Message-Id: <20230714083530.F2E79138F8@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.5 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: INBOX X-GMAIL-THRID: 1771384373065678156 X-GMAIL-MSGID: 1771384373065678156 The following adds checking that the edge we query an associated PHI arg for is related to the PHI node. Triggered by questionable code in one of my reviews. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. * gimple.h (gimple_phi_arg): New const overload. (gimple_phi_arg_def): Make gimple arg const. (gimple_phi_arg_def_from_edge): New inline function. * tree-phinodes.h (gimple_phi_arg_imm_use_ptr_from_edge): Likewise. * tree-ssa-operands.h (PHI_ARG_DEF_FROM_EDGE): Direct to new inline function. (PHI_ARG_DEF_PTR_FROM_EDGE): Likewise. --- gcc/gimple.h | 25 ++++++++++++++++++++++++- gcc/tree-phinodes.h | 7 +++++++ gcc/tree-ssa-operands.h | 4 ++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/gcc/gimple.h b/gcc/gimple.h index daf55242f68..d3750f95d79 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -4633,6 +4633,13 @@ gimple_phi_arg (const gphi *gs, unsigned index) return &(gs->args[index]); } +inline const phi_arg_d * +gimple_phi_arg (const gimple *gs, unsigned index) +{ + const gphi *phi_stmt = as_a (gs); + return gimple_phi_arg (phi_stmt, index); +} + inline struct phi_arg_d * gimple_phi_arg (gimple *gs, unsigned index) { @@ -4678,11 +4685,27 @@ gimple_phi_arg_def (const gphi *gs, size_t index) } inline tree -gimple_phi_arg_def (gimple *gs, size_t index) +gimple_phi_arg_def (const gimple *gs, size_t index) { return gimple_phi_arg (gs, index)->def; } +/* Return the tree operand for the argument associated with + edge E of PHI node GS. */ + +inline tree +gimple_phi_arg_def_from_edge (const gphi *gs, const_edge e) +{ + gcc_checking_assert (e->dest == gimple_bb (gs)); + return gimple_phi_arg (gs, e->dest_idx)->def; +} + +inline tree +gimple_phi_arg_def_from_edge (const gimple *gs, const_edge e) +{ + gcc_checking_assert (e->dest == gimple_bb (gs)); + return gimple_phi_arg (gs, e->dest_idx)->def; +} /* Return a pointer to the tree operand for argument I of phi node PHI. */ diff --git a/gcc/tree-phinodes.h b/gcc/tree-phinodes.h index 932a461e987..be114e317b4 100644 --- a/gcc/tree-phinodes.h +++ b/gcc/tree-phinodes.h @@ -37,6 +37,13 @@ gimple_phi_arg_imm_use_ptr (gimple *gs, int i) return &gimple_phi_arg (gs, i)->imm_use; } +inline use_operand_p +gimple_phi_arg_imm_use_ptr_from_edge (gimple *gs, const_edge e) +{ + gcc_checking_assert (e->dest == gimple_bb (gs)); + return &gimple_phi_arg (gs, e->dest_idx)->imm_use; +} + /* Return the phi argument which contains the specified use. */ inline int diff --git a/gcc/tree-ssa-operands.h b/gcc/tree-ssa-operands.h index ae36bcdb893..c7b74e046d0 100644 --- a/gcc/tree-ssa-operands.h +++ b/gcc/tree-ssa-operands.h @@ -83,9 +83,9 @@ struct GTY(()) ssa_operands { #define SET_PHI_ARG_DEF(PHI, I, V) \ SET_USE (PHI_ARG_DEF_PTR ((PHI), (I)), (V)) #define PHI_ARG_DEF_FROM_EDGE(PHI, E) \ - PHI_ARG_DEF ((PHI), (E)->dest_idx) + gimple_phi_arg_def_from_edge ((PHI), (E)) #define PHI_ARG_DEF_PTR_FROM_EDGE(PHI, E) \ - PHI_ARG_DEF_PTR ((PHI), (E)->dest_idx) + gimple_phi_arg_imm_use_ptr_from_edge ((PHI), (E)) #define PHI_ARG_INDEX_FROM_USE(USE) phi_arg_index_from_use (USE)