[COMMITTED] ada: Explicitly analyze and expand null array aggregates

Message ID 20230915142105.2101247-1-poulhies@adacore.com
State Accepted
Headers
Series [COMMITTED] ada: Explicitly analyze and expand null array aggregates |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Marc Poulhiès Sept. 15, 2023, 2:21 p.m. UTC
  From: Piotr Trojanek <trojanek@adacore.com>

Null array aggregates have present but empty lists of expressions and
component associations. This confuses the previous code for ordinary
array aggregates, which assumes that if a list of either expressions or
component associations is present, then it is non-empty.

This patch adds explicit handling for null array aggregates to avoid
assertion failures in code for ordinary array aggregates.

gcc/ada/

	* exp_aggr.adb (Build_Array_Aggr_Code): Don't build aggregate code
	for null array aggregates.
	* sem_aggr.adb (Resolve_Array_Aggregate): Don't examine formatting
	of a null array aggregate.

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

---
 gcc/ada/exp_aggr.adb | 5 ++++-
 gcc/ada/sem_aggr.adb | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index d72e27030e5..165f517c031 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -1989,7 +1989,10 @@  package body Exp_Aggr is
 
       --  Skip this if no component associations
 
-      if No (Expressions (N)) then
+      if Is_Null_Aggregate (N) then
+         null;
+
+      elsif No (Expressions (N)) then
 
          --  STEP 1 (a): Sort the discrete choices
 
diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb
index e929fea3bb6..597c3ce2dd1 100644
--- a/gcc/ada/sem_aggr.adb
+++ b/gcc/ada/sem_aggr.adb
@@ -2081,7 +2081,10 @@  package body Sem_Aggr is
 
       --  STEP 1: make sure the aggregate is correctly formatted
 
-      if Present (Component_Associations (N)) then
+      if Is_Null_Aggregate (N) then
+         null;
+
+      elsif Present (Component_Associations (N)) then
 
          --  Verify that all or none of the component associations
          --  include an iterator specification.