From 135c02769b9ec625a55a0beba63415c1484f8951 Mon Sep 17 00:00:00 2001 From: Javier Miranda Date: Sat, 13 Jun 2020 08:21:19 -0400 Subject: [PATCH] [Ada] Misplace of internal master renaming declaration 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). --- gcc/ada/exp_ch3.adb | 5 ++++- gcc/ada/exp_ch9.adb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb index d90bbadd7c7..ba4f3da23bc 100644 --- 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 index 001aa4b77d4..26de2c32b27 100644 --- 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; -- 2.30.2