]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix strange holes for type with variant part reported by -gnatRh
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 9 Jun 2025 19:45:45 +0000 (21:45 +0200)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Thu, 3 Jul 2025 08:16:26 +0000 (10:16 +0200)
The problem is that the sorting algorithm mixes components of variants.

gcc/ada/ChangeLog:

* repinfo.adb (First_Comp_Or_Discr.Is_Placed_Before): Return True
only if the components are in the same component list.

gcc/ada/repinfo.adb

index 1d616db71f30f8fd43703c81a81858d0010eaab8..bbf92a7780076fe2f588eed02cb4053e23716a6b 100644 (file)
@@ -1239,15 +1239,25 @@ package body Repinfo is
          function First_Comp_Or_Discr (Ent : Entity_Id) return Entity_Id is
 
             function Is_Placed_Before (C1, C2 : Entity_Id) return Boolean;
-            --  Return True if component C1 is placed before component C2
+            --  Return True if components C1 and C2 are in the same component
+            --  list and component C1 is placed before component C2 in there.
 
             ----------------------
             -- Is_Placed_Before --
             ----------------------
 
             function Is_Placed_Before (C1, C2 : Entity_Id) return Boolean is
+               L1 : constant Node_Id := Parent (Parent (C1));
+               L2 : constant Node_Id := Parent (Parent (C2));
+
             begin
-               return Known_Static_Component_Bit_Offset (C1)
+               --  Discriminants and top-level components are considered to be
+               --  in the same list, although this is not syntactically true.
+
+               return (L1 = L2
+                        or else (Nkind (Parent (L1)) /= N_Variant
+                                  and then Nkind (Parent (L2)) /= N_Variant))
+                 and then Known_Static_Component_Bit_Offset (C1)
                  and then Known_Static_Component_Bit_Offset (C2)
                  and then
                    Component_Bit_Offset (C1) < Component_Bit_Offset (C2);