From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Bob Duff <duff@adacore.com>
Subject: [COMMITTED] ada: Add missing ss_mark/ss_release in quantified expressions
Date: Tue, 13 Jun 2023 09:38:41 +0200 [thread overview]
Message-ID: <20230613073841.240638-1-poulhies@adacore.com> (raw)
From: Bob Duff <duff@adacore.com>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
gcc/ada/exp_ch4.adb | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index fdaeb50512f..7b6e997e3e7 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:
--
2.40.0
reply other threads:[~2023-06-13 7:38 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230613073841.240638-1-poulhies@adacore.com \
--to=poulhies@adacore.com \
--cc=duff@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).