Hi,

In Ada, small bit-packed array types are represented by modular (aka unsigned) 
integer types under the hood and, in this case, the debug info generated for 
them is incorrect if they are declared with the reverse scalar storage order.

This is fixed by adding a reverse_storage_order field to the array_descr_info 
structure that is filled by the LANG_HOOKS_GET_ARRAY_DESCR_INFO language hook 
and setting it properly in the front-end.  The only other front-end declaring 
this hook is the Fortran front-end and 1) AFAIK the language does not support 
toggling the scalar storage order and 2) the language hook first clears the 
entire structure before returning true, so no changes is made to it.

Tested on x86-64/Linux, OK for the mainline?


2026-09-21  Eric Botcazou  <[email protected]>

        * dwarf2out.h (struct array_descr_info): Add reverse_storage_order.
        * dwarf2out.cc (gen_descr_array_type_die): Pass it in the call to
        add_type_attribute instead of using TYPE_REVERSE_STORAGE_ORDER.
ada/
        * gcc-interface/misc.cc (gnat_get_array_descr_info): Return the
        TYPE_REVERSE_STORAGE_ORDER flag of the underlying array type.

-- 
Eric Botcazou
diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index 505c48606a5..9c56afed5e5 100644
--- a/gcc/ada/gcc-interface/misc.cc
+++ b/gcc/ada/gcc-interface/misc.cc
@@ -788,7 +788,7 @@ gnat_get_array_descr_info (const_tree const_type,
 {
   tree type = const_cast<tree> (const_type);
   tree first_dimen, dimen;
-  bool is_array;
+  bool is_array, reverse_storage_order;
   int i;
 
   /* Temporaries created in the first pass and used in the second one for thin
@@ -877,15 +877,19 @@ gnat_get_array_descr_info (const_tree const_type,
 		    : array_descr_ordering_row_major);
   info->rank = NULL_TREE;
 
-  /* Count the number of dimensions and determine the element type.  */
+  /* Count the number of dimensions, determine the element type and whether
+     it is stored in reverse storage order.  */
   i = 1;
+  reverse_storage_order = TYPE_REVERSE_STORAGE_ORDER (first_dimen);
   dimen = TREE_TYPE (first_dimen);
   while (TREE_CODE (dimen) == ARRAY_TYPE && TYPE_MULTI_ARRAY_P (dimen))
     {
       i++;
+      reverse_storage_order = TYPE_REVERSE_STORAGE_ORDER (dimen);
       dimen = TREE_TYPE (dimen);
     }
   info->ndimensions = i;
+  info->reverse_storage_order = reverse_storage_order;
   info->element_type = dimen;
 
   /* Too many dimensions?  Give up generating proper description: yield instead
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index d170e18c740..4db0600a2ea 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -23179,8 +23179,7 @@ gen_descr_array_type_die (tree type, struct array_descr_info *info,
 
   gen_type_die (info->element_type, context_die);
   add_type_attribute (array_die, info->element_type, TYPE_UNQUALIFIED,
-		      TREE_CODE (type) == ARRAY_TYPE
-		      && TYPE_REVERSE_STORAGE_ORDER (type),
+		      info->reverse_storage_order,
 		      context_die);
 
   if (get_AT (array_die, DW_AT_name))
diff --git a/gcc/dwarf2out.h b/gcc/dwarf2out.h
index 35898874c0a..c2834d50761 100644
--- a/gcc/dwarf2out.h
+++ b/gcc/dwarf2out.h
@@ -461,6 +461,7 @@ struct array_descr_info
   tree associated;
   tree stride;
   tree rank;
+  bool reverse_storage_order;
   bool stride_in_bits;
   struct array_descr_dimen
     {

Reply via email to