aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2023-05-03 08:42:24 -0400
committerMarc Poulhiès <poulhies@adacore.com>2023-06-13 09:31:46 +0200
commitd38366cbaedee32faba1664a8f529875f1128ae5 (patch)
tree9b5975f54763a38708d891fcec5728a1f4d2e4f4 /gcc
parent86b8d11e485832367446569dec6847bfcd8a62da (diff)
downloadgcc-d38366cbaedee32faba1664a8f529875f1128ae5.zip
gcc-d38366cbaedee32faba1664a8f529875f1128ae5.tar.gz
gcc-d38366cbaedee32faba1664a8f529875f1128ae5.tar.bz2
ada: Add missing ss_mark/ss_release in quantified expressions
If a quantified expression says "for all ... of F(...)" where F(...) is a function call that returns on the secondary stack, we need to clean up the secondary stack. This patch adds the required ss_mark/ss_release in that case. gcc/ada/ * exp_ch4.adb (Expand_N_Quantified_Expression): Detect the secondary-stack case, and find the innermost scope where we should mark/release, and Set_Uses_Sec_Stack on that. Skip intermediate blocks and loops that are part of expansion.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/exp_ch4.adb26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index fdaeb505..7b6e997 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -11116,6 +11116,32 @@ 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: