Commit 6186a6ef by Eric Botcazou Committed by Pierre-Marie de Rodat

[Ada] Fix elaboration of record with 1-element dynamic array

2018-12-11  Eric Botcazou  <ebotcazou@adacore.com>

gcc/ada/

	* einfo.ads (Is_Bit_Packed_Array): Fix values of component size.
	(Is_Packed): Likewise.
	* gcc-interface/utils.c (convert): Do not extract the value of a
	justified modular type if the destination type is a regular
	array.
	* gcc-interface/decl.c (gnat_to_gnu_component_type): Pass
	TYPE_DECL to validate_size wherever the array has packed
	components.

From-SVN: r267005
parent af3ded08
2018-12-11 Eric Botcazou <ebotcazou@adacore.com>
* einfo.ads (Is_Bit_Packed_Array): Fix values of component size.
(Is_Packed): Likewise.
* gcc-interface/utils.c (convert): Do not extract the value of a
justified modular type if the destination type is a regular
array.
* gcc-interface/decl.c (gnat_to_gnu_component_type): Pass
TYPE_DECL to validate_size wherever the array has packed
components.
2018-12-11 Bob Duff <duff@adacore.com> 2018-12-11 Bob Duff <duff@adacore.com>
* gnat1drv.adb (gnat1drv): Pass the correct Object value when * gnat1drv.adb (gnat1drv): Pass the correct Object value when
......
...@@ -2355,7 +2355,7 @@ package Einfo is ...@@ -2355,7 +2355,7 @@ package Einfo is
-- Is_Bit_Packed_Array (Flag122) [implementation base type only] -- Is_Bit_Packed_Array (Flag122) [implementation base type only]
-- Defined in all entities. This flag is set for a packed array type that -- Defined in all entities. This flag is set for a packed array type that
-- is bit-packed (i.e. the component size is known by the front end and -- is bit-packed (i.e. the component size is known by the front end and
-- is in the range 1-7, 9-15, 17-31, or 33-63). Is_Packed is always set -- is in the range 1-63 but not a multiple of 8). Is_Packed is always set
-- if Is_Bit_Packed_Array is set, but it is possible for Is_Packed to be -- if Is_Bit_Packed_Array is set, but it is possible for Is_Packed to be
-- set without Is_Bit_Packed_Array if the component size is not known by -- set without Is_Bit_Packed_Array if the component size is not known by
-- the front-end or for the case of an array having one or more index -- the front-end or for the case of an array having one or more index
...@@ -3020,9 +3020,9 @@ package Einfo is ...@@ -3020,9 +3020,9 @@ package Einfo is
-- out that the component size doesn't require packing, the Is_Packed -- out that the component size doesn't require packing, the Is_Packed
-- flag gets turned off. -- flag gets turned off.
-- In the bit-packed array case (i.e. component size is known at compile -- In the bit-packed array case (i.e. the component size is known by the
-- time and is 1-7, 9-15, 17-31 or 33-63), Is_Bit_Packed_Array will be -- front end and is in the range 1-63 but not a multiple of 8), then the
-- set once the array type is frozen. -- Is_Bit_Packed_Array flag will be set once the array type is frozen.
-- --
-- Is_Packed_Array (synth) -- Is_Packed_Array (synth)
-- Applies to all entities, true if entity is for a packed array. -- Applies to all entities, true if entity is for a packed array.
......
...@@ -5051,6 +5051,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition, ...@@ -5051,6 +5051,7 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
{ {
const Entity_Id gnat_type = Component_Type (gnat_array); const Entity_Id gnat_type = Component_Type (gnat_array);
tree gnu_type = gnat_to_gnu_type (gnat_type); tree gnu_type = gnat_to_gnu_type (gnat_type);
bool has_packed_components = Is_Bit_Packed_Array (gnat_array);
tree gnu_comp_size; tree gnu_comp_size;
unsigned int max_align; unsigned int max_align;
...@@ -5063,20 +5064,23 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition, ...@@ -5063,20 +5064,23 @@ gnat_to_gnu_component_type (Entity_Id gnat_array, bool definition,
else else
max_align = 0; max_align = 0;
/* Try to get a smaller form of the component if needed. */ /* Try to get a packable form of the component if needed. */
if ((Is_Packed (gnat_array) || Has_Component_Size_Clause (gnat_array)) if ((Is_Packed (gnat_array) || Has_Component_Size_Clause (gnat_array))
&& !Is_Bit_Packed_Array (gnat_array)
&& !Has_Aliased_Components (gnat_array) && !Has_Aliased_Components (gnat_array)
&& !Strict_Alignment (gnat_type) && !Strict_Alignment (gnat_type)
&& !has_packed_components
&& RECORD_OR_UNION_TYPE_P (gnu_type) && RECORD_OR_UNION_TYPE_P (gnu_type)
&& !TYPE_FAT_POINTER_P (gnu_type) && !TYPE_FAT_POINTER_P (gnu_type)
&& tree_fits_uhwi_p (TYPE_SIZE (gnu_type))) && tree_fits_uhwi_p (TYPE_SIZE (gnu_type)))
gnu_type = make_packable_type (gnu_type, false, max_align); {
gnu_type = make_packable_type (gnu_type, false, max_align);
has_packed_components = true;
}
/* Get and validate any specified Component_Size. */ /* Get and validate any specified Component_Size. */
gnu_comp_size gnu_comp_size
= validate_size (Component_Size (gnat_array), gnu_type, gnat_array, = validate_size (Component_Size (gnat_array), gnu_type, gnat_array,
Is_Bit_Packed_Array (gnat_array) ? TYPE_DECL : VAR_DECL, has_packed_components ? TYPE_DECL : VAR_DECL,
true, Has_Component_Size_Clause (gnat_array)); true, Has_Component_Size_Clause (gnat_array));
/* If the component type is a RECORD_TYPE that has a self-referential size, /* If the component type is a RECORD_TYPE that has a self-referential size,
......
...@@ -4361,12 +4361,13 @@ convert (tree type, tree expr) ...@@ -4361,12 +4361,13 @@ convert (tree type, tree expr)
TYPE_MIN_VALUE (etype)))); TYPE_MIN_VALUE (etype))));
/* If the input is a justified modular type, we need to extract the actual /* If the input is a justified modular type, we need to extract the actual
object before converting it to any other type with the exceptions of an object before converting it to an other type with the exceptions of an
unconstrained array or of a mere type variant. It is useful to avoid the [unconstrained] array or a mere type variant. It is useful to avoid
extraction and conversion in the type variant case because it could end the extraction and conversion in these cases because it could end up
up replacing a VAR_DECL expr by a constructor and we might be about the replacing a VAR_DECL by a constructor and we might be about the take
take the address of the result. */ the address of the result. */
if (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype) if (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype)
&& code != ARRAY_TYPE
&& code != UNCONSTRAINED_ARRAY_TYPE && code != UNCONSTRAINED_ARRAY_TYPE
&& TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (etype)) && TYPE_MAIN_VARIANT (type) != TYPE_MAIN_VARIANT (etype))
return return
......
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