[COMMITTED,05/30] ada: Fix test for wrapping loop parameter spec

Message ID 20240801151738.400796-5-poulhies@adacore.com
State Committed
Commit 45174a8adf000406a42d877c132afcbaad83f3b4
Headers
Series [COMMITTED,01/30] ada: Remove obsolete workaround |

Commit Message

Marc Poulhiès Aug. 1, 2024, 3:17 p.m. UTC
  From: Ronan Desplanques <desplanques@adacore.com>

This patches fixes a problem where cleanup statements would be
missing for some cases of loop parameter specifications that allocate
on the secondary stack.

gcc/ada/

	* sem_ch5.adb (Prepare_Param_Spec_Loop): Fix criterion for
	wrapping loop statements into blocks.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/sem_ch5.adb | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb
index 5739fe06ea2..ac8cd0821ff 100644
--- a/gcc/ada/sem_ch5.adb
+++ b/gcc/ada/sem_ch5.adb
@@ -3806,20 +3806,16 @@  package body Sem_Ch5 is
                Rng_Typ := Etype (Rng_Copy);
 
                --  Wrap the loop statement within a block in order to manage
-               --  the secondary stack when the discrete range is
+               --  the secondary stack when the discrete range:
                --
-               --    * Either a Forward_Iterator or a Reverse_Iterator
+               --    * is either a Forward_Iterator or a Reverse_Iterator
+               --  or
                --
-               --    * Function call whose return type requires finalization
-               --      actions.
-
-               --  ??? it is unclear why using Has_Sec_Stack_Call directly on
-               --  the discrete range causes the freeze node of an itype to be
-               --  in the wrong scope in complex assertion expressions.
+               --    * contains a function call that returns on the secondary
+               --      stack.
 
                if Is_Iterator (Rng_Typ)
-                 or else (Nkind (Rng_Copy) = N_Function_Call
-                           and then Needs_Finalization (Rng_Typ))
+                 or else Has_Sec_Stack_Call (Rng_Copy)
                then
                   Wrap_Loop_Statement (Manage_Sec_Stack => True);
                   Stop_Processing := True;