From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id D7A68385AC22; Mon, 9 May 2022 09:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D7A68385AC22 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-186] [Ada] Fix visibility inside declare_expression X-Act-Checkin: gcc X-Git-Author: Ed Schonberg X-Git-Refname: refs/heads/master X-Git-Oldrev: f1231d9a0baab25e0a07b0d6146b91e59ecfadb8 X-Git-Newrev: 5081e9205a6f12c41bdd5a7d630a732120fb4e92 Message-Id: <20220509093114.D7A68385AC22@sourceware.org> Date: Mon, 9 May 2022 09:31:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 09:31:14 -0000 https://gcc.gnu.org/g:5081e9205a6f12c41bdd5a7d630a732120fb4e92 commit r13-186-g5081e9205a6f12c41bdd5a7d630a732120fb4e92 Author: Ed Schonberg Date: Mon Jan 3 15:29:09 2022 +0100 [Ada] Fix visibility inside declare_expression The first implementation just created a scope for the analysis of the declarations and the expression, so that visibility would just work as it does for all other constructs. However this led to an annoying bug when one of the declarations or the expression itself creates a transient scope: there may be a confusion on scope exit between those two scopes. As a result visibility is handled by explicit traversal of the expression and replacement of occurrences of the local variables, see Replace_Local_Ref in Resolve_Declare_Expression (sem_res.adb). The current code does not take into account that there may be references to a local object in a subsequent declaration (not just in the expression). gcc/ada/ * sem_res.adb (Resolve_Declare_Expression): Traverse the expression to replace references to local variables that occur within declarations of the declare_expression; fix typos in comments. Diff: --- gcc/ada/sem_res.adb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index b918615904e..f5c8b10456e 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -7595,7 +7595,7 @@ package body Sem_Res is Local : Entity_Id := Empty; function Replace_Local (N : Node_Id) return Traverse_Result; - -- Use a tree traversal to replace each ocurrence of the name of + -- Use a tree traversal to replace each occurrence of the name of -- a local object declared in the construct, with the corresponding -- entity. This replaces the usual way to perform name capture by -- visibility, because it is not possible to place on the scope @@ -7632,7 +7632,7 @@ package body Sem_Res is procedure Replace_Local_Ref is new Traverse_Proc (Replace_Local); - -- Start of processing for Resolve_Declare_Expression + -- Start of processing for Resolve_Declare_Expression begin @@ -7645,6 +7645,19 @@ package body Sem_Res is then Local := Defining_Identifier (Decl); Replace_Local_Ref (Expr); + + -- Traverse the expression to replace references to local + -- variables that occur within declarations of the + -- declare_expression. + + declare + D : Node_Id := Next (Decl); + begin + while Present (D) loop + Replace_Local_Ref (D); + Next (D); + end loop; + end; end if; Next (Decl);