From fb36f0187808d8486b9eb7442aacf13e7e2d3ed9 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Thu, 1 Jun 2023 15:43:41 +0200 Subject: ada: Fix too late finalization and secondary stack release in iterator loops Sem_Ch5 contains an entire machinery to deal with finalization actions and secondary stack releases around iterator loops, so this removes a recent fix that was made in a narrower case and instead refines the condition under which this machinery is triggered. As a side effect, given that finalization and secondary stack management are still entangled in this machinery, this also fixes the counterpart of a leak for the former, which is a finalization occurring too late. gcc/ada/ * exp_ch4.adb (Expand_N_Quantified_Expression): Revert the latest change as it is subsumed by the machinery in Sem_Ch5. * sem_ch5.adb (Prepare_Iterator_Loop): Also wrap the loop statement in a block in the name contains a function call that returns on the secondary stack. --- gcc/ada/exp_ch4.adb | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'gcc/ada/exp_ch4.adb') diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 7b6e997..fdaeb505 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -11116,32 +11116,6 @@ package body Exp_Ch4 is Freeze_Before (P, Etype (Var)); end; - -- For an expression of the form "for all/some X of F(...) => ...", - -- where F(...) is a function call that returns on the secondary stack, - -- we need to mark an enclosing scope as Uses_Sec_Stack. We must do - -- this before expansion, which can obscure the tree. Note that we - -- might be inside another quantified expression. Skip blocks and - -- loops that were generated by expansion. - - if Present (Iterator_Specification (N)) - and then Nkind (Name (Iterator_Specification (N))) = N_Function_Call - and then Needs_Secondary_Stack - (Etype (Name (Iterator_Specification (N)))) - then - declare - Source_Scope : Entity_Id := Current_Scope; - begin - while Ekind (Source_Scope) in E_Block | E_Loop - and then not Comes_From_Source (Source_Scope) - loop - Source_Scope := Scope (Source_Scope); - end loop; - - Set_Uses_Sec_Stack (Source_Scope); - Check_Restriction (No_Secondary_Stack, N); - end; - end if; - -- Create the declaration of the flag which tracks the status of the -- quantified expression. Generate: -- cgit v1.1