This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Ada] Improve output of -gnatR? for discriminated extensions
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 27 Oct 2009 21:27:34 +0100
- Subject: [Ada] Improve output of -gnatR? for discriminated extensions
For the extension Rec2 of discriminated tagged type Rec1:
type Arr is array (Positive range <>) of Natural;
type Rec1 (D : Positive) is tagged record
A : Arr (1..D);
I : Integer;
end record;
type Rec2 is new Rec1 (1) with null record;
the output of -gnatR1 is:
for Rec2'Size use 128;
for Rec2'Alignment use 4;
for Rec2 use record
D at 4 range 0 .. 31;
_Tag at 0 range 0 .. 31;
A at 8 range 0 .. ??;
I at ?? range 0 .. 31;
_Parent at 0 range 0 .. 127;
end record;
which is suboptimal since all fields have fixed position and size.
Tested on i586-suse-linux, applied on the mainline.
2009-10-27 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (purpose_member_field): New static function.
(annotate_rep): Use it instead of purpose_member.
--
Eric Botcazou
Index: gcc-interface/decl.c
===================================================================
--- gcc-interface/decl.c (revision 153615)
+++ gcc-interface/decl.c (working copy)
@@ -7231,6 +7231,23 @@ annotate_object (Entity_Id gnat_entity,
UI_From_Int (TYPE_ALIGN (gnu_type) / BITS_PER_UNIT));
}
+/* Return first element of field list whose TREE_PURPOSE is ELEM or whose
+ DECL_ORIGINAL_FIELD of TREE_PURPOSE is ELEM. Return NULL_TREE if there
+ is no such element in the list. */
+
+static tree
+purpose_member_field (const_tree elem, tree list)
+{
+ while (list)
+ {
+ tree field = TREE_PURPOSE (list);
+ if (elem == field || elem == DECL_ORIGINAL_FIELD (field))
+ return list;
+ list = TREE_CHAIN (list);
+ }
+ return NULL_TREE;
+}
+
/* Given GNAT_ENTITY, a record type, and GNU_TYPE, its corresponding GCC type,
set Component_Bit_Offset and Esize of the components to the position and
size used by Gigi. */
@@ -7254,11 +7271,12 @@ annotate_rep (Entity_Id gnat_entity, tre
|| (Ekind (gnat_field) == E_Discriminant
&& !Is_Unchecked_Union (Scope (gnat_field))))
{
- tree parent_offset, t;
-
- t = purpose_member (gnat_to_gnu_field_decl (gnat_field), gnu_list);
+ tree t = purpose_member_field (gnat_to_gnu_field_decl (gnat_field),
+ gnu_list);
if (t)
{
+ tree parent_offset;
+
if (type_annotate_only && Is_Tagged_Type (gnat_entity))
{
/* In this mode the tag and parent components are not