From 2e188579aaa928bd60af6dc49434edf17c546ba1 Mon Sep 17 00:00:00 2001 From: Arnaud Charlet Date: Tue, 24 Nov 2020 17:53:28 +0100 Subject: [PATCH] [Ada] Crash on unnesting unnamed blocks gcc/ada/ * exp_ch7.adb (Reset_Scopes_To_Block_Elab_Proc): Do not crash on a block with no Identifier. Code cleanups. --- gcc/ada/exp_ch7.adb | 49 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index e06517c9213..64de40c6a04 100644 --- a/gcc/ada/exp_ch7.adb +++ b/gcc/ada/exp_ch7.adb @@ -4132,20 +4132,23 @@ package body Exp_Ch7 is procedure Reset_Scopes_To_Block_Elab_Proc (L : List_Id) is Id : Entity_Id; Stat : Node_Id; + Node : Node_Id; begin Stat := First (L); while Present (Stat) loop case Nkind (Stat) is when N_Block_Statement => - Id := Entity (Identifier (Stat)); + if Present (Identifier (Stat)) then + Id := Entity (Identifier (Stat)); - -- The Scope of this block needs to be reset to the new - -- procedure if the block contains nested subprograms. + -- The Scope of this block needs to be reset to the new + -- procedure if the block contains nested subprograms. - if Present (Id) and then Contains_Subprogram (Id) then - Set_Block_Elab_Proc; - Set_Scope (Id, Block_Elab_Proc); + if Present (Id) and then Contains_Subprogram (Id) then + Set_Block_Elab_Proc; + Set_Scope (Id, Block_Elab_Proc); + end if; end if; when N_Loop_Statement => @@ -4168,34 +4171,20 @@ package body Exp_Ch7 is when N_If_Statement => Reset_Scopes_To_Block_Elab_Proc (Then_Statements (Stat)); - Reset_Scopes_To_Block_Elab_Proc (Else_Statements (Stat)); - declare - Elif : Node_Id; - - begin - Elif := First (Elsif_Parts (Stat)); - while Present (Elif) loop - Reset_Scopes_To_Block_Elab_Proc - (Then_Statements (Elif)); - - Next (Elif); - end loop; - end; + Node := First (Elsif_Parts (Stat)); + while Present (Node) loop + Reset_Scopes_To_Block_Elab_Proc (Then_Statements (Node)); + Next (Node); + end loop; when N_Case_Statement => - declare - Alt : Node_Id; - - begin - Alt := First (Alternatives (Stat)); - while Present (Alt) loop - Reset_Scopes_To_Block_Elab_Proc (Statements (Alt)); - - Next (Alt); - end loop; - end; + Node := First (Alternatives (Stat)); + while Present (Node) loop + Reset_Scopes_To_Block_Elab_Proc (Statements (Node)); + Next (Node); + end loop; -- Reset the Scope of a subprogram occurring at the top level -- 2.30.2