An access type whose designated type is an incomplete or class-wide type
may end up designating a task type or a type with a task component. It
is then necessary to associate the access type with the Master of the
tasks that may be generated on an allocator for that access type. This
is done by creating a renaming declaration that uses a local name to
rename the master of an enclosing construct (subprogram or task body)
that is the finalization master of these tasks, the local nanme used in
that renaming declaration must be unique across the compilation unit,
because several nested constructs that are not masters (for example,
package instantiastions) may contain local access types with the same
name.

Tested on x86_64-pc-linux-gnu, committed on trunk

2020-06-09  Ed Schonberg  <schonb...@adacore.com>

gcc/ada/

        * exp_ch9.adb (Build_Master_Renaming): Make name in renaming
        declaration unique by adding a numeric suffix, to prevent
        accidental name conflict when several instantiations of a
        package containing an access_to_incomplete type that designate
        tasks appear in the same scope.
--- gcc/ada/exp_ch9.adb
+++ gcc/ada/exp_ch9.adb
@@ -3469,10 +3469,13 @@ package body Exp_Ch9 is
 
       --  Generate:
       --    <Ptr_Typ>M : Master_Id renames _Master;
+      --  and add a numeric suffix to the name to ensure that it is
+      --  unique in case other access types in nested constructs
+      --  are homonyms of this one.
 
       Master_Id :=
         Make_Defining_Identifier (Loc,
-          New_External_Name (Chars (Ptr_Typ), 'M'));
+          New_External_Name (Chars (Ptr_Typ), 'M', -1));
 
       Master_Decl :=
         Make_Object_Renaming_Declaration (Loc,

Reply via email to