From patchwork Wed Jan 5 11:33:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 49561 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 02C93385842C for ; Wed, 5 Jan 2022 11:43:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 02C93385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641383032; bh=POXgdRagGD6mFCV/1U2X+WaFzWd9uZGpuqkPUHoIOyI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ISrw1YGaHrFe2nf3DNEDjybat4sIXXJ+Sb3hVtB81vdazc+fALOZT8QsXyqU67U+d Zj1sVRdKVAs3PgiC3ZzwKzvRY1x7wFroao/E61USY1K/PqI37nitP7OMN8syhzzp8I pe4WUn9k096QPCJh3vPL+Qps4cNt7aI+2m2hnuio= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 538C83858423 for ; Wed, 5 Jan 2022 11:33:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 538C83858423 Received: by mail-wr1-x434.google.com with SMTP id i22so82320631wrb.13 for ; Wed, 05 Jan 2022 03:33:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=POXgdRagGD6mFCV/1U2X+WaFzWd9uZGpuqkPUHoIOyI=; b=5GgiAi5nIqfCNulavrWSjssr4YsCaK5z8csp9UHmLZvmIVm5oRsEBHClmYyabR/Fdg 1MUyPLZv2Ynvb2uHgYIE0DT3lMTU6lrx4keVfa5qpjdvtJliakfKEcwbaHSDbHF2uyo4 yMftHjNeySA11aE2xZQvyCleBkNNW0HKLzoZvBDGTVG9i2vPWxCzoZLrdUZ6pxtdvDV0 D4dP4yU+Fjyz4PazZnieFZe707gswr/BYqsp2arnqj57sv2DMULv13eicuyUeBcy7+Gk KRanHHUKWhCme7yyIPtKqKPy4lMvLNPrRXPw9bUnDOOl5dV434l+0uOxt8qz2oKkog2e pHRw== X-Gm-Message-State: AOAM5311AIEn0N2N6d3KhUuVy/oNCe4QIuOX5T1NvqHXwhRuM8IXbepn aWfoX/f2MZLV7d3VwP1+mstx2+fR5cxeiA== X-Google-Smtp-Source: ABdhPJx5s7x6TrpnrNV1s7XUvd4KzuAmRqzZFk6wBncwMEGpwQNxDqaxXwfrP4LGDxU9ROFOcXy/4Q== X-Received: by 2002:a5d:5988:: with SMTP id n8mr46917489wri.309.1641382413413; Wed, 05 Jan 2022 03:33:33 -0800 (PST) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id d4sm40372628wrx.102.2022.01.05.03.33.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jan 2022 03:33:32 -0800 (PST) Date: Wed, 5 Jan 2022 11:33:32 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Simplify making of null procedure wrappers Message-ID: <20220105113332.GA2713610@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.1 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Yet another cleanup related to expansion of dispatching primitives for GNATprove. To keep this change semantically neutral, one parameter is added to the Copy_Subprogram_Spec utility routine. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch3.adb (Make_Null_Procedure_Specs): Simplify by reusing Copy_Subprogram_Spec. * sem_util.ads (Copy_Subprogram_Spec): Add New_Sloc parameter. * sem_util.adb (Copy_Subprogram_Spec): Pass New_Sloc to New_Copy_Tree. diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb --- a/gcc/ada/exp_ch3.adb +++ b/gcc/ada/exp_ch3.adb @@ -10265,8 +10265,8 @@ package body Exp_Ch3 is Decl_List : constant List_Id := New_List; Loc : constant Source_Ptr := Sloc (Tag_Typ); Formal : Entity_Id; - Formal_List : List_Id; New_Param_Spec : Node_Id; + New_Spec : Node_Id; Parent_Subp : Entity_Id; Prim_Elmt : Elmt_Id; Subp : Entity_Id; @@ -10285,59 +10285,47 @@ package body Exp_Ch3 is if Present (Parent_Subp) and then Is_Null_Interface_Primitive (Parent_Subp) then - Formal := First_Formal (Subp); - - if Present (Formal) then - Formal_List := New_List; - - while Present (Formal) loop + -- The null procedure spec is copied from the inherited procedure, + -- except for the IS NULL (which must be added) and the overriding + -- indicators (which must be removed, if present). - -- Copy the parameter spec including default expressions + New_Spec := + Copy_Subprogram_Spec (Subprogram_Specification (Subp), Loc); - New_Param_Spec := - New_Copy_Tree (Parent (Formal), New_Sloc => Loc); + Set_Null_Present (New_Spec, True); + Set_Must_Override (New_Spec, False); + Set_Must_Not_Override (New_Spec, False); - -- Generate a new defining identifier for the new formal. - -- Required because New_Copy_Tree does not duplicate - -- semantic fields (except itypes). + Formal := First_Formal (Subp); + New_Param_Spec := First (Parameter_Specifications (New_Spec)); - Set_Defining_Identifier (New_Param_Spec, - Make_Defining_Identifier (Sloc (Formal), - Chars => Chars (Formal))); + while Present (Formal) loop - -- For controlling arguments we must change their parameter - -- type to reference the tagged type (instead of the - -- interface type). + -- For controlling arguments we must change their parameter + -- type to reference the tagged type (instead of the interface + -- type). - if Is_Controlling_Formal (Formal) then - if Nkind (Parameter_Type (Parent (Formal))) = N_Identifier - then - Set_Parameter_Type (New_Param_Spec, - New_Occurrence_Of (Tag_Typ, Loc)); - - else pragma Assert - (Nkind (Parameter_Type (Parent (Formal))) = - N_Access_Definition); - Set_Subtype_Mark (Parameter_Type (New_Param_Spec), - New_Occurrence_Of (Tag_Typ, Loc)); - end if; + if Is_Controlling_Formal (Formal) then + if Nkind (Parameter_Type (Parent (Formal))) = N_Identifier + then + Set_Parameter_Type (New_Param_Spec, + New_Occurrence_Of (Tag_Typ, Loc)); + + else pragma Assert + (Nkind (Parameter_Type (Parent (Formal))) = + N_Access_Definition); + Set_Subtype_Mark (Parameter_Type (New_Param_Spec), + New_Occurrence_Of (Tag_Typ, Loc)); end if; + end if; - Append (New_Param_Spec, Formal_List); - - Next_Formal (Formal); - end loop; - else - Formal_List := No_List; - end if; + Next_Formal (Formal); + Next (New_Param_Spec); + end loop; Append_To (Decl_List, Make_Subprogram_Declaration (Loc, - Make_Procedure_Specification (Loc, - Defining_Unit_Name => - Make_Defining_Identifier (Loc, Chars (Subp)), - Parameter_Specifications => Formal_List, - Null_Present => True))); + Specification => New_Spec)); end if; Next_Elmt (Prim_Elmt); diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -6871,7 +6871,10 @@ package body Sem_Util is -- Copy_Subprogram_Spec -- -------------------------- - function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id is + function Copy_Subprogram_Spec + (Spec : Node_Id; + New_Sloc : Source_Ptr := No_Location) return Node_Id + is Def_Id : Node_Id; Formal_Spec : Node_Id; Result : Node_Id; @@ -6880,7 +6883,7 @@ package body Sem_Util is -- The structure of the original tree must be replicated without any -- alterations. Use New_Copy_Tree for this purpose. - Result := New_Copy_Tree (Spec); + Result := New_Copy_Tree (Spec, New_Sloc => New_Sloc); -- However, the spec of a null procedure carries the corresponding null -- statement of the body (created by the parser), and this cannot be diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -623,10 +623,13 @@ package Sem_Util is -- aspect specifications. If From has no aspects, the routine has no -- effect. - function Copy_Subprogram_Spec (Spec : Node_Id) return Node_Id; + function Copy_Subprogram_Spec + (Spec : Node_Id; + New_Sloc : Source_Ptr := No_Location) return Node_Id; -- Replicate a function or a procedure specification denoted by Spec. The -- resulting tree is an exact duplicate of the original tree. New entities - -- are created for the unit name and the formal parameters. + -- are created for the unit name and the formal parameters. For definition + -- of New_Sloc, see the comment for New_Copy_Tree. function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id; -- If a type is a generic actual type, return the corresponding formal in