public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-6211] [Ada] Crash on if expression inside declare expression
@ 2020-12-17 10:51 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-12-17 10:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b7e68e7de0fb6dfc9099a333f800dc904eb3c9e7
commit r11-6211-gb7e68e7de0fb6dfc9099a333f800dc904eb3c9e7
Author: Arnaud Charlet <charlet@adacore.com>
Date: Tue Dec 1 09:44:33 2020 -0500
[Ada] Crash on if expression inside declare expression
gcc/ada/
* sem_res.adb (Resolve_Declare_Expression): Need to establish a
transient scope in case Expression (N) requires actions to be
wrapped. Code cleanup.
* exp_ch7.adb, exp_ch11.adb: Code cleanup.
Diff:
---
gcc/ada/exp_ch11.adb | 4 ++--
gcc/ada/exp_ch7.adb | 2 +-
gcc/ada/sem_res.adb | 37 +++++++++++++++++++++++++++++--------
3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb
index 3ab2ea25eab..a501bf1aa26 100644
--- a/gcc/ada/exp_ch11.adb
+++ b/gcc/ada/exp_ch11.adb
@@ -1864,8 +1864,8 @@ package body Exp_Ch11 is
then
return Empty;
- -- Test for handled sequence of statements with at least one
- -- exception handler which might be the one we are looking for.
+ -- Test for handled sequence of statements with at least one
+ -- exception handler which might be the one we are looking for.
elsif Nkind (P) = N_Handled_Sequence_Of_Statements
and then Present (Exception_Handlers (P))
diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index 615cc4137c0..42cfb39bf7a 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -6532,7 +6532,7 @@ package body Exp_Ch7 is
begin
-- Nothing to do if the scope does not manage the secondary stack or
- -- does not contain meaninful actions for insertion.
+ -- does not contain meaningful actions for insertion.
if not Manage_SS
and then No (Act_Before)
diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb
index 4077ae1b256..f6e0eab84b7 100644
--- a/gcc/ada/sem_res.adb
+++ b/gcc/ada/sem_res.adb
@@ -2298,11 +2298,8 @@ package body Sem_Res is
-- Declare_Expression and requires scope management.
if Nkind (N) = N_Expression_With_Actions then
- if Comes_From_Source (N)
- and then N = Original_Node (N)
- then
+ if Comes_From_Source (N) and then N = Original_Node (N) then
Resolve_Declare_Expression (N, Typ);
-
else
Resolve (Expression (N), Typ);
end if;
@@ -7470,7 +7467,8 @@ package body Sem_Res is
(N : Node_Id;
Typ : Entity_Id)
is
- Decl : Node_Id;
+ Decl : Node_Id;
+ Need_Transient_Scope : Boolean := False;
begin
-- Install the scope created for local declarations, if
-- any. The syntax allows a Declare_Expression with no
@@ -7479,7 +7477,6 @@ package body Sem_Res is
-- appears as the scope of all entities declared therein.
Decl := First (Actions (N));
-
while Present (Decl) loop
exit when Nkind (Decl)
in N_Object_Declaration | N_Object_Renaming_Declaration;
@@ -7487,11 +7484,35 @@ package body Sem_Res is
end loop;
if Present (Decl) then
- Push_Scope (Scope (Defining_Identifier (Decl)));
+
+ -- Need to establish a transient scope in case Expression (N)
+ -- requires actions to be wrapped.
declare
- E : Entity_Id := First_Entity (Current_Scope);
+ Node : Node_Id;
+ begin
+ Node := First (Actions (N));
+ while Present (Node) loop
+ if Nkind (Node) = N_Object_Declaration
+ and then Requires_Transient_Scope
+ (Etype (Defining_Identifier (Node)))
+ then
+ Need_Transient_Scope := True;
+ exit;
+ end if;
+ Next (Node);
+ end loop;
+ end;
+
+ if Need_Transient_Scope then
+ Establish_Transient_Scope (Decl, True);
+ else
+ Push_Scope (Scope (Defining_Identifier (Decl)));
+ end if;
+
+ declare
+ E : Entity_Id := First_Entity (Current_Scope);
begin
while Present (E) loop
Set_Current_Entity (E);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-17 10:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 10:51 [gcc r11-6211] [Ada] Crash on if expression inside declare expression Pierre-Marie de Rodat
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).