[Ada] Small fix for couple of internal glitches with record layout

Arnaud Charlet charlet@adacore.com
Fri Sep 8 08:59:00 GMT 2017


This change ensures that (1) -gnatR always displays the record layout that was
used internally by the compiler for code generation and (2) the record layout
is fully adjusted internally when the reverse bit order is specified.

No functional changes expected because the first issue was papering over the
second issue and the second issue was very likely harmless in practice since
the normalized position is redundant with the bit offset, which was correct.

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-09-08  Eric Botcazou  <ebotcazou@adacore.com>

	* repinfo.adb (List_Record_Info): During first loop,
	do not override the normalized position and first bit
	if they have already been set.	Move fallback code
	for the packed case to the case where it belongs.
	* sem_ch13.adb (Adjust_Record_For_Reverse_Bit_Order):
	Also adjust the normalized position of components.
	(Adjust_Record_For_Reverse_Bit_Order_Ada_95): Likewise.

-------------- next part --------------
Index: repinfo.adb
===================================================================
--- repinfo.adb	(revision 251863)
+++ repinfo.adb	(working copy)
@@ -894,30 +894,30 @@
             Cfbit := Component_Bit_Offset (Comp);
 
             if Rep_Not_Constant (Cfbit) then
-               UI_Image_Length := 2;
+               --  If the record is not packed, then we know that all fields
+               --  whose position is not specified have a starting normalized
+               --  bit position of zero.
 
+               if Unknown_Normalized_First_Bit (Comp)
+                 and then not Is_Packed (Ent)
+               then
+                  Set_Normalized_First_Bit (Comp, Uint_0);
+               end if;
+
+               UI_Image_Length := 2; -- For "??" marker
             else
                --  Complete annotation in case not done
 
-               Set_Normalized_Position (Comp, Cfbit / SSU);
-               Set_Normalized_First_Bit (Comp, Cfbit mod SSU);
+               if Unknown_Normalized_First_Bit (Comp) then
+                  Set_Normalized_Position (Comp, Cfbit / SSU);
+                  Set_Normalized_First_Bit (Comp, Cfbit mod SSU);
+               end if;
 
                Sunit := Cfbit / SSU;
                UI_Image (Sunit);
             end if;
 
-            --  If the record is not packed, then we know that all fields
-            --  whose position is not specified have a starting normalized
-            --  bit position of zero.
-
-            if Unknown_Normalized_First_Bit (Comp)
-              and then not Is_Packed (Ent)
-            then
-               Set_Normalized_First_Bit (Comp, Uint_0);
-            end if;
-
-            Max_Suni_Length :=
-              Natural'Max (Max_Suni_Length, UI_Image_Length);
+            Max_Suni_Length := Natural'Max (Max_Suni_Length, UI_Image_Length);
          end if;
 
          Next_Component_Or_Discriminant (Comp);
Index: sem_ch13.adb
===================================================================
--- sem_ch13.adb	(revision 251866)
+++ sem_ch13.adb	(working copy)
@@ -627,6 +627,7 @@
                   end if;
 
                   Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
+                  Set_Normalized_Position  (Comp, Pos + NFB / SSU);
                   Set_Normalized_First_Bit (Comp, NFB mod SSU);
                end;
             end loop;
@@ -750,6 +751,9 @@
                       (System_Storage_Unit - 1) -
                       (Start_Bit + CSZ - 1));
 
+                  Set_Normalized_Position (Comp,
+                    Component_Bit_Offset (Comp) / System_Storage_Unit);
+
                   Set_Normalized_First_Bit (Comp,
                     Component_Bit_Offset (Comp) mod System_Storage_Unit);
                end if;


More information about the Gcc-patches mailing list