From: Eric Botcazou <ebotca...@adacore.com> The (minimal) expansion is now done by Build_Array_Aggr_Code in all cases, which means that it must prevent the aggregate from being re-analyzed as the RHS of the assignment, which may trigger a bogus warning and lead to another useless rewriting.
The change also inlines Build_Assignment_With_Temporary that is now called only once by Build_Array_Aggr_Code for this processing. gcc/ada/ChangeLog: * exp_aggr.adb (Build_Assignment_With_Temporary): Inline into... (Build_Array_Aggr_Code): ...this. Set the Analyzed flag on the relocated aggregate if it is to be handled by the back-end. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_aggr.adb | 71 ++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index c34df840401..a82705dca3f 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -78,13 +78,6 @@ with Warnsw; use Warnsw; package body Exp_Aggr is - function Build_Assignment_With_Temporary - (Target : Node_Id; - Typ : Entity_Id; - Source : Node_Id) return List_Id; - -- Returns a list of actions to assign Source to Target of type Typ using - -- an extra temporary, which can potentially be large. - type Case_Bounds is record Choice_Lo : Node_Id; Choice_Hi : Node_Id; @@ -1925,8 +1918,8 @@ package body Exp_Aggr is -- Start of processing for Build_Array_Aggr_Code begin - -- If the assignment can be done directly by the back end, then reset - -- the Set_Expansion_Delayed flag and do not expand further. + -- If the assignment can be done directly by the back end, then expand + -- into an assignment statement. if Present (Etype (N)) and then Aggr_Assignment_OK_For_Backend (N) @@ -1940,7 +1933,13 @@ package body Exp_Aggr is (if Nkind (Into) = N_Unchecked_Type_Conversion then Expression (Into) else Into); + + Temp : Node_Id; + begin + -- Block any further processing of the aggregate by the front end + + Set_Analyzed (New_Aggr); Set_Expansion_Delayed (New_Aggr, False); -- In the case where the target is the dereference of a prefix @@ -1956,7 +1955,23 @@ package body Exp_Aggr is (Storage_Model_Object (Etype (Prefix (Target))))) then - return Build_Assignment_With_Temporary (Into, Typ, New_Aggr); + Temp := Build_Temporary_On_Secondary_Stack (Loc, Typ, New_Code); + + Append_To (New_Code, + Make_OK_Assignment_Statement (Loc, + Name => + Make_Explicit_Dereference (Loc, + Prefix => New_Occurrence_Of (Temp, Loc)), + Expression => New_Aggr)); + + Append_To (New_Code, + Make_OK_Assignment_Statement (Loc, + Name => Target, + Expression => + Make_Explicit_Dereference (Loc, + Prefix => New_Occurrence_Of (Temp, Loc)))); + + return New_Code; else return New_List ( @@ -2159,42 +2174,6 @@ package body Exp_Aggr is return New_Code; end Build_Array_Aggr_Code; - ------------------------------------- - -- Build_Assignment_With_Temporary -- - ------------------------------------- - - function Build_Assignment_With_Temporary - (Target : Node_Id; - Typ : Entity_Id; - Source : Node_Id) return List_Id - is - Loc : constant Source_Ptr := Sloc (Source); - - Aggr_Code : List_Id; - Tmp : Entity_Id; - - begin - Aggr_Code := New_List; - - Tmp := Build_Temporary_On_Secondary_Stack (Loc, Typ, Aggr_Code); - - Append_To (Aggr_Code, - Make_OK_Assignment_Statement (Loc, - Name => - Make_Explicit_Dereference (Loc, - Prefix => New_Occurrence_Of (Tmp, Loc)), - Expression => Source)); - - Append_To (Aggr_Code, - Make_OK_Assignment_Statement (Loc, - Name => Target, - Expression => - Make_Explicit_Dereference (Loc, - Prefix => New_Occurrence_Of (Tmp, Loc)))); - - return Aggr_Code; - end Build_Assignment_With_Temporary; - ---------------------------- -- Build_Record_Aggr_Code -- ---------------------------- -- 2.43.0