https://gcc.gnu.org/g:7fc31aa3530a80252e4a7859c375b305e6f6aaec

commit r17-4539-g7fc31aa3530a80252e4a7859c375b305e6f6aaec
Author: Eric Botcazou <[email protected]>
Date:   Mon Sep 21 23:34:34 2026 +0200

    Fix wrong debug info for bit-packed array type with reverse storage order
    
    In Ada, small bit-packed array types are represented by modular (unsigned)
    integer types under the hood and, in this case, the debug info generated for
    them is incorrect when they are declared with reverse scalar storage order.
    
    This is fixed by adding a 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 are made to it.
    
    gcc/
            * 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.
    
    gcc/ada/
            * gcc-interface/misc.cc (gnat_get_array_descr_info): Return the
            TYPE_REVERSE_STORAGE_ORDER flag of the underlying array type.

Diff:
---
 gcc/ada/gcc-interface/misc.cc | 8 ++++++--
 gcc/dwarf2out.cc              | 3 +--
 gcc/dwarf2out.h               | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index 505c48606a59..9c56afed5e57 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 d170e18c7409..4db0600a2ea7 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 35898874c0a6..c2834d50761e 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