From 02a8253980d04638085237915498acd04297fbbf Mon Sep 17 00:00:00 2001 From: Ed Schonberg Date: Mon, 21 Sep 2020 11:54:09 -0400 Subject: [PATCH] [Ada] Handle Iterated_Component_Association with Others_Choice gcc/ada/ * exp_aggr.adb (Build_Array_Aggr_Code): If the aggregate includes an Others_Choice in an association that is an Iterated_Component_Association, generate a proper loop for it. --- gcc/ada/exp_aggr.adb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 469777f..986ccc9 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -2448,18 +2448,30 @@ package body Exp_Aggr is Next (Expr); end loop; - -- STEP 2 (b): Generate final loop if an others choice is present + -- STEP 2 (b): Generate final loop if an others choice is present. -- Here Nb_Elements gives the offset of the last positional element. if Present (Component_Associations (N)) then Assoc := Last (Component_Associations (N)); - -- Ada 2005 (AI-287) + if Nkind (Assoc) = N_Iterated_Component_Association then + -- Ada 2020: generate a loop to have a proper scope for + -- the identifier that typically appears in the expression. + -- The lower bound of the loop is the position after all + -- previous positional components. - Append_List (Gen_While (Add (Nb_Elements, To => Aggr_L), - Aggr_High, - Get_Assoc_Expr (Assoc)), -- AI-287 - To => New_Code); + Append_List (Gen_Loop (Add (Nb_Elements + 1, To => Aggr_L), + Aggr_High, + Expression (Assoc)), + To => New_Code); + else + -- Ada 2005 (AI-287) + + Append_List (Gen_While (Add (Nb_Elements, To => Aggr_L), + Aggr_High, + Get_Assoc_Expr (Assoc)), + To => New_Code); + end if; end if; end if; -- 2.7.4