[Ada] More default initialization for multi-dim array aggregates

Message ID 20220107162722.GA948763@adacore.com
State Committed
Commit d7b2fad2ec6652194aab0b9acfd41f187c4396d0
Headers
Series [Ada] More default initialization for multi-dim array aggregates |

Commit Message

Pierre-Marie de Rodat Jan. 7, 2022, 4:27 p.m. UTC
  Expansion of multi-dimensional array aggregates with boxes (e.g.
"(others => (others => <>))" only applied default initialization to
components of a scalar type with Default_Value aspect and of an access
type (which are initialized by default to null).

Now default initialization is applied to components of all types that
require default initialization (e.g. because of pragma
Normalize_Scalars), except for those with pragma
Suppress_Initialization.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* exp_aggr.adb (Gen_Assign): Remove explicit initialization for
	components of access types.
	(Get_Assoc_Expr): Enable initialization for components of all
	types that require simple initialization.
  

Patch

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1872,12 +1872,6 @@  package body Exp_Aggr is
                   Set_Etype (Indexed_Comp, Ctype);
                   Append_To (Stmts, Make_Invariant_Call (Indexed_Comp));
                end if;
-
-            elsif Is_Access_Type (Ctype) then
-               Append_To (Stmts,
-                 Make_Assignment_Statement (Loc,
-                   Name       => New_Copy_Tree (Indexed_Comp),
-                   Expression => Make_Null (Loc)));
             end if;
 
             if Needs_Finalization (Ctype) then
@@ -2212,15 +2206,10 @@  package body Exp_Aggr is
 
       begin
          if Box_Present (Assoc) then
-            if Is_Scalar_Type (Ctype) then
-               if Present (Default_Aspect_Component_Value (Typ)) then
-                  return Default_Aspect_Component_Value (Typ);
-               elsif Present (Default_Aspect_Value (Ctype)) then
-                  return Default_Aspect_Value (Ctype);
-               else
-                  return Empty;
-               end if;
-
+            if Present (Default_Aspect_Component_Value (Typ)) then
+               return Default_Aspect_Component_Value (Typ);
+            elsif Needs_Simple_Initialization (Ctype) then
+               return Get_Simple_Init_Val (Ctype, N);
             else
                return Empty;
             end if;