]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix internal error on concatenation of discriminant-dependent component
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 16 Aug 2024 14:03:30 +0000 (16:03 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Mon, 4 Nov 2024 10:50:31 +0000 (11:50 +0100)
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.

gcc/ada/checks.adb

index e1a1b0cfec1b62b80d7623a5bc87c99e0a7df5b8..449aa6578ac93de22c627880117939ed5aea8152 100644 (file)
@@ -9936,7 +9936,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);