]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix iterated component initialization
authorMarc Poulhiès <poulhies@adacore.com>
Tue, 11 Apr 2023 07:46:33 +0000 (09:46 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 13 Jun 2023 07:31:45 +0000 (09:31 +0200)
The call to Resolve_Aggr_Expr may leave references to temporary entities
used to check for the construct legality and meant to be removed.

Using Preanalyze_And_Resolve correctly guarantees that there is no
visible occurrence of such entities.

gcc/ada/

* sem_aggr.adb (Resolve_Iterated_Component_Association): Call
Preanalyze_And_Resolve instead of Resolve_Aggr_Expr except for
aggregate.

Co-authored-by: Ed Schonberg <schonberg@adacore.com>
gcc/ada/sem_aggr.adb

index 3b2d0347b41b73297f5f8ad2789725ba1318cd1b..843606ab4a1945c6d1c984e202b23ebab5b6ee90 100644 (file)
@@ -1862,9 +1862,14 @@ package body Sem_Aggr is
 
          Expr := Expression (N);
 
-         Expander_Mode_Save_And_Set (False);
-         Dummy := Resolve_Aggr_Expr (Expr, Single_Elmt => False);
-         Expander_Mode_Restore;
+         if Nkind (Expr) = N_Aggregate then
+            --  If the expression is an aggregate, this is a multidimensional
+            --  aggregate where the component type must be propagated downward.
+
+            Dummy := Resolve_Aggr_Expr (Expr, Single_Elmt => False);
+         else
+            Preanalyze_And_Resolve (Expr, Component_Typ);
+         end if;
 
          if Operating_Mode /= Check_Semantics then
             Remove_References (Expr);