https://gcc.gnu.org/g:bcf47b4d18378a90b3529b48d8d6e9085788f83b
commit r13-9167-gbcf47b4d18378a90b3529b48d8d6e9085788f83b Author: Eric Botcazou <ebotca...@adacore.com> Date: Fri Aug 16 16:03:30 2024 +0200 ada: Fix internal error on concatenation of discriminant-dependent component This only occurs with optimization enabled, but the expanded code is always wrong because it reuses the formal parameter of an initialization procedure associated with a discriminant (a discriminal in GNAT parlance) outside of the initialization procedure. gcc/ada/ * checks.adb (Selected_Length_Checks.Get_E_Length): For a component of a record with discriminants and if the expression is a selected component, try to build an actual subtype from its prefix instead of from the discriminal. Diff: --- gcc/ada/checks.adb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index ca6fe42d967a..bce7d8f8b8a7 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -9779,7 +9779,15 @@ package body Checks is if Ekind (Scope (E)) = E_Record_Type and then Has_Discriminants (Scope (E)) then - N := Build_Discriminal_Subtype_Of_Component (E); + -- If the expression is a selected component, in other words, + -- has a prefix, then build an actual subtype from the prefix. + -- Otherwise, build an actual subtype from the discriminal. + + if Nkind (Expr) = N_Selected_Component then + N := Build_Actual_Subtype_Of_Component (E, Expr); + else + N := Build_Discriminal_Subtype_Of_Component (E); + end if; if Present (N) then Insert_Action (Expr, N);