This patch fixes a compiler abort on a declaration of subtype of a
derived type DT whose declaration renames a discriminant of its parent
type T, when there is a record representation clause for DT.

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

gcc/ada/

        * exp_ch5.adb (Find_Component): If the target type is a derived
        record type and the required component is a discriminant that is
        renamed in the derived type declaration, use the name of the
        original discriminant to locate the intended target component.
diff --git a/gcc/ada/exp_ch5.adb b/gcc/ada/exp_ch5.adb
--- a/gcc/ada/exp_ch5.adb
+++ b/gcc/ada/exp_ch5.adb
@@ -1594,6 +1594,18 @@ package body Exp_Ch5 is
             while Present (C) loop
                if Chars (C) = Chars (Comp) then
                   return C;
+
+               --  The component may be a renamed discriminant, in
+               --  which case check against the name of the original
+               --  discriminant of the parent type.
+
+               elsif Is_Derived_Type (Scope (Comp))
+                 and then Ekind (Comp) = E_Discriminant
+                 and then Present (Corresponding_Discriminant (Comp))
+                 and then
+                   Chars (C) = Chars (Corresponding_Discriminant (Comp))
+               then
+                  return C;
                end if;
 
                Next_Entity (C);


Reply via email to