diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2023-04-08 18:29:16 +0200 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-29 10:23:22 +0200 |
commit | 61c54dd719630570161551bb52b6e5412fc5f85e (patch) | |
tree | d7d15a0b59ec6f0af085f2f8bd5cd0414223e01f /gcc/ada/sem_res.adb | |
parent | e256e67a8a3ce9adceca223a0974fc7dfdac1be5 (diff) | |
download | gcc-61c54dd719630570161551bb52b6e5412fc5f85e.zip gcc-61c54dd719630570161551bb52b6e5412fc5f85e.tar.gz gcc-61c54dd719630570161551bb52b6e5412fc5f85e.tar.bz2 |
ada: Fix memory leak in expression function returning Big_Integer
We fail to establish a transient scope around the return statement because
the function returns a controlled type, but this is no longer problematic
because controlled types are no longer returned on the secondary stack.
gcc/ada/
* exp_ch7.adb (Establish_Transient_Scope.Find_Transient_Context):
Bail out for a simple return statement only if the transient scope
and the function both require secondary stack management, or else
if the function is a thunk.
* sem_res.adb (Resolve_Call): Do not create a transient scope when
the call is the expression of a simple return statement.
Diffstat (limited to 'gcc/ada/sem_res.adb')
-rw-r--r-- | gcc/ada/sem_res.adb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 899b5b5..b16e489 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -6960,6 +6960,12 @@ package body Sem_Res is -- want to create a transient scope (this could occur in the case of a -- static string-returning call). + -- h) If the subprogram is an ignored ghost entity, because it does not + -- return anything. + + -- i) If the call is the expression of a simple return statement, since + -- it will be handled as a tail call by Expand_Simple_Function_Return. + if Is_Inlined (Nam) and then Has_Pragma_Inline (Nam) and then Nkind (Unit_Declaration_Node (Nam)) = N_Subprogram_Declaration @@ -6972,16 +6978,14 @@ package body Sem_Res is or else Is_Intrinsic_Subprogram (Nam) or else Is_Inlinable_Expression_Function (Nam) or else Is_Static_Function_Call (N) + or else Is_Ignored_Ghost_Entity (Nam) + or else Nkind (Parent (N)) = N_Simple_Return_Statement then null; - -- A return statement from an ignored Ghost function does not use the - -- secondary stack (or any other one). - elsif Expander_Active and then Ekind (Nam) in E_Function | E_Subprogram_Type and then Requires_Transient_Scope (Etype (Nam)) - and then not Is_Ignored_Ghost_Entity (Nam) then Establish_Transient_Scope (N, Needs_Secondary_Stack (Etype (Nam))); |