https://gcc.gnu.org/g:027457ded6416c36f5b76a24153a69b7ff3f2f0e
commit r16-1327-g027457ded6416c36f5b76a24153a69b7ff3f2f0e Author: Bob Duff <d...@adacore.com> Date: Thu Mar 6 14:21:51 2025 -0500 ada: Back out removal of renaming tranformation A previous change (commit 33eebd96d27fa2b29cec79f55167a11aaf7f4802) removed code in Analyze_Object_Renaming that tranformed renamings into object declarations. This reinstates that code. Removing the code causes failures in gnatbugs-large/2023/gnat-435_deep_blue_capital. Ideally, we SHOULD remove that transformation at some point, but that will require further changes. gcc/ada/ChangeLog: * exp_ch6.adb: (Make_Build_In_Place_Call_In_Object_Declaration): Deal with renamings transformed into object declarations. * sem_ch8.adb (Analyze_Object_Renaming): Reinstate transformation of a renaming into an object declaration. Diff: --- gcc/ada/exp_ch6.adb | 6 ++++++ gcc/ada/sem_ch8.adb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/gcc/ada/exp_ch6.adb b/gcc/ada/exp_ch6.adb index 84847377bf33..3a45b1c59340 100644 --- a/gcc/ada/exp_ch6.adb +++ b/gcc/ada/exp_ch6.adb @@ -8819,6 +8819,8 @@ package body Exp_Ch6 is Constraint_Check_Needed : constant Boolean := (Has_Discriminants (Obj_Typ) or else Is_Array_Type (Obj_Typ)) and then Is_Tagged_Type (Obj_Typ) + and then Nkind (Original_Node (Obj_Decl)) /= + N_Object_Renaming_Declaration and then Is_Constrained (Obj_Typ); -- We are processing a call in the context of something like -- "X : T := F (...);". This is True if we need to do a constraint @@ -8828,6 +8830,10 @@ package body Exp_Ch6 is -- which is possible only in the callee-allocates case, -- which is why we have Is_Tagged_Type above. -- ???The check is missing in the untagged caller-allocates case. + -- ???The check for renaming declarations above is needed because + -- Sem_Ch8.Analyze_Object_Renaming sometimes changes a renaming + -- into an object declaration. We probably shouldn't do that, + -- but for now, we need this check. -- Start of processing for Make_Build_In_Place_Call_In_Object_Declaration diff --git a/gcc/ada/sem_ch8.adb b/gcc/ada/sem_ch8.adb index 4ed0598bcec9..db892d0a5bef 100644 --- a/gcc/ada/sem_ch8.adb +++ b/gcc/ada/sem_ch8.adb @@ -1149,6 +1149,29 @@ package body Sem_Ch8 is Resolve (Nam, T); + -- If the renamed object is a function call of a limited type, + -- the expansion of the renaming is complicated by the presence + -- of various temporaries and subtypes that capture constraints + -- of the renamed object. Rewrite node as an object declaration, + -- whose expansion is simpler. Given that the object is limited + -- there is no copy involved and no performance hit. + + if Nkind (Nam) = N_Function_Call + and then Is_Inherently_Limited_Type (Etype (Nam)) + and then not Is_Constrained (Etype (Nam)) + and then Comes_From_Source (N) + then + Set_Etype (Id, T); + Mutate_Ekind (Id, E_Constant); + Rewrite (N, + Make_Object_Declaration (Loc, + Defining_Identifier => Id, + Constant_Present => True, + Object_Definition => New_Occurrence_Of (Etype (Nam), Loc), + Expression => Relocate_Node (Nam))); + return; + end if; + -- Ada 2012 (AI05-149): Reject renaming of an anonymous access object -- when renaming declaration has a named access type. The Ada 2012 -- coverage rules allow an anonymous access type in the context of