[COMMITTED,19/31] ada: Fix crash on aliased constant with packed array type and -g switch

Message ID 20240521073035.314024-19-poulhies@adacore.com
State Committed
Commit 0967e06caaa606eec7b2f222bb9926ec6523ea02
Series [COMMITTED,01/31] ada: Add new Mingw task priority mapping |

Commit Message

Marc Poulhiès May 21, 2024, 7:30 a.m. UTC
  From: Eric Botcazou <ebotcazou@adacore.com>

The problem is that we build a template whose array field is not an array
in the case of an aliased object with nominal unconstrained array subtype.


	* gcc-interface/decl.cc (gnat_to_gnu_entity) <E_Variable>: For an
	array allocated with its bounds, make sure to have an array type
	to build the template.

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

 gcc/ada/gcc-interface/decl.cc | 3 +++
 1 file changed, 3 insertions(+)


diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc
index ca174bff009..41d5c29a17c 100644
--- a/gcc/ada/gcc-interface/decl.cc
+++ b/gcc/ada/gcc-interface/decl.cc
@@ -939,6 +939,9 @@  gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
 	    && !type_annotate_only)
 	    tree gnu_array = gnat_to_gnu_type (Base_Type (gnat_type));
+	    /* Make sure to have an array type for the template.  */
+	    if (TYPE_IS_PADDING_P (gnu_type))
+	      gnu_type = TREE_TYPE (TYPE_FIELDS (gnu_type));
 	      = build_unc_object_type_from_ptr (TREE_TYPE (gnu_array),