[Ada] Make copies of entities being declared when copying block
authorRichard Kenner <kenner@adacore.com>
Wed, 21 Apr 2021 12:35:24 +0000 (08:35 -0400)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 29 Jun 2021 14:23:49 +0000 (14:23 +0000)
gcc/ada/

* sem_util.adb (Visit_Node): Add handling for N_Block_Statement
with declarations.

gcc/ada/sem_util.adb

index 0d50952..a543268 100644 (file)
@@ -24344,6 +24344,26 @@ package body Sem_Util is
             EWA_Inner_Scope_Level := EWA_Inner_Scope_Level + 1;
          end if;
 
+         --  If the node is a block, we need to process all declarations
+         --  in the block and make new entities for each.
+
+         if Nkind (N) = N_Block_Statement and then Present (Declarations (N))
+         then
+            declare
+               Decl : Node_Id := First (Declarations (N));
+
+            begin
+               while Present (Decl) loop
+                  if Nkind (Decl) = N_Object_Declaration then
+                     Add_New_Entity (Defining_Identifier (Decl),
+                                     New_Copy (Defining_Identifier (Decl)));
+                  end if;
+
+                  Next (Decl);
+               end loop;
+            end;
+         end if;
+
          declare
             procedure Action (U : Union_Id);
             procedure Action (U : Union_Id) is