From cb690aa1ce37f109986a5848c2b727be6a2aaacb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Thu, 8 Aug 2024 13:36:37 +0200 Subject: 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. --- gcc/ada/exp_ch9.adb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'gcc/ada') 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 -- := P.; 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; -- cgit v1.1