From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id 35491398B879; Thu, 8 Jul 2021 13:36:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35491398B879 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2148] [Ada] Compute sizes when possible for packed array with Component_Size X-Act-Checkin: gcc X-Git-Author: Yannick Moy X-Git-Refname: refs/heads/master X-Git-Oldrev: 5478d8a7aefbec4d93d32237fb29b9fdb8347b6b X-Git-Newrev: 36fcfed88c7cbb3d55a59cdd077e8b26107148b9 Message-Id: <20210708133634.35491398B879@sourceware.org> Date: Thu, 8 Jul 2021 13:36:34 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 Jul 2021 13:36:34 -0000 https://gcc.gnu.org/g:36fcfed88c7cbb3d55a59cdd077e8b26107148b9 commit r12-2148-g36fcfed88c7cbb3d55a59cdd077e8b26107148b9 Author: Yannick Moy Date: Wed May 19 15:50:02 2021 +0200 [Ada] Compute sizes when possible for packed array with Component_Size gcc/ada/ * layout.adb (Layout_Type): Special case when RM_Size and Esize can be computed for packed arrays. Diff: --- gcc/ada/layout.adb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb index 6dc4d7fb699..cbc296a6e45 100644 --- a/gcc/ada/layout.adb +++ b/gcc/ada/layout.adb @@ -487,6 +487,48 @@ package body Layout is then Set_Alignment (E, Alignment (Component_Type (E))); end if; + + -- If packing was requested, the one-dimensional array is constrained + -- with static bounds, the component size was set explicitly, and + -- the alignment is known, we can set (if not set explicitly) the + -- RM_Size and the Esize of the array type, as RM_Size is equal to + -- (arr'length * arr'component_size) and Esize is the same value + -- rounded to the next multiple of arr'alignment. This is not + -- applicable to packed arrays that are implemented specially + -- in GNAT, i.e. when Packed_Array_Impl_Type is set. + + if Is_Array_Type (E) + and then Number_Dimensions (E) = 1 + and then not Present (Packed_Array_Impl_Type (E)) + and then Has_Pragma_Pack (E) + and then Is_Constrained (E) + and then Compile_Time_Known_Bounds (E) + and then Known_Component_Size (E) + and then Known_Alignment (E) + then + declare + Abits : constant Int := UI_To_Int (Alignment (E)) * SSU; + Lo, Hi : Node_Id; + Siz : Uint; + + begin + Get_Index_Bounds (First_Index (E), Lo, Hi); + Siz := (Expr_Value (Hi) - Expr_Value (Lo) + 1) + * Component_Size (E); + + -- Do not overwrite a different value of 'Size specified + -- explicitly by the user. In that case, also do not set Esize. + + if Unknown_RM_Size (E) or else RM_Size (E) = Siz then + Set_RM_Size (E, Siz); + + if Unknown_Esize (E) then + Siz := ((Siz + (Abits - 1)) / Abits) * Abits; + Set_Esize (E, Siz); + end if; + end if; + end; + end if; end if; -- Even if the backend performs the layout, we still do a little in