From e1b0956a8e1f5609266cbe064b345bbb37b1e7e2 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 15 May 2020 23:15:38 +0200 Subject: [PATCH] [Ada] Small adjustment in the handling of alignment for arrays gcc/ada/ * freeze.adb (Freeze_Array_Type): Use Ctyp more consistently. Move code setting the alignment in the non-packed case to... * layout.adb (Layout_Type): ...here. --- gcc/ada/freeze.adb | 25 +++++-------------------- gcc/ada/layout.adb | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index fd76e7bc63c..7c6fac155ee 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -2573,13 +2573,13 @@ package body Freeze is -- Propagate flags for component type - if Is_Controlled (Component_Type (Arr)) + if Is_Controlled (Ctyp) or else Has_Controlled_Component (Ctyp) then Set_Has_Controlled_Component (Arr); end if; - if Has_Unchecked_Union (Component_Type (Arr)) then + if Has_Unchecked_Union (Ctyp) then Set_Has_Unchecked_Union (Arr); end if; @@ -2590,7 +2590,7 @@ package body Freeze is -- that the procedure can be used to check the array type -- invariants if any. - if Has_Invariants (Component_Type (Arr)) + if Has_Invariants (Ctyp) and then not GNATprove_Mode then Set_Has_Own_Invariants (Arr); @@ -2902,8 +2902,8 @@ package body Freeze is -- If the Esize of the component is known and equal to -- the component size then even packing is not needed. - if Known_Static_Esize (Component_Type (Arr)) - and then Esize (Component_Type (Arr)) = Csiz + if Known_Static_Esize (Ctyp) + and then Esize (Ctyp) = Csiz then -- Here the array was requested to be packed, but -- the packing request had no effect whatsoever, @@ -3157,21 +3157,6 @@ package body Freeze is <> - -- For non-packed arrays set the alignment of the array to the - -- alignment of the component type if it is unknown. Skip this - -- in atomic/VFA case (atomic/VFA arrays may need larger alignments). - - if not Is_Packed (Arr) - and then Unknown_Alignment (Arr) - and then Known_Alignment (Ctyp) - and then Known_Static_Component_Size (Arr) - and then Known_Static_Esize (Ctyp) - and then Esize (Ctyp) = Component_Size (Arr) - and then not Is_Atomic_Or_VFA (Arr) - then - Set_Alignment (Arr, Alignment (Component_Type (Arr))); - end if; - -- A Ghost type cannot have a component of protected or task type -- (SPARK RM 6.9(19)). diff --git a/gcc/ada/layout.adb b/gcc/ada/layout.adb index 33728c0f918..73812f64e73 100644 --- a/gcc/ada/layout.adb +++ b/gcc/ada/layout.adb @@ -467,6 +467,22 @@ package body Layout is end if; end; end if; + + -- For non-packed arrays set the alignment of the array to the + -- alignment of the component type if it is unknown. Skip this + -- in atomic/VFA case since a larger alignment may be needed. + + if Is_Array_Type (E) + and then not Is_Packed (E) + and then Unknown_Alignment (E) + and then Known_Alignment (Component_Type (E)) + and then Known_Static_Component_Size (E) + and then Known_Static_Esize (Component_Type (E)) + and then Component_Size (E) = Esize (Component_Type (E)) + and then not Is_Atomic_Or_VFA (E) + then + Set_Alignment (E, Alignment (Component_Type (E))); + end if; end if; -- Even if the backend performs the layout, we still do a little in -- 2.30.2