[COMMITTED,10/31] ada: Crash on null aggregate of multidimensional type

Message ID 20250911091904.1505690-10-poulhies@adacore.com
State Committed
Commit f2ba38d3babe484b65726cea9f750a57f4951228
Headers
Series [COMMITTED,01/31] ada: Disable new warning for composite equality ops that can raise Program_Error |

Commit Message

Marc Poulhiès Sept. 11, 2025, 9:18 a.m. UTC
  From: Javier Miranda <miranda@adacore.com>

A compiler built with assertions enabled crashes processing
a null aggregate of multidimensional type.

gcc/ada/ChangeLog:

	* sem_aggr.adb (Report_Null_Array_Constraint_Error): Adjust code
	for reporting the error on enumeration types.
	(Resolve_Null_Array_Aggregate): On multidimiensional arrays, avoid
	reporting the same error several times. Flag the node as raising
	constraint error when the bounds are known and some of them is
	known to raise constraint error.

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

---
 gcc/ada/sem_aggr.adb | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
  

Patch

diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index bbd0eaefb98e..baca06800abe 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -1139,7 +1139,8 @@  package body Sem_Aggr is
       if Is_Modular_Integer_Type (Index_Typ) then
          Error_Msg_N
            ("null array aggregate indexed by a modular type<<", N);
-      else
+
+      elsif Is_Enumeration_Type (Index_Typ) then
          Error_Msg_N
            ("null array aggregate indexed by an enumeration type<<", N);
       end if;
@@ -5463,8 +5464,13 @@  package body Sem_Aggr is
 
             Hi := New_Copy_Tree (Lo);
 
-            Report_Null_Array_Constraint_Error (N, Index_Typ);
-            Set_Raises_Constraint_Error (N);
+            --  On multidimiensional arrays, avoid reporting the same error
+            --  several times.
+
+            if not Raises_Constraint_Error (N) then
+               Report_Null_Array_Constraint_Error (N, Index_Typ);
+               Set_Raises_Constraint_Error (N);
+            end if;
 
          else
             --  The upper bound is the predecessor of the lower bound
@@ -5478,6 +5484,15 @@  package body Sem_Aggr is
          Append (Make_Range (Loc, New_Copy_Tree (Lo), Hi), Constr);
          Analyze_And_Resolve (Last (Constr), Etype (Index));
 
+         if Known_Bounds
+           and then
+             (Nkind (High_Bound (Last (Constr))) = N_Raise_Constraint_Error
+                or else
+              Nkind (Low_Bound (Last (Constr))) = N_Raise_Constraint_Error)
+         then
+            Set_Raises_Constraint_Error (N);
+         end if;
+
          Next_Index (Index);
       end loop;