From: Arnaud Charlet Date: Tue, 24 Nov 2020 16:53:28 +0000 (+0100) Subject: [Ada] Crash on unnesting unnamed blocks X-Git-Tag: upstream/12.2.0~10895 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2e188579aaa928bd60af6dc49434edf17c546ba1;p=platform%2Fupstream%2Fgcc.git [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. --- diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb index e06517c..64de40c 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