[Ada] Fix scope of block in expanded protected entry body
authorPiotr Trojanek <trojanek@adacore.com>
Fri, 4 Feb 2022 19:56:51 +0000 (20:56 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Thu, 12 May 2022 12:38:35 +0000 (12:38 +0000)
We expand protected entry body into procedure with a nested block. The
scope of this block is naturally the enclosing procedure. However, the
scope field was wrongly set to the entity of the enclosing procedure
body (i.e. E_Subprogram_Body); now it is set to the entity of the
enclosing procedure spec (i.e. E_Procedure).

In general, the scope field should always points to spec, even for
entities that are syntactically nested within a program unit body. The
scope set to E_Subprogram_Body entity was only accepted because in gigi
we had a protection for that, but this protection is now removed.

This patch fixes a regression in a ravenscar testsuite test (c_rf02_06),
where GNAT was crashing when compiling in configurable runtime mode with
restriction No_Exception_Propagation.

gcc/ada/

* exp_ch9.adb (Build_Protected_Entry): Set scope of the nested
block to spec and not the body of the procedure created for a
protected entry.

gcc/ada/exp_ch9.adb

index 04a87fb..f706780 100644 (file)
@@ -3707,7 +3707,8 @@ package body Exp_Ch9 is
 
       Analyze_Statements (Bod_Stmts);
 
-      Set_Scope (Entity (Identifier (First (Bod_Stmts))), Bod_Id);
+      Set_Scope (Entity (Identifier (First (Bod_Stmts))),
+                 Protected_Body_Subprogram (Ent));
 
       Reset_Scopes_To
         (First (Bod_Stmts), Entity (Identifier (First (Bod_Stmts))));