Skip to content

Commit 82835a1

Browse files
author
pmderodat
committed
[Ada] Fix irregular output with -gnatR3
This fixes a long-standing quirk present in the layout information for record types displayed by the -gnatR3 switch: when a component has a variable (starting) position, its corresponding line in the output has an irregular and awkward format. After this change, the format is the same as in all the other cases. For the following record: type R (m : natural) is record s : string (1 .. m); r : natural; b : boolean; end record; for R'alignment use 4; pragma Pack (R); the output of -gnatR3 used to be: for R'Object_Size use 17179869248; for R'Value_Size use ((#1 + 8) * 8); for R'Alignment use 4; for R use record m at 0 range 0 .. 30; s at 4 range 0 .. ((#1 * 8)) - 1; r at bit offset (((#1 + 4) * 8)) size in bits = 31 b at bit offset ((((#1 + 7) * 8) + 7)) size in bits = 1 end record; and is changed into: for R'Object_Size use 17179869248; for R'Value_Size use ((#1 + 8) * 8); for R'Alignment use 4; for R use record m at 0 range 0 .. 30; s at 4 range 0 .. ((#1 * 8)) - 1; r at (#1 + 4) range 0 .. 30; b at (#1 + 7) range 7 .. 7; end record; 2018-05-24 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * fe.h (Set_Normalized_First_Bit): Declare. (Set_Normalized_Position): Likewise. * repinfo.adb (List_Record_Layout): Do not use irregular output for a variable position. Fix minor spacing issue. * gcc-interface/decl.c (annotate_rep): If a field has a variable offset, compute the normalized position and annotate it in addition to the bit offset. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@260669 138bc75d-0d04-0410-961f-82ee72b054a4
1 parent 84cb8ff commit 82835a1

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

gcc/ada/ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2018-05-24 Eric Botcazou <ebotcazou@adacore.com>
2+
3+
* fe.h (Set_Normalized_First_Bit): Declare.
4+
(Set_Normalized_Position): Likewise.
5+
* repinfo.adb (List_Record_Layout): Do not use irregular output for a
6+
variable position. Fix minor spacing issue.
7+
* gcc-interface/decl.c (annotate_rep): If a field has a variable
8+
offset, compute the normalized position and annotate it in addition to
9+
the bit offset.
10+
111
2018-05-24 Eric Botcazou <ebotcazou@adacore.com>
212

313
* gcc-interface/trans.c (Handled_Sequence_Of_Statements_to_gnu):

gcc/ada/fe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,17 @@ extern Boolean Debug_Flag_NN;
6868
#define Set_Component_Size einfo__set_component_size
6969
#define Set_Esize einfo__set_esize
7070
#define Set_Mechanism einfo__set_mechanism
71+
#define Set_Normalized_First_Bit einfo__set_normalized_first_bit
72+
#define Set_Normalized_Position einfo__set_normalized_position
7173
#define Set_RM_Size einfo__set_rm_size
7274

7375
extern void Set_Alignment (Entity_Id, Uint);
7476
extern void Set_Component_Bit_Offset (Entity_Id, Uint);
7577
extern void Set_Component_Size (Entity_Id, Uint);
7678
extern void Set_Esize (Entity_Id, Uint);
7779
extern void Set_Mechanism (Entity_Id, Mechanism_Type);
80+
extern void Set_Normalized_First_Bit (Entity_Id, Uint);
81+
extern void Set_Normalized_Position (Entity_Id, Uint);
7882
extern void Set_RM_Size (Entity_Id, Uint);
7983

8084
#define Is_Entity_Name einfo__is_entity_name

gcc/ada/gcc-interface/decl.c

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8291,7 +8291,8 @@ annotate_rep (Entity_Id gnat_entity, tree gnu_type)
82918291
gnu_list);
82928292
if (t)
82938293
{
8294-
tree parent_offset;
8294+
tree offset = TREE_VEC_ELT (TREE_VALUE (t), 0);
8295+
tree bit_offset = TREE_VEC_ELT (TREE_VALUE (t), 2);
82958296

82968297
/* If we are just annotating types and the type is tagged, the tag
82978298
and the parent components are not generated by the front-end so
@@ -8301,31 +8302,46 @@ annotate_rep (Entity_Id gnat_entity, tree gnu_type)
83018302
&& Is_Tagged_Type (gnat_entity)
83028303
&& No (Component_Clause (gnat_field)))
83038304
{
8305+
tree parent_bit_offset;
8306+
83048307
/* For a component appearing in the current extension, the
83058308
offset is the size of the parent. */
83068309
if (Is_Derived_Type (gnat_entity)
83078310
&& Original_Record_Component (gnat_field) == gnat_field)
8308-
parent_offset
8311+
parent_bit_offset
83098312
= UI_To_gnu (Esize (Etype (Base_Type (gnat_entity))),
83108313
bitsizetype);
83118314
else
8312-
parent_offset = bitsize_int (POINTER_SIZE);
8315+
parent_bit_offset = bitsize_int (POINTER_SIZE);
83138316

83148317
if (TYPE_FIELDS (gnu_type))
8315-
parent_offset
8316-
= round_up (parent_offset,
8318+
parent_bit_offset
8319+
= round_up (parent_bit_offset,
83178320
DECL_ALIGN (TYPE_FIELDS (gnu_type)));
8321+
8322+
offset
8323+
= size_binop (PLUS_EXPR, offset,
8324+
fold_convert (sizetype,
8325+
size_binop (TRUNC_DIV_EXPR,
8326+
parent_bit_offset,
8327+
bitsize_unit_node)));
8328+
}
8329+
8330+
/* If the field has a variable offset, also compute the normalized
8331+
position since it's easier to do on trees here than to deduce
8332+
it from the annotated expression of Component_Bit_Offset. */
8333+
if (TREE_CODE (offset) != INTEGER_CST)
8334+
{
8335+
normalize_offset (&offset, &bit_offset, BITS_PER_UNIT);
8336+
Set_Normalized_Position (gnat_field,
8337+
annotate_value (offset));
8338+
Set_Normalized_First_Bit (gnat_field,
8339+
annotate_value (bit_offset));
83188340
}
8319-
else
8320-
parent_offset = bitsize_zero_node;
83218341

83228342
Set_Component_Bit_Offset
83238343
(gnat_field,
8324-
annotate_value
8325-
(size_binop (PLUS_EXPR,
8326-
bit_from_pos (TREE_VEC_ELT (TREE_VALUE (t), 0),
8327-
TREE_VEC_ELT (TREE_VALUE (t), 2)),
8328-
parent_offset)));
8344+
annotate_value (bit_from_pos (offset, bit_offset)));
83298345

83308346
Set_Esize (gnat_field,
83318347
annotate_value (DECL_SIZE (TREE_PURPOSE (t))));
@@ -8334,19 +8350,27 @@ annotate_rep (Entity_Id gnat_entity, tree gnu_type)
83348350
{
83358351
/* If there is no entry, this is an inherited component whose
83368352
position is the same as in the parent type. */
8337-
Entity_Id gnat_orig_field = Original_Record_Component (gnat_field);
8353+
Entity_Id gnat_orig = Original_Record_Component (gnat_field);
83388354

83398355
/* If we are just annotating types, discriminants renaming those of
83408356
the parent have no entry so deal with them specifically. */
83418357
if (type_annotate_only
8342-
&& gnat_orig_field == gnat_field
8358+
&& gnat_orig == gnat_field
83438359
&& Ekind (gnat_field) == E_Discriminant)
8344-
gnat_orig_field = Corresponding_Discriminant (gnat_field);
8360+
gnat_orig = Corresponding_Discriminant (gnat_field);
8361+
8362+
if (Known_Normalized_Position (gnat_orig))
8363+
{
8364+
Set_Normalized_Position (gnat_field,
8365+
Normalized_Position (gnat_orig));
8366+
Set_Normalized_First_Bit (gnat_field,
8367+
Normalized_First_Bit (gnat_orig));
8368+
}
83458369

83468370
Set_Component_Bit_Offset (gnat_field,
8347-
Component_Bit_Offset (gnat_orig_field));
8371+
Component_Bit_Offset (gnat_orig));
83488372

8349-
Set_Esize (gnat_field, Esize (gnat_orig_field));
8373+
Set_Esize (gnat_field, Esize (gnat_orig));
83508374
}
83518375
}
83528376
}

gcc/ada/repinfo.adb

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ package body Repinfo is
992992
declare
993993
Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp));
994994
Esiz : constant Uint := Esize (Comp);
995-
Bofs : constant Uint := Component_Bit_Offset (Comp);
996995
Npos : constant Uint := Normalized_Position (Comp);
997996
Fbit : constant Uint := Normalized_First_Bit (Comp);
998997
Spos : Uint;
@@ -1047,35 +1046,14 @@ package body Repinfo is
10471046
Spaces (Max_Spos_Length - UI_Image_Length);
10481047
Write_Str (UI_Image_Buffer (1 .. UI_Image_Length));
10491048

1050-
elsif Known_Component_Bit_Offset (Comp)
1051-
and then List_Representation_Info = 3
1052-
then
1053-
Spaces (Max_Spos_Length - 2);
1054-
Write_Str ("bit offset ");
1055-
1056-
if Starting_Position /= Uint_0
1057-
or else Starting_First_Bit /= Uint_0
1058-
then
1059-
UI_Write (Starting_Position * SSU + Starting_First_Bit);
1060-
Write_Str (" + ");
1061-
end if;
1062-
1063-
Write_Val (Bofs, Paren => True);
1064-
Write_Str (" size in bits = ");
1065-
Write_Val (Esiz, Paren => True);
1066-
Write_Eol;
1067-
1068-
goto Continue;
1069-
10701049
elsif Known_Normalized_Position (Comp)
10711050
and then List_Representation_Info = 3
10721051
then
10731052
Spaces (Max_Spos_Length - 2);
10741053

10751054
if Starting_Position /= Uint_0 then
1076-
Write_Char (' ');
10771055
UI_Write (Starting_Position);
1078-
Write_Str (" +");
1056+
Write_Str (" + ");
10791057
end if;
10801058

10811059
Write_Val (Npos);

0 commit comments

Comments
 (0)