From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 4BBEA38576B0; Fri, 4 Nov 2022 13:54:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BBEA38576B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667570083; bh=n+Q810MVzXJIoMJgOPrM7YQjC9bx4DEOYiXY62Iabnk=; h=From:To:Subject:Date:From; b=yPkEGu0+7CQeZ9ig301Fxc0l98wxFJVoN9PKHdl24VJvQLFPdcm9q/6AR/mMB547F sM9muLS2spBJxLzgVzSOvKOsgCC9AUdss6yOZ6Caf9eamnGXlGuYX+gepYlzqAO35a /fBtPvRJBl+alqC+S2pS1lGWmZHLLkJwCw62Y4b8= MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3671] ada: Fix loop unnesting issue. X-Act-Checkin: gcc X-Git-Author: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Git-Refname: refs/heads/master X-Git-Oldrev: 73d04a073b7288fcf6fc2e1f25d8b1f3a2c6fb81 X-Git-Newrev: 12cfb2949754facc3624d70f6267a10b8b57df88 Message-Id: <20221104135443.4BBEA38576B0@sourceware.org> Date: Fri, 4 Nov 2022 13:54:43 +0000 (GMT) List-Id: https://gcc.gnu.org/g:12cfb2949754facc3624d70f6267a10b8b57df88 commit r13-3671-g12cfb2949754facc3624d70f6267a10b8b57df88 Author: Marc Poulhiès Date: Thu Sep 22 10:59:42 2022 +0200 ada: Fix loop unnesting issue. During loop unnesting, when the loop statements are wrapped in a code block, the newly created block's scope must be set to the loop scope (instead of the previous 'Current_Scope' that would point to an upper scope). gcc/ada/ * sem_util.ads (Add_Block_Identifier): Add new extra Scope argument. * sem_util.adb (Add_Block_Identifier): Likewise and use this scope variable instead of Current_Scope. * exp_util.adb (Wrap_Statements_In_Block): Add new scope argument to Add_Block_Identifier call. Diff: --- gcc/ada/exp_util.adb | 2 +- gcc/ada/sem_util.adb | 8 ++++++-- gcc/ada/sem_util.ads | 14 +++++++++----- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 6c87debe456..35667028df1 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -11367,7 +11367,7 @@ package body Exp_Util is -- Create a label for the block in case the block needs to manage the -- secondary stack. A label allows for flag Uses_Sec_Stack to be set. - Add_Block_Identifier (Block_Nod, Block_Id); + Add_Block_Identifier (Block_Nod, Block_Id, Scop); -- When wrapping the statements of an iterator loop, check whether -- the loop requires secondary stack management and if so, propagate diff --git a/gcc/ada/sem_util.adb b/gcc/ada/sem_util.adb index 28396a4c34b..9a7640b3147 100644 --- a/gcc/ada/sem_util.adb +++ b/gcc/ada/sem_util.adb @@ -1044,7 +1044,11 @@ package body Sem_Util is -- Add_Block_Identifier -- -------------------------- - procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is + procedure Add_Block_Identifier + (N : Node_Id; + Id : out Entity_Id; + Scope : Entity_Id := Current_Scope) + is Loc : constant Source_Ptr := Sloc (N); begin pragma Assert (Nkind (N) = N_Block_Statement); @@ -1057,7 +1061,7 @@ package body Sem_Util is -- Create a new block label and set its attributes else - Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B'); + Id := New_Internal_Entity (E_Block, Scope, Loc, 'B'); Set_Etype (Id, Standard_Void_Type); Set_Parent (Id, N); diff --git a/gcc/ada/sem_util.ads b/gcc/ada/sem_util.ads index c23d358e2fb..88bfbfc2086 100644 --- a/gcc/ada/sem_util.ads +++ b/gcc/ada/sem_util.ads @@ -88,11 +88,6 @@ package Sem_Util is -- Add A to the list of access types to process when expanding the -- freeze node of E. - procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id); - -- Given a block statement N, generate an internal E_Block label and make - -- it the identifier of the block. Id denotes the generated entity. If the - -- block already has an identifier, Id returns the entity of its label. - procedure Add_Global_Declaration (N : Node_Id); -- These procedures adds a declaration N at the library level, to be -- elaborated before any other code in the unit. It is used for example @@ -678,6 +673,15 @@ package Sem_Util is function Current_Scope return Entity_Id; -- Get entity representing current scope + procedure Add_Block_Identifier + (N : Node_Id; + Id : out Entity_Id; + Scope : Entity_Id := Current_Scope); + -- Given a block statement N, generate an internal E_Block label and make + -- it the identifier of the block. Scope denotes the scope in which the + -- generated entity Id is created and defaults to the current scope. If the + -- block already has an identifier, Id returns the entity of its label. + function Current_Scope_No_Loops return Entity_Id; -- Return the current scope ignoring internally generated loops