From: Eric Botcazou <ebotca...@adacore.com> The problem occurs for an anonymous array object declared with an aspect and when pragma {Initialize,Normalize}_Scalars is in effect: in this case, the synthesized aggregate is attached to the Initialization_Statements field by Convert_Aggr_In_Object_Decl, but Explode_Initialization_Compound_Statement puts it back at the point of declaration instead of the freeze point, thus voiding the effects of the mechanism.
This was previously hidden because of a bypass in Freeze_Entity which drops the freeze node on the floor in this case, so the change fixes the issue and removes the bypass in the process. gcc/ada/ChangeLog: * freeze.ads (Explode_Initialization_Compound_Statement): Adjust the description. * freeze.adb (Explode_Initialization_Compound_Statement): If the entity has its freezing delayed, append the initialization actions to its freeze actions. (Freeze_Object_Declaration): Remove commented out code. (Freeze_Entity): Remove bypass for object of anonymous array type. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/freeze.adb | 28 +++++++++------------------- gcc/ada/freeze.ads | 2 +- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index 7502a04d517..3b781f7d21c 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -2461,7 +2461,15 @@ package body Freeze is if Present (Init_Stmts) and then Nkind (Init_Stmts) = N_Compound_Statement then - Insert_List_Before (Init_Stmts, Actions (Init_Stmts)); + -- If the entity has its freezing delayed, append the initialization + -- actions to its freeze actions. Otherwise insert them back at the + -- point where they have been generated. + + if Has_Delayed_Freeze (E) then + Append_Freeze_Actions (E, Actions (Init_Stmts)); + else + Insert_List_Before (Init_Stmts, Actions (Init_Stmts)); + end if; -- Note that we rewrite Init_Stmts into a NULL statement, rather than -- just removing it, because Freeze_All may rely on this particular @@ -4519,7 +4527,6 @@ package body Freeze is Expression => Expression (Decl))); Set_No_Initialization (Decl); - -- Set_Is_Frozen (E, False); end; end if; @@ -6799,23 +6806,6 @@ package body Freeze is and then Within_Scope (Etype (E), Current_Scope) then Freeze_And_Append (Etype (E), N, Result); - - -- For an object of an anonymous array type, aspects on the - -- object declaration apply to the type itself. This is the - -- case for Atomic_Components, Volatile_Components, and - -- Independent_Components. In these cases analysis of the - -- generated pragma will mark the anonymous types accordingly, - -- and the object itself does not require a freeze node. - - if Ekind (E) = E_Variable - and then Is_Itype (Etype (E)) - and then Is_Array_Type (Etype (E)) - and then Has_Delayed_Aspects (E) - then - Set_Has_Delayed_Aspects (E, False); - Set_Has_Delayed_Freeze (E, False); - Set_Freeze_Node (E, Empty); - end if; end if; -- Special processing for objects created by object declaration; diff --git a/gcc/ada/freeze.ads b/gcc/ada/freeze.ads index 4bc03c4ef59..67f0a55fbdd 100644 --- a/gcc/ada/freeze.ads +++ b/gcc/ada/freeze.ads @@ -181,7 +181,7 @@ package Freeze is procedure Explode_Initialization_Compound_Statement (E : Entity_Id); -- If Initialization_Statements (E) is an N_Compound_Statement, insert its - -- actions in the enclosing list and reset the attribute. + -- actions at the appropriate point and clear the attribute. function Freeze_Entity (E : Entity_Id; -- 2.43.0