This patch fixes a regression introduced by the recent work done for
tagged type constructors with task components.

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

gcc/ada/

        * exp_ch3.adb (Expand_N_Full_Type_Declaration): Ensure a _master
        declaration on limited types that might have tasks.
        * exp_ch9.adb (Build_Master_Renaming): For private types, if we
        are processing declarations in the private part, ensure that
        master is inserted before its full declaration; otherwise the
        master renaming may be inserted in the public part of the
        package (and hence before the declaration of its _master
        variable).
diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -5898,7 +5898,10 @@ package body Exp_Ch3 is
                Typ := Etype (Comp);
 
                if Ekind (Typ) = E_Anonymous_Access_Type
-                 and then Has_Task (Available_View (Designated_Type (Typ)))
+                 and then
+                   (Has_Task (Available_View (Designated_Type (Typ)))
+                      or else
+                    Might_Have_Tasks (Available_View (Designated_Type (Typ))))
                  and then No (Master_Id (Typ))
                then
                   --  Ensure that the record or array type have a _master


diff --git a/gcc/ada/exp_ch9.adb b/gcc/ada/exp_ch9.adb
--- a/gcc/ada/exp_ch9.adb
+++ b/gcc/ada/exp_ch9.adb
@@ -3576,8 +3576,40 @@ package body Exp_Ch9 is
 
       if Present (Ins_Nod) then
          Context := Ins_Nod;
+
       elsif Is_Itype (Ptr_Typ) then
          Context := Associated_Node_For_Itype (Ptr_Typ);
+
+         --  When the context references a discriminant or a component of a
+         --  private type and we are processing declarations in the private
+         --  part of the enclosing package, we must insert the master renaming
+         --  before the full declaration of the private type; otherwise the
+         --  master renaming would be inserted in the public part of the
+         --  package (and hence before the declaration of _master).
+
+         if In_Private_Part (Current_Scope) then
+            declare
+               Ctx : Node_Id := Context;
+
+            begin
+               if Nkind (Context) = N_Discriminant_Specification then
+                  Ctx := Parent (Ctx);
+               else
+                  while Nkind_In (Ctx, N_Component_Declaration,
+                                       N_Component_List)
+                  loop
+                     Ctx := Parent (Ctx);
+                  end loop;
+               end if;
+
+               if Nkind_In (Ctx, N_Private_Type_Declaration,
+                                 N_Private_Extension_Declaration)
+               then
+                  Context := Parent (Full_View (Defining_Identifier (Ctx)));
+               end if;
+            end;
+         end if;
+
       else
          Context := Parent (Ptr_Typ);
       end if;


Reply via email to