[COMMITTED] ada: Default_Component_Value trumps Initialize/Normalize_Scalars

Message ID 20230529082916.2409887-1-poulhies@adacore.com
State Committed
Commit 603c253d2698a586f5fa55acd25deb2bc8bd6e4f
Headers
Series [COMMITTED] ada: Default_Component_Value trumps Initialize/Normalize_Scalars |

Commit Message

Marc Poulhiès May 29, 2023, 8:29 a.m. UTC
  From: Steve Baird <baird@adacore.com>

If the Default_Component_Value aspect is specified for an array type, then
specifying Initialize_Scalars or Normalize_Scalars should have no effect
on the default initialization of an object of the array type.

gcc/ada/

	* exp_ch3.adb
	(Expand_N_Object_Declaration.Default_Initialize_Object): Add test for
	specified Default_Component_Value aspect when deciding whether
	either Initialize_Scalars or Normalize_Scalars impacts default
	initialization of an array object.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch3.adb | 6 ++++++
 1 file changed, 6 insertions(+)
  

Patch

diff --git a/gcc/ada/exp_ch3.adb b/gcc/ada/exp_ch3.adb
index e23a3fde15c..5f651bacafb 100644
--- a/gcc/ada/exp_ch3.adb
+++ b/gcc/ada/exp_ch3.adb
@@ -6897,6 +6897,12 @@  package body Exp_Ch3 is
 
                  and then not Has_Predicates (Component_Type (Typ))
 
+                 --  Array default component value takes precedence over
+                 --  Init_Or_Norm_Scalars.
+
+                 and then No (Find_Aspect (Typ,
+                                           Aspect_Default_Component_Value))
+
                  --  The component type must have a single initialization value
 
                  and then Simple_Initialization_OK (Component_Type (Typ))