https://gcc.gnu.org/g:93d5053b1f3ab546808d81d1ef4955e448fb751b
commit r16-1945-g93d5053b1f3ab546808d81d1ef4955e448fb751b Author: Eric Botcazou <ebotca...@adacore.com> Date: Mon Jun 9 21:45:45 2025 +0200 ada: Fix strange holes for type with variant part reported by -gnatRh 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. Diff: --- gcc/ada/repinfo.adb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gcc/ada/repinfo.adb b/gcc/ada/repinfo.adb index 1d616db71f30..bbf92a778007 100644 --- a/gcc/ada/repinfo.adb +++ b/gcc/ada/repinfo.adb @@ -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);