From patchwork Tue May 17 08:27:52 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: 54085 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 BD858385735B for ; Tue, 17 May 2022 08:52:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD858385735B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652777562; bh=wiZPYPgZPRWEdJ3jQ/YlTHWovwUBf2rpQRddif4+XJU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=DEAeRvXugc4EBZFF304onddFwb4Ul5M6xDRLVNc7l7Y1l23k4+ieUV4AgPGxarfeO dalReasw0Vho5D2/k8SW/5FRQKRNp6T6XmmkfrexdbFworlc7jlj9KqH7RuGInTnyz ElVqq/LhKBP/TPjI6v3Zz6C+JVGzUMgI1OTcik78= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id E5144385742A for ; Tue, 17 May 2022 08:27:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5144385742A Received: by mail-wm1-x335.google.com with SMTP id o12-20020a1c4d0c000000b00393fbe2973dso929006wmh.2 for ; Tue, 17 May 2022 01:27:54 -0700 (PDT) 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=wiZPYPgZPRWEdJ3jQ/YlTHWovwUBf2rpQRddif4+XJU=; b=jRT4w/+Db9UW0iX05epK0W++68oZlFceniBKy4odEgIjQ60rAzOUyaZRC1SdfS+XtU 5+Qt8jeeRioyO70i6Nk2cld3H5Xf4pxZCfpXhFhSU4Z8hEbbLS71nC6W+1IlHyAvX9nK fFNfWXtLE38qRxhMJO1c+1zt8jPLZLMR6zOnJXkfcGsFT0hjG6k+FAXU08GA8BKL7Ri5 K3Uzk7RgQExJ+7YlQzqwhNPXOXjW9YnHQnYU/HU2sOBw53zBOYObDlk6zcdy891THFff 0JnrPutBTk0PMbMt8xPnCY3SZlSNRu6YPD8XKzKl1cZ6Esbh/mVj32F6nkHMT87JjebN mF/A== X-Gm-Message-State: AOAM533pD4WkHbFbkvSItyZRkLmWhAtuUnDLoe7v8K5RFFjEyNxbp/C0 1PATnJMVNKIEoS11bZjZg5/zEll7+73BXKzE X-Google-Smtp-Source: ABdhPJzeSx8liV2WnYPJczArQ26MIUR4u+vmxozrPtubfD7dYh7SQ+EXCQu0jgANtv+SVFJLzqd4kQ== X-Received: by 2002:a05:600c:22d2:b0:393:f4be:ea1f with SMTP id 18-20020a05600c22d200b00393f4beea1fmr20752342wmg.51.1652776073855; Tue, 17 May 2022 01:27:53 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id f18-20020adf9c12000000b0020c6fa5a797sm11538749wrc.91.2022.05.17.01.27.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 01:27:53 -0700 (PDT) Date: Tue, 17 May 2022 08:27:52 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Provide allocation subtype for allocators of a Designated_Storage_Model type Message-ID: <20220517082752.GA1091102@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Gary Dismukes Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When an allocator is for an access type that has a Designated_Storage_Model aspect, and the designated type is an unconstrained record type with discriminants, and the subtype associated with the allocator is constrained, a dereference of the new access value can be passed to the designated type's initialization procedure. The post-front-end phase of the compiler needs to be able to create a temporary object in the host memory space to pass to the init proc, which requires creating such an object, but the subtype needed for the allocation isn't readily available at the point of the dereference. To make the subtype easily accessible, we set the Actual_Designated_Subtype of such a dereference to the subtype of the allocated object. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_ch4.adb (Expand_N_Allocator): For an allocator with an unconstrained discriminated designated type, and whose allocation subtype is constrained, set the Actual_Designated_Subtype of the dereference passed to the init proc of the designated type to be the allocation subtype. * sinfo.ads: Add documentation of new setting of Actual_Designated_Subtype on a dereference used as an actual parameter of call to an init proc associated with an allocator. Also add missing syntax and documentation for the GNAT language extension that allows an expression as a default for a concrete generic formal function. diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -5135,6 +5135,30 @@ package body Exp_Ch4 is Set_Expression (N, New_Occurrence_Of (Typ, Loc)); end if; + -- When the designated subtype is unconstrained and + -- the allocator specifies a constrained subtype (or + -- such a subtype has been created, such as above by + -- Build_Default_Subtype), associate that subtype with + -- the dereference of the allocator's access value. + -- This is needed by the back end for cases where + -- the access type has a Designated_Storage_Model, + -- to support allocation of a host object of the right + -- size for passing to the initialization procedure. + + if not Is_Constrained (Dtyp) + and then Is_Constrained (Typ) + then + declare + Init_Deref : constant Node_Id := + Unqual_Conv (Init_Arg1); + begin + pragma Assert + (Nkind (Init_Deref) = N_Explicit_Dereference); + + Set_Actual_Designated_Subtype (Init_Deref, Typ); + end; + end if; + Discr := First_Elmt (Discriminant_Constraint (Typ)); while Present (Discr) loop Nod := Node (Discr); diff --git a/gcc/ada/sinfo.ads b/gcc/ada/sinfo.ads --- a/gcc/ada/sinfo.ads +++ b/gcc/ada/sinfo.ads @@ -816,12 +816,15 @@ package Sinfo is -- Actual_Designated_Subtype -- Present in N_Free_Statement and N_Explicit_Dereference nodes. If gigi - -- needs to known the dynamic constrained subtype of the designated - -- object, this attribute is set to that type. This is done for - -- N_Free_Statements for access-to-classwide types and access to - -- unconstrained packed array types, and for N_Explicit_Dereference when - -- the designated type is an unconstrained packed array and the - -- dereference is the prefix of a 'Size attribute reference. + -- needs to know the dynamic constrained subtype of the designated + -- object, this attribute is set to that subtype. This is done for + -- N_Free_Statements for access-to-classwide types and access-to- + -- unconstrained packed array types. For N_Explicit_Dereference, + -- this is done in two circumstances: 1) when the designated type is + -- an unconstrained packed array and the dereference is the prefix of + -- a 'Size attribute reference, or 2) when the dereference node is + -- created for the expansion of an allocator with a subtype_indication + -- and the designated subtype is an unconstrained discriminated type. -- Address_Warning_Posted -- Present in N_Attribute_Definition nodes. Set to indicate that we have @@ -7313,10 +7316,15 @@ package Sinfo is -- Specification -- Default_Name (set to Empty if no subprogram default) -- Box_Present + -- Expression (set to Empty if no expression present) - -- Note: if no subprogram default is present, then Name is set + -- Note: If no subprogram default is present, then Name is set -- to Empty, and Box_Present is False. + -- Note: The Expression field is only used for the GNAT extension + -- that allows a FORMAL_CONCRETE_SUBPROGRAM_DECLARATION to specify + -- an expression default for generic formal functions. + -------------------------------------------------- -- 12.6 Formal Abstract Subprogram Declaration -- -------------------------------------------------- @@ -7338,13 +7346,17 @@ package Sinfo is -- 12.6 Subprogram Default -- ------------------------------ - -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <> + -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <> | (EXPRESSION) -- There is no separate node in the tree for a subprogram default. -- Instead the parent (N_Formal_Concrete_Subprogram_Declaration -- or N_Formal_Abstract_Subprogram_Declaration) node contains the -- default name or box indication, as needed. + -- Note: The syntax "(EXPRESSION)" is a GNAT extension, and allows + -- a FORMAL_CONCRETE_SUBPROGRAM_DECLARATION to specify an expression + -- default for formal functions, in analogy with expression_functions. + ------------------------ -- 12.6 Default Name -- ------------------------