From: Marc Poulhiès Date: Thu, 22 Sep 2022 08:59:42 +0000 (+0200) Subject: ada: Fix loop unnesting issue. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12cfb2949754facc3624d70f6267a10b8b57df88;p=platform%2Fupstream%2Fgcc.git 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 --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index 6c87deb..3566702 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 28396a4..9a7640b 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 c23d358..88bfbfc 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