[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.
This commit is contained in:
Eric Botcazou 2020-05-15 23:15:38 +02:00 committed by Pierre-Marie de Rodat
parent e997d94b29
commit e1b0956a8e
2 changed files with 21 additions and 20 deletions

View file

@ -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
<<Skip_Packed>>
-- 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)).

View file

@ -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