Commit 3d626f94 by Eric Botcazou Committed by Eric Botcazou

freeze.adb (Freeze_Array_Type): Call Addressable predicate instead of testing for individual sizes.

	* freeze.adb (Freeze_Array_Type): Call Addressable predicate instead
	of testing for individual sizes.
	(Freeze_Entity): Rework implementation of pragma Implicit_Packing for
	array types, in particular test for suitable sizes upfront and do not
	mimic the processing that will be redone later in Freeze_Array_Type.

From-SVN: r236281
parent cce309d7
2016-05-16 Eric Botcazou <ebotcazou@adacore.com> 2016-05-16 Eric Botcazou <ebotcazou@adacore.com>
* freeze.adb (Freeze_Array_Type): Call Addressable predicate instead
of testing for individual sizes.
(Freeze_Entity): Rework implementation of pragma Implicit_Packing for
array types, in particular test for suitable sizes upfront and do not
mimic the processing that will be redone later in Freeze_Array_Type.
2016-05-16 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/trans.c (elaborate_all_entities_for_package): Also skip * gcc-interface/trans.c (elaborate_all_entities_for_package): Also skip
formal objects. formal objects.
......
...@@ -2453,11 +2453,7 @@ package body Freeze is ...@@ -2453,11 +2453,7 @@ package body Freeze is
-- Bit packing is never needed for 8, 16, 32, 64 -- Bit packing is never needed for 8, 16, 32, 64
if Csiz = 8 if Addressable (Csiz) then
or else Csiz = 16
or else Csiz = 32
or else Csiz = 64
then
-- If the Esize of the component is known and equal to -- If the Esize of the component is known and equal to
-- the component size then even packing is not needed. -- the component size then even packing is not needed.
...@@ -5295,20 +5291,20 @@ package body Freeze is ...@@ -5295,20 +5291,20 @@ package body Freeze is
if E /= Base_Type (E) then if E /= Base_Type (E) then
-- Before we do anything else, a specialized test for the case of -- Before we do anything else, a specific test for the case of a
-- a size given for an array where the array needs to be packed, -- size given for an array where the array would need to be packed
-- but was not so the size cannot be honored. This is the case -- in order for the size to be honored, but is not. This is the
-- where implicit packing may apply. The reason we do this so -- case where implicit packing may apply. The reason we do this so
-- early is that if we have implicit packing, the layout of the -- early is that, if we have implicit packing, the layout of the
-- base type is affected, so we must do this before we freeze -- base type is affected, so we must do this before we freeze the
-- the base type. -- base type.
-- We could do this processing only if implicit packing is enabled -- We could do this processing only if implicit packing is enabled
-- since in all other cases, the error would be caught by the back -- since in all other cases, the error would be caught by the back
-- end. However, we choose to do the check even if we do not have -- end. However, we choose to do the check even if we do not have
-- implicit packing enabled, since this allows us to give a more -- implicit packing enabled, since this allows us to give a more
-- useful error message (advising use of pragmas Implicit_Packing -- useful error message (advising use of pragma Implicit_Packing
-- or Pack). -- or pragma Pack).
if Is_Array_Type (E) then if Is_Array_Type (E) then
declare declare
...@@ -5321,7 +5317,8 @@ package body Freeze is ...@@ -5321,7 +5317,8 @@ package body Freeze is
Hi : Node_Id; Hi : Node_Id;
Indx : Node_Id; Indx : Node_Id;
Num_Elmts : Uint; Dim : Uint;
Num_Elmts : Uint := Uint_1;
-- Number of elements in array -- Number of elements in array
begin begin
...@@ -5337,13 +5334,21 @@ package body Freeze is ...@@ -5337,13 +5334,21 @@ package body Freeze is
-- a chance to freeze the base type (and it is that freeze -- a chance to freeze the base type (and it is that freeze
-- action that causes stuff to be inherited). -- action that causes stuff to be inherited).
-- The conditions on the size are identical to those used in
-- Freeze_Array_Type to set the Is_Packed flag.
if Has_Size_Clause (E) if Has_Size_Clause (E)
and then Known_Static_RM_Size (E) and then Known_Static_RM_Size (E)
and then not Is_Packed (E) and then not Is_Packed (E)
and then not Has_Pragma_Pack (E) and then not Has_Pragma_Pack (E)
and then not Has_Component_Size_Clause (E) and then not Has_Component_Size_Clause (E)
and then Known_Static_RM_Size (Ctyp) and then Known_Static_RM_Size (Ctyp)
and then RM_Size (Ctyp) < 64 and then Rsiz <= 64
and then not (Addressable (Rsiz)
and then Known_Static_Esize (Ctyp)
and then Esize (Ctyp) = Rsiz)
and then not (Rsiz mod System_Storage_Unit = 0
and then Is_Composite_Type (Ctyp))
and then not Is_Limited_Composite (E) and then not Is_Limited_Composite (E)
and then not Is_Packed (Root_Type (E)) and then not Is_Packed (Root_Type (E))
and then not Has_Component_Size_Clause (Root_Type (E)) and then not Has_Component_Size_Clause (Root_Type (E))
...@@ -5351,7 +5356,6 @@ package body Freeze is ...@@ -5351,7 +5356,6 @@ package body Freeze is
then then
-- Compute number of elements in array -- Compute number of elements in array
Num_Elmts := Uint_1;
Indx := First_Index (E); Indx := First_Index (E);
while Present (Indx) loop while Present (Indx) loop
Get_Index_Bounds (Indx, Lo, Hi); Get_Index_Bounds (Indx, Lo, Hi);
...@@ -5363,33 +5367,28 @@ package body Freeze is ...@@ -5363,33 +5367,28 @@ package body Freeze is
goto No_Implicit_Packing; goto No_Implicit_Packing;
end if; end if;
Num_Elmts := Dim := Expr_Value (Hi) - Expr_Value (Lo) + 1;
Num_Elmts *
UI_Max (Uint_0, if Dim >= 0 then
Expr_Value (Hi) - Expr_Value (Lo) + 1); Num_Elmts := Num_Elmts * Dim;
else
Num_Elmts := Uint_0;
end if;
Next_Index (Indx); Next_Index (Indx);
end loop; end loop;
-- What we are looking for here is the situation where -- What we are looking for here is the situation where
-- the RM_Size given would be exactly right if there was -- the RM_Size given would be exactly right if there was
-- a pragma Pack (resulting in the component size being -- a pragma Pack, resulting in the component size being
-- the same as the RM_Size). Furthermore, the component -- the RM_Size of the component type.
-- type size must be an odd size (not a multiple of
-- storage unit). If the component RM size is an exact if RM_Size (E) = Num_Elmts * Rsiz then
-- number of storage units that is a power of two, the
-- array is not packed and has a standard representation.
if RM_Size (E) = Num_Elmts * Rsiz
and then Rsiz mod System_Storage_Unit /= 0
then
-- For implicit packing mode, just set the component -- For implicit packing mode, just set the component
-- size silently. -- size and Freeze_Array_Type will do the rest.
if Implicit_Packing then if Implicit_Packing then
Set_Component_Size (Btyp, Rsiz); Set_Component_Size (Btyp, Rsiz);
Set_Is_Bit_Packed_Array (Btyp);
Set_Is_Packed (Btyp);
Set_Has_Non_Standard_Rep (Btyp);
-- Otherwise give an error message -- Otherwise give an error message
...@@ -5400,20 +5399,6 @@ package body Freeze is ...@@ -5400,20 +5399,6 @@ package body Freeze is
("\use explicit pragma Pack " ("\use explicit pragma Pack "
& "or use pragma Implicit_Packing", SZ); & "or use pragma Implicit_Packing", SZ);
end if; end if;
elsif RM_Size (E) = Num_Elmts * Rsiz
and then Implicit_Packing
and then
(Rsiz / System_Storage_Unit = 1
or else
Rsiz / System_Storage_Unit = 2
or else
Rsiz / System_Storage_Unit = 4)
then
-- Not a packed array, but indicate the desired
-- component size, for the back-end.
Set_Component_Size (Btyp, Rsiz);
end if; end if;
end if; end if;
end; end;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment