]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix crash on vector initialization
authorMarc Poulhiès <poulhies@adacore.com>
Mon, 27 Mar 2023 14:47:04 +0000 (16:47 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Sun, 5 Jan 2025 11:17:44 +0000 (12:17 +0100)
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/
PR ada/118234
* 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.

gcc/ada/exp_aggr.adb
gcc/ada/sem_util.adb
gcc/ada/sem_util.ads

index e360baa6683af4ba8a1233e59a2b0ef9c98a0856..a97882dba73a3b381c497f426e2fa0855d2038d6 100644 (file)
@@ -4930,9 +4930,12 @@ package body Exp_Aggr is
 
       if
          --  Internal aggregate (transformed when expanding the parent)
+         --  excluding the Container aggregate as these are transformed to
+         --  procedure call later.
 
-         Parent_Kind in
-           N_Aggregate | N_Extension_Aggregate | N_Component_Association
+         (Parent_Kind in
+            N_Component_Association | N_Aggregate | N_Extension_Aggregate
+            and then not Is_Container_Aggregate (Parent_Node))
 
          --  Allocator (see Convert_Aggr_In_Allocator)
 
index 3c55dda5a85666d52d2087e10b54470d6b5f6854..cbe19cbeeb2aa67bcda01d6d410ddc199a12f723 100644 (file)
@@ -130,9 +130,6 @@ package body Sem_Util is
    --  Determine whether arbitrary entity Id denotes an atomic object as per
    --  RM C.6(7).
 
-   function Is_Container_Aggregate (Exp : Node_Id) return Boolean;
-   --  Is the given expression a container aggregate?
-
    generic
       with function Is_Effectively_Volatile_Entity
         (Id : Entity_Id) return Boolean;
index 695158a34f35654e4c23247b6678513b7f178a90..28dcefd71fb75d8d9f3dc9e7009fe2c8fbdbd54d 100644 (file)
@@ -1531,6 +1531,9 @@ package Sem_Util is
    --  integer for use in compile-time checking. Note: Level is restricted to
    --  be non-dynamic.
 
+   function Is_Container_Aggregate (Exp : Node_Id) return Boolean;
+   --  Is the given expression a container aggregate?
+
    function Is_Newly_Constructed
      (Exp : Node_Id; Context_Requires_NC : Boolean) return Boolean;
    --  Indicates whether a given expression is "newly constructed" (RM 4.4).