ada: Fix minor fallout of previous changes to aggregate expansion

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.
This commit is contained in:
Eric Botcazou 2024-11-07 18:50:49 +01:00 committed by Marc Poulhiès
parent 6a7849592d
commit 3716d9887c
2 changed files with 10 additions and 20 deletions

View file

@ -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;

View file

@ -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;