From patchwork Tue Jan 3 09:35:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 38335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4524489wrt; Tue, 3 Jan 2023 01:39:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXuzrjwx7IOD2O5dMdcMWWWC6mVscIyMzR0dA7AnHvGo2khLTfp8+9EK3nYVtJvNzfp2NKqP X-Received: by 2002:a05:6402:2296:b0:46a:96b3:22bf with SMTP id cw22-20020a056402229600b0046a96b322bfmr46494423edb.17.1672738743069; Tue, 03 Jan 2023 01:39:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672738743; cv=none; d=google.com; s=arc-20160816; b=INxJvCiMbsftiKHbSB0CFP5EUyeptVgZFwUma5sgBY2q8tK8q8qq4tF28xAoNyrcR+ qgjK1IMdI0j2GJ2gb5ydFFYQEjmfd6vM33TzePQGZXLwBPK0Y4Zaaw/JQEqSqQmkUKH9 CRQ8bbWY5qCBiieCtevE3WYnYS6qfjPNoBGLLZUPzoJhadYJ+9sLIdBqOwx1zH71Q4O0 gIrx4fXdTxhkoykAUeIBfo7nUI1zDGM7ZhiRYetA5wXC6mM8hK/w/p/BhpKEAwLUI9y2 FRWiEXzOft18W9ffYEZv4TmBUZyf4vifjToop0yVH/OKy20R1fC7ut1BHUDvucOMFCEZ XGXQ== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:delivered-to:dkim-signature:dkim-filter; bh=YKC5aO+3mcvZcziCTNqB+B+CoZCb8KPK6tb8A5DlntA=; b=GRdLbh2ddiP3m7Px39HJ0csWr14lZV8cVLBYhYSjtu3WwexlLmoHTKZc4fmDt0CtsW HKJ7t8Vs+EhsgtYksG/BLHnQPEcvMMCzMvFcvaRZn+qA0l98ehZ07g3aSFvEqgDgHM1p KnhFmzQtcaeSQeOwbzNbKllD2VMvEv84kxhhq4qL8oUMnEhSgu3bpRSESsMnpeWHu/1m FDfvhX3p7ogwtbR03yZdy77keiku1J/w0BJuX9HwKWVpIqdTw0+TwmKbskadF11EXP9t V1NBHh/WeXzdlN3vWHlTR+jx/EiJe5JREfH4GREDwVvcDf/+BnYUg1l9/QPotQZi+l17 A2Iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DM6ICmpf; 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 f8-20020a056402194800b004838856a8dasi22165015edz.568.2023.01.03.01.39.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:39:03 -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=DM6ICmpf; 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 57A5338493EC for ; Tue, 3 Jan 2023 09:37:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57A5338493EC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672738643; bh=YKC5aO+3mcvZcziCTNqB+B+CoZCb8KPK6tb8A5DlntA=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DM6ICmpfV0bw1C+Wtf6RkNj/4NCjog289pA4ayMez9QwWc8cRP6Gl7h6uHOPpQC0b W3KabTitaxRkx5iDtAb+XOnrBiUcTVkGV6VzCN397zTa1GBUjy5+LRBERMeiRT6RpT WfikaE6Ux9I194jg3jnZ1sqQD7j7ohFw2bMaMm8Q= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 2FBE338493C0 for ; Tue, 3 Jan 2023 09:36:01 +0000 (GMT) Received: by mail-wr1-x42a.google.com with SMTP id j17so23469586wrr.7 for ; Tue, 03 Jan 2023 01:36:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YKC5aO+3mcvZcziCTNqB+B+CoZCb8KPK6tb8A5DlntA=; b=VHCvEz5hR+GCF3EpukHhrBBMqsd+srP/ItXFuFwDwJl7sRpcKpsblgynRZBfhepqNF USwFOjVRej6orTJ42uBsFBozjZAHON+CHnK7hNXBjA7GEC/pE68OjoqGaxACUDOs6jlv 3mpZK3LycJB87TA6bFYx/506Sn9fRiA5yn91eu7sbzotd9A9EQbDheg4iLJ+crFU6ZXh FYssYMS1tjOnvllkVMJs5WrW0cUn0pqe1+ob9Qh2a7vEIwbbSD7x36JyKGk22PvU2GHR LjTUsytyb5uctMcrD9zgW4+dNo9OfoF2R2voGkFCBm0yG6NxPTlIb43D3kDnmZHbCl70 vV0Q== X-Gm-Message-State: AFqh2koFiffgTPhEW7Ig4zQ7B8GUoSaCSMhioxyLDqQeINQSBBEW4lX+ rJXxs3xHDJgq3fChmjbPDuQOw9NFs3C+MKHuPbA= X-Received: by 2002:a5d:4008:0:b0:264:ae8b:7de0 with SMTP id n8-20020a5d4008000000b00264ae8b7de0mr33383605wrp.39.1672738560015; Tue, 03 Jan 2023 01:36:00 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id bo19-20020a056000069300b00294176c2c01sm8900390wrb.86.2023.01.03.01.35.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 01:35:59 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED] ada: Make Apply_Discriminant_Check.Denotes_Explicit_Dereference more robust Date: Tue, 3 Jan 2023 10:35:57 +0100 Message-Id: <20230103093557.76628-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= 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?1753993700335026554?= X-GMAIL-MSGID: =?utf-8?q?1753993700335026554?= From: Eric Botcazou The predicate implements the rules of the language so it needs to cope with constructs rewritten by the expander, in particular explicit dereferences that the expander uses liberally for various purposes. This change makes the detection of rewritten calls more robust and adds the detection of rewritten return objects. gcc/ada/ * checks.adb (Apply_Discriminant_Check.Denotes_Explicit_Dereference): Return false for artificial dereferences generated by the expander. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/checks.adb | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 5833be3a5de..d518e6720a2 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -1388,13 +1388,23 @@ package body Checks is function Denotes_Explicit_Dereference (Obj : Node_Id) return Boolean is begin - return - Nkind (Obj) = N_Explicit_Dereference - or else - (Is_Entity_Name (Obj) - and then Present (Renamed_Object (Entity (Obj))) - and then Nkind (Renamed_Object (Entity (Obj))) = - N_Explicit_Dereference); + if Is_Entity_Name (Obj) then + return Present (Renamed_Object (Entity (Obj))) + and then + Denotes_Explicit_Dereference (Renamed_Object (Entity (Obj))); + + -- This routine uses the rules of the language so we need to exclude + -- rewritten constructs that introduce artificial dereferences. + + elsif Nkind (Obj) = N_Explicit_Dereference then + return not Is_Captured_Function_Call (Obj) + and then not + (Nkind (Parent (Obj)) = N_Object_Renaming_Declaration + and then Is_Return_Object (Defining_Entity (Parent (Obj)))); + + else + return False; + end if; end Denotes_Explicit_Dereference; ---------------------------------------- @@ -1497,9 +1507,7 @@ package body Checks is and then not Is_Aliased_Unconstrained_Component) or else (Ada_Version >= Ada_2005 and then not Is_Constrained (T_Typ) - and then Denotes_Explicit_Dereference (Lhs) - and then Nkind (Original_Node (Lhs)) /= - N_Function_Call)) + and then Denotes_Explicit_Dereference (Lhs))) then T_Typ := Get_Actual_Subtype (Lhs); end if;