[Ada] Call-initialize all controlled objects in place
commitc901877facf9635149ed69cabd88c871f60931fe
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 26 May 2022 09:06:01 +0000 (26 11:06 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Mon, 4 Jul 2022 07:45:55 +0000 (4 07:45 +0000)
tree507d544b31199e0fd649a8c297653e6120f02eae
parenteb6e8a7acd1b8ecf36489e01cafad61add528f23
[Ada] Call-initialize all controlled objects in place

This changes the compiler to build in place almost all objects that need
finalization and are initialized with the result of a function call, thus
saving a pair of Adjust/Finalize calls for the anonymous return object.

gcc/ada/

* exp_ch3.adb (Expand_N_Object_Declaration): Don't adjust the object
if the expression is a function call.
<Rewrite_As_Renaming>: Return true if the object needs finalization
and is initialized  with the result of a function call returned on
the secondary stack.
* exp_ch6.adb (Expand_Ctrl_Function_Call): Add Use_Sec_Stack boolean
parameter.  Early return if the parent is an object declaration and
Use_Sec_Stack is false.
(Expand_Call_Helper): Adjust call to Expand_Ctrl_Function_Call.
* exp_ch7.adb (Find_Last_Init): Be prepared for initialization still
present in the object declaration.
* sem_ch3.adb (Analyze_Object_Declaration): Call the predicates
Needs_Secondary_Stack and Needs_Finalization to guard the renaming
optimization.
gcc/ada/exp_ch3.adb
gcc/ada/exp_ch6.adb
gcc/ada/exp_ch7.adb
gcc/ada/sem_ch3.adb