ada: Fix crash on vector initialization

Initializing a vector using

 Vec : V.Vector := [Some_Type'(Some_Abstract_Type with F => 0)];

may crash the compiler. The expander marks the N_Extension_Aggregate for
delayed expansion which never happens and incorrectly ends up in gigi.

The delayed expansion is needed for nested aggregates, which the
original code is testing for, but container aggregates are handled
differently.

Such assignments to container aggregates are later transformed into
procedure calls to the procedures named in the Aggregate aspect
definition, for which the delayed expansion is not required/expected.

gcc/ada/

	* exp_aggr.adb (Convert_To_Assignments): Do not mark node for
	delayed expansion if parent type has the Aggregate aspect.
	* sem_util.adb (Is_Container_Aggregate): Move...
	* sem_util.ads (Is_Container_Aggregate): ... here and make it
	public.
This commit is contained in:
Marc Poulhiès 2023-03-27 16:47:04 +02:00 committed by Eric Botcazou
parent 4a158c09e5
commit 0fb227b912
3 changed files with 8 additions and 5 deletions

View File

@ -5017,9 +5017,12 @@ package body Exp_Aggr is
if if
-- Internal aggregate (transformed when expanding the parent) -- Internal aggregate (transformed when expanding the parent)
-- excluding the Container aggregate as these are transformed to
-- procedure call later.
Parent_Kind in (Parent_Kind in
N_Aggregate | N_Extension_Aggregate | N_Component_Association N_Component_Association | N_Aggregate | N_Extension_Aggregate
and then not Is_Container_Aggregate (Parent_Node))
-- Allocator (see Convert_Aggr_In_Allocator) -- Allocator (see Convert_Aggr_In_Allocator)

View File

@ -132,9 +132,6 @@ package body Sem_Util is
-- Determine whether arbitrary entity Id denotes an atomic object as per -- Determine whether arbitrary entity Id denotes an atomic object as per
-- RM C.6(7). -- RM C.6(7).
function Is_Container_Aggregate (Exp : Node_Id) return Boolean;
-- Is the given expression a container aggregate?
generic generic
with function Is_Effectively_Volatile_Entity with function Is_Effectively_Volatile_Entity
(Id : Entity_Id) return Boolean; (Id : Entity_Id) return Boolean;

View File

@ -1474,6 +1474,9 @@ package Sem_Util is
-- Return True if the loop has no side effect and can therefore be -- Return True if the loop has no side effect and can therefore be
-- marked for removal. Return False if N is not a N_Loop_Statement. -- marked for removal. Return False if N is not a N_Loop_Statement.
function Is_Container_Aggregate (Exp : Node_Id) return Boolean;
-- Is the given expression a container aggregate?
function Is_Newly_Constructed function Is_Newly_Constructed
(Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean; (Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean;
-- Indicates whether a given expression is "newly constructed" (RM 4.4). -- Indicates whether a given expression is "newly constructed" (RM 4.4).