From c00d5b12b08040fe0d8ee5168b612bf125e21566 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Sun, 20 Dec 2015 10:30:27 +0000 Subject: [PATCH] decl.c (gnat_to_gnu_entity): During layout in type_annotate_only mode... * gcc-interface/decl.c (gnat_to_gnu_entity) : During layout in type_annotate_only mode, skip discriminants of derived tagged types renaming those of the parent type. In type_annotate_only mode, if the type is tagged, do not override a size clause but take into account the alignment of the tag. (annotate_rep): In type_annotate_only mode, deal with discriminants of derived tagged types renaming those of the parent type. From-SVN: r231860 --- gcc/ada/ChangeLog | 10 +++++++ gcc/ada/gcc-interface/decl.c | 54 ++++++++++++++++++++++++++++-------- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 0de7c0a8cdc..1a97c932ce5 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,13 @@ +2015-12-20 Eric Botcazou + + * gcc-interface/decl.c (gnat_to_gnu_entity) : During + layout in type_annotate_only mode, skip discriminants of derived + tagged types renaming those of the parent type. + In type_annotate_only mode, if the type is tagged, do not override a + size clause but take into account the alignment of the tag. + (annotate_rep): In type_annotate_only mode, deal with discriminants + of derived tagged types renaming those of the parent type. + 2015-12-20 Eric Botcazou * gcc-interface/utils.c (maybe_pad_type): In type_annotate_only mode, diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index 7058ef0809f..0b1cd6f18bf 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -3181,6 +3181,14 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) && Present (Corresponding_Discriminant (gnat_field))) continue; + /* However, if we are just annotating types, the Parent_Subtype + doesn't exist so we need skip the discriminant altogether. */ + if (type_annotate_only + && Is_Tagged_Type (gnat_entity) + && Is_Derived_Type (gnat_entity) + && Present (Corresponding_Discriminant (gnat_field))) + continue; + gnu_field = gnat_to_gnu_field (gnat_field, gnu_type, packed, definition, debug_info_p); @@ -5321,15 +5329,15 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) /* If we are just annotating types and the type is tagged, the tag and the parent components are not generated by the front-end so - sizes must be adjusted if there is no representation clause. */ + alignment and sizes must be adjusted if there is no rep clause. */ if (type_annotate_only && Is_Tagged_Type (gnat_entity) + && Unknown_RM_Size (gnat_entity) && !VOID_TYPE_P (gnu_type) && (!TYPE_FIELDS (gnu_type) || integer_zerop (bit_position (TYPE_FIELDS (gnu_type))))) { - tree pointer_size = bitsize_int (POINTER_SIZE), offset; - Uint uint_size; + tree offset; if (Is_Derived_Type (gnat_entity)) { @@ -5338,7 +5346,12 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) Set_Alignment (gnat_entity, Alignment (gnat_parent)); } else - offset = pointer_size; + { + unsigned int align + = MAX (TYPE_ALIGN (gnu_type), POINTER_SIZE) / BITS_PER_UNIT; + offset = bitsize_int (POINTER_SIZE); + Set_Alignment (gnat_entity, UI_From_Int (align)); + } if (TYPE_FIELDS (gnu_type)) offset @@ -5346,10 +5359,22 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) gnu_size = size_binop (PLUS_EXPR, gnu_size, offset); gnu_size = round_up (gnu_size, POINTER_SIZE); - uint_size = annotate_value (gnu_size); - Set_Esize (gnat_entity, uint_size); + Uint uint_size = annotate_value (gnu_size); Set_RM_Size (gnat_entity, uint_size); + Set_Esize (gnat_entity, uint_size); + } + + /* If there is a rep clause, only adjust alignment and Esize. */ + else if (type_annotate_only && Is_Tagged_Type (gnat_entity)) + { + unsigned int align + = MAX (TYPE_ALIGN (gnu_type), POINTER_SIZE) / BITS_PER_UNIT; + Set_Alignment (gnat_entity, UI_From_Int (align)); + gnu_size = round_up (gnu_size, POINTER_SIZE); + Set_Esize (gnat_entity, annotate_value (gnu_size)); } + + /* Otherwise no adjustment is needed. */ else Set_Esize (gnat_entity, annotate_value (gnu_size)); } @@ -7933,12 +7958,19 @@ annotate_rep (Entity_Id gnat_entity, tree gnu_type) { /* If there is no entry, this is an inherited component whose position is the same as in the parent type. */ - Set_Component_Bit_Offset - (gnat_field, - Component_Bit_Offset (Original_Record_Component (gnat_field))); + Entity_Id gnat_orig_field = Original_Record_Component (gnat_field); - Set_Esize (gnat_field, - Esize (Original_Record_Component (gnat_field))); + /* If we are just annotating types, discriminants renaming those of + the parent have no entry so deal with them specifically. */ + if (type_annotate_only + && gnat_orig_field == gnat_field + && Ekind (gnat_field) == E_Discriminant) + gnat_orig_field = Corresponding_Discriminant (gnat_field); + + Set_Component_Bit_Offset (gnat_field, + Component_Bit_Offset (gnat_orig_field)); + + Set_Esize (gnat_field, Esize (gnat_orig_field)); } } } -- 2.30.2