aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorMarc Poulhiès <poulhies@adacore.com>2024-08-08 13:36:37 +0200
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-09-02 10:22:49 +0200
commitcb690aa1ce37f109986a5848c2b727be6a2aaacb (patch)
tree10e6514f8abf2bc6da1c34a819bed2d95df60dbd /gcc/ada
parent905ab329ccd06b0154eb42724eb5999165cd01fc (diff)
downloadgcc-cb690aa1ce37f109986a5848c2b727be6a2aaacb.zip
gcc-cb690aa1ce37f109986a5848c2b727be6a2aaacb.tar.gz
gcc-cb690aa1ce37f109986a5848c2b727be6a2aaacb.tar.bz2
ada: Also reset scope for some nested declaration
When changing the scope for entities found in the entry body that is mutated into a procedure, the compiler needs to look deeper than only the top level entities as expansion may produce object declarations which scopes are also the entry. For example, the tree after expansion may look like: procedure This_Is_An_Entry_Proc is ... O1 : Typ := do TMP1 : OTyp := ...; ... in TMP1; O1's scope needs to be reset to This_Is_An_Entry_Proc, but so does TMP1's scope. This change also fix a small oversight where N_Implicit_Label_Declaration scope must be reset and its content skipped. gcc/ada/ * exp_ch9.adb (Reset_Scopes_To): Adjust comment. (Reset_Scopes_To.Reset_Scope): Adjust the scope reset for object declaration. In particular, visit the children nodes if any. Also extend the handling of other declarations to N_Implicit_Label_Declaration.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/exp_ch9.adb25
1 files changed, 24 insertions, 1 deletions
diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
index 958657f..9b82a9f 100644
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -489,7 +489,8 @@ package body Exp_Ch9 is
-- <actualN> := P.<formalN>;
procedure Reset_Scopes_To (Bod : Node_Id; E : Entity_Id);
- -- Reset the scope of declarations and blocks at the top level of Bod to
+ -- Reset the scope of declarations and blocks at the top level of Bod and
+ -- of nested object declarations with scope pointing to the entry entity to
-- be E. Bod is either a block or a subprogram body. Used after expanding
-- various kinds of entry bodies into their corresponding constructs. This
-- is needed during unnesting to determine whether a body generated for an
@@ -14868,12 +14869,34 @@ package body Exp_Ch9 is
Set_Scope (Entity (Identifier (N)), E);
return Skip;
+ -- Reset scope for object declaration which scope is the task entry.
+ --
+ -- Also look inside the declaration (in particular in the expression
+ -- if present) because we may have expanded to something like:
+
+ -- O1 : Typ := do
+ -- TMP1 : OTyp := ...;
+ -- ...
+ -- in TMP1;
+
+ -- And the scope for TMP1 is Scope (O1). We need to look inside the
+ -- declaration to also reset such scope.
+
+ elsif Nkind (N) = N_Object_Declaration then
+ if Present (Scope (Defining_Entity (N)))
+ and then Ekind (Scope (Defining_Entity (N)))
+ in E_Entry | E_Entry_Family
+ then
+ Set_Scope (Defining_Entity (N), E);
+ end if;
+
-- Ditto for a package declaration or a full type declaration, etc.
elsif (Nkind (N) = N_Package_Declaration
and then N /= Specification (N))
or else Nkind (N) in N_Declaration
or else Nkind (N) in N_Renaming_Declaration
+ or else Nkind (N) in N_Implicit_Label_Declaration
then
Set_Scope (Defining_Entity (N), E);
return Skip;