https://gcc.gnu.org/g:6f5035b0d710e540b283e9526298a8e33b5e5f4b
commit r16-1922-g6f5035b0d710e540b283e9526298a8e33b5e5f4b Author: Eric Botcazou <ebotca...@adacore.com> Date: Tue May 27 13:32:18 2025 +0200 ada: Fix wrong conversion of controlled array with representation change The problem is that a temporary is created for the conversion because of the representation change, and it is finalized without having been initialized. gcc/ada/ChangeLog: * exp_ch4.adb (Handle_Changed_Representation): Alphabetize local variables. Set the No_Finalize_Actions flag on the assignment. Diff: --- gcc/ada/exp_ch4.adb | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index b4270021fafd..a845982d6908 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -11285,11 +11285,12 @@ package body Exp_Ch4 is ----------------------------------- procedure Handle_Changed_Representation is - Temp : Entity_Id; + Cons : List_Id; Decl : Node_Id; - Odef : Node_Id; N_Ix : Node_Id; - Cons : List_Id; + Odef : Node_Id; + Stmt : Node_Id; + Temp : Entity_Id; begin -- Nothing else to do if no change of representation @@ -11432,19 +11433,24 @@ package body Exp_Ch4 is Defining_Identifier => Temp, Object_Definition => Odef); - Set_No_Initialization (Decl, True); + -- The temporary need not be initialized + + Set_No_Initialization (Decl); + + Stmt := + Make_Assignment_Statement (Loc, + Name => New_Occurrence_Of (Temp, Loc), + Expression => Relocate_Node (N)); + + -- And, therefore, cannot be finalized + + Set_No_Finalize_Actions (Stmt); -- Insert required actions. It is essential to suppress checks -- since we have suppressed default initialization, which means -- that the variable we create may have no discriminants. - Insert_Actions (N, - New_List ( - Decl, - Make_Assignment_Statement (Loc, - Name => New_Occurrence_Of (Temp, Loc), - Expression => Relocate_Node (N))), - Suppress => All_Checks); + Insert_Actions (N, New_List (Decl, Stmt), Suppress => All_Checks); Rewrite (N, New_Occurrence_Of (Temp, Loc)); return;