decl.c (make_packable_type): Revert last change.

* decl.c (make_packable_type): Revert last change.
	(gnat_to_gnu_field): Avoid setting size and position multiple times.
	* utils.c (finish_record_type): Retrieve the real name of the type.

From-SVN: r130665
This commit is contained in:
Eric Botcazou 2007-12-06 22:39:58 +00:00
parent 4c42b3d84f
commit 4039fb351c
3 changed files with 39 additions and 33 deletions

View File

@ -1,3 +1,9 @@
2007-12-06 Eric Botcazou <ebotcazou@adacore.com>
* decl.c (make_packable_type): Revert last change.
(gnat_to_gnu_field): Avoid setting size and position multiple times.
* utils.c (finish_record_type): Retrieve the real name of the type.
2007-12-05 Eric Botcazou <ebotcazou@adacore.com>
* trans.c (lvalue_required_p): Take base node directly instead
@ -80,7 +86,7 @@
2007-11-25 Richard Guenther <rguenther@suse.de>
utils.c (gnat_pushlevel): Use BLOCK_CHAIN.
* utils.c (gnat_pushlevel): Use BLOCK_CHAIN.
(gnat_poplevel): Likewise.
2007-11-25 Eric Botcazou <ebotcazou@adacore.com>

View File

@ -5198,19 +5198,14 @@ static tree
make_packable_type (tree type)
{
tree new_type = make_node (TREE_CODE (type));
tree name = TYPE_NAME (type);
tree field_list = NULL_TREE;
tree old_field;
if (name && TREE_CODE (name) == TYPE_DECL)
name = DECL_NAME (name);
/* Copy the name and flags from the old type to that of the new and set
the alignment to try for an integral type. For QUAL_UNION_TYPE,
also copy the size. */
TYPE_NAME (new_type) = name;
TYPE_JUSTIFIED_MODULAR_P (new_type)
= TYPE_JUSTIFIED_MODULAR_P (type);
/* Copy the name and flags from the old type to that of the new. Note
that we rely on the pointer equality created here for TYPE_NAME at
the end of gnat_to_gnu. For QUAL_UNION_TYPE, also copy the size. */
TYPE_NAME (new_type) = TYPE_NAME (type);
TYPE_JUSTIFIED_MODULAR_P (new_type) = TYPE_JUSTIFIED_MODULAR_P (type);
TYPE_CONTAINS_TEMPLATE_P (new_type) = TYPE_CONTAINS_TEMPLATE_P (type);
if (TREE_CODE (type) == RECORD_TYPE)
@ -5221,6 +5216,7 @@ make_packable_type (tree type)
TYPE_SIZE_UNIT (new_type) = TYPE_SIZE_UNIT (type);
}
/* Set the alignment to try for an integral type. */
TYPE_ALIGN (new_type) = ceil_alignment (tree_low_cst (TYPE_SIZE (type), 1));
TYPE_USER_ALIGN (new_type) = 1;
@ -5599,9 +5595,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
{
tree gnu_field_id = get_entity_name (gnat_field);
tree gnu_field_type = gnat_to_gnu_type (Etype (gnat_field));
tree gnu_pos = 0;
tree gnu_size = 0;
tree gnu_field;
tree gnu_field, gnu_size, gnu_pos;
bool needs_strict_alignment
= (Is_Aliased (gnat_field) || Strict_Alignment (Etype (gnat_field))
|| Treat_As_Volatile (gnat_field));
@ -5613,18 +5607,17 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
else
packed = adjust_packed (gnu_field_type, gnu_record_type, packed);
/* For packed records, this is one of the few occasions on which we use
the official RM size for discrete or fixed-point components, instead
of the normal GNAT size stored in Esize. See description in Einfo:
"Handling of Type'Size Values" for further details. */
if (packed == 1)
gnu_size = validate_size (RM_Size (Etype (gnat_field)), gnu_field_type,
gnat_field, FIELD_DECL, false, true);
/* If a size is specified, use it. Otherwise, if the record type is packed,
use the official RM size. See "Handling of Type'Size Values" in Einfo
for further details. */
if (Known_Static_Esize (gnat_field))
gnu_size = validate_size (Esize (gnat_field), gnu_field_type,
gnat_field, FIELD_DECL, false, true);
else if (packed == 1)
gnu_size = validate_size (RM_Size (Etype (gnat_field)), gnu_field_type,
gnat_field, FIELD_DECL, false, true);
else
gnu_size = NULL_TREE;
/* If we have a specified size that's smaller than that of the field type,
or a position is specified, and the field type is also a record that's
@ -5656,8 +5649,8 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
&& compare_tree_int (TYPE_SIZE (gnu_field_type), BIGGEST_ALIGNMENT) <= 0
&& (packed == 1
|| (gnu_size
&& tree_int_cst_lt (gnu_size, TYPE_SIZE (gnu_field_type)))
|| (Present (Component_Clause (gnat_field)) && gnu_size != 0)))
&& (tree_int_cst_lt (gnu_size, TYPE_SIZE (gnu_field_type))
|| Present (Component_Clause (gnat_field))))))
{
/* See what the alternate type and size would be. */
tree gnu_packable_type = make_packable_type (gnu_field_type);
@ -5689,7 +5682,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
{
gnu_field_type = gnu_packable_type;
if (gnu_size == 0)
if (!gnu_size)
gnu_size = rm_size (gnu_field_type);
}
}
@ -5797,6 +5790,9 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
gnu_size = TYPE_SIZE (gnu_field_type);
}
else
gnu_pos = NULL_TREE;
/* We need to make the size the maximum for the type if it is
self-referential and an unconstrained type. In that case, we can't
pack the field since we can't make a copy to align it. */
@ -5809,11 +5805,8 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
packed = 0;
}
/* If no size is specified (or if there was an error), don't specify a
position. */
if (!gnu_size)
gnu_pos = NULL_TREE;
else
/* If a size is specified, adjust the field's type to it. */
if (gnu_size)
{
/* If the field's type is justified modular, we would need to remove
the wrapper to (better) meet the layout requirements. However we
@ -5834,6 +5827,10 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed,
"PAD", false, definition, true);
}
/* Otherwise (or if there was an error), don't specify a position. */
else
gnu_pos = NULL_TREE;
gcc_assert (TREE_CODE (gnu_field_type) != RECORD_TYPE
|| !TYPE_CONTAINS_TEMPLATE_P (gnu_field_type));

View File

@ -747,6 +747,7 @@ finish_record_type (tree record_type, tree fieldlist, int rep_level,
bool do_not_finalize)
{
enum tree_code code = TREE_CODE (record_type);
tree name = TYPE_NAME (record_type);
tree ada_size = bitsize_zero_node;
tree size = bitsize_zero_node;
bool var_size = false;
@ -754,9 +755,11 @@ finish_record_type (tree record_type, tree fieldlist, int rep_level,
bool had_size_unit = TYPE_SIZE_UNIT (record_type) != 0;
tree field;
if (name && TREE_CODE (name) == TYPE_DECL)
name = DECL_NAME (name);
TYPE_FIELDS (record_type) = fieldlist;
TYPE_STUB_DECL (record_type)
= build_decl (TYPE_DECL, TYPE_NAME (record_type), record_type);
TYPE_STUB_DECL (record_type) = build_decl (TYPE_DECL, name, record_type);
/* We don't need both the typedef name and the record name output in
the debugging information, since they are the same. */