aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@adacore.com>2020-11-24 17:53:28 +0100
committerPierre-Marie de Rodat <derodat@adacore.com>2020-12-15 06:41:54 -0500
commit2e188579aaa928bd60af6dc49434edf17c546ba1 (patch)
treec699517e9f453253c6fa4b9a6829ce8af94989e0
parentb2304663888042a75a07851833519842a953cecb (diff)
downloadgcc-2e188579aaa928bd60af6dc49434edf17c546ba1.zip
gcc-2e188579aaa928bd60af6dc49434edf17c546ba1.tar.gz
gcc-2e188579aaa928bd60af6dc49434edf17c546ba1.tar.bz2
[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.
-rw-r--r--gcc/ada/exp_ch7.adb49
1 files changed, 19 insertions, 30 deletions
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