aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/sem_ch3.adb
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2022-05-26 11:06:01 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2022-07-04 07:45:55 +0000
commitc901877facf9635149ed69cabd88c871f60931fe (patch)
tree507d544b31199e0fd649a8c297653e6120f02eae /gcc/ada/sem_ch3.adb
parenteb6e8a7acd1b8ecf36489e01cafad61add528f23 (diff)
downloadgcc-c901877facf9635149ed69cabd88c871f60931fe.zip
gcc-c901877facf9635149ed69cabd88c871f60931fe.tar.gz
gcc-c901877facf9635149ed69cabd88c871f60931fe.tar.bz2
[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.
Diffstat (limited to 'gcc/ada/sem_ch3.adb')
-rw-r--r--gcc/ada/sem_ch3.adb10
1 files changed, 5 insertions, 5 deletions
diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 2dbba15..3bbb788 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -5046,21 +5046,21 @@ package body Sem_Ch3 is
end if;
-- Another optimization: if the nominal subtype is unconstrained and
- -- the expression is a function call that returns an unconstrained
- -- type, rewrite the declaration as a renaming of the result of the
+ -- the expression is a function call that returns on the secondary
+ -- stack, rewrite the declaration as a renaming of the result of the
-- call. The exceptions below are cases where the copy is expected,
-- either by the back end (Aliased case) or by the semantics, as for
-- initializing controlled types or copying tags for class-wide types.
+ -- ??? To be moved to Expand_N_Object_Declaration.Rewrite_As_Renaming.
if Present (E)
and then Nkind (E) = N_Explicit_Dereference
and then Nkind (Original_Node (E)) = N_Function_Call
and then not Is_Library_Level_Entity (Id)
- and then not Is_Constrained (Underlying_Type (T))
and then not Is_Aliased (Id)
+ and then Needs_Secondary_Stack (T)
and then not Is_Class_Wide_Type (T)
- and then not Is_Controlled (T)
- and then not Has_Controlled_Component (Base_Type (T))
+ and then not Needs_Finalization (T)
and then Expander_Active
then
Rewrite (N,