https://gcc.gnu.org/g:19c22fbea31ae421d5b09a9d0b4f91438310ac45

commit r15-3117-g19c22fbea31ae421d5b09a9d0b4f91438310ac45
Author: Eric Botcazou <ebotca...@adacore.com>
Date:   Mon Aug 5 13:06:17 2024 +0200

    ada: Fix crash on aliased variable with packed array type and -g switch
    
    This comes from a loophole in gnat_get_array_descr_info for record types
    containing a template, which represent an aliased array, when this array
    type is bit-packed and implemented as a modular integer.
    
    gcc/ada/
    
            * gcc-interface/misc.cc (gnat_get_array_descr_info): Test the
            BIT_PACKED_ARRAY_TYPE_P flag only once on the final debug type. In
            the case of records containing a template, replay the entire
            processing for the array type contained therein.

Diff:
---
 gcc/ada/gcc-interface/misc.cc | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc
index f77629ce70bf..13cb39e91cbe 100644
--- a/gcc/ada/gcc-interface/misc.cc
+++ b/gcc/ada/gcc-interface/misc.cc
@@ -784,7 +784,7 @@ gnat_get_array_descr_info (const_tree const_type,
 {
   tree type = const_cast<tree> (const_type);
   tree first_dimen, dimen;
-  bool is_bit_packed_array, is_array;
+  bool is_array;
   int i;
 
   /* Temporaries created in the first pass and used in the second one for thin
@@ -797,12 +797,7 @@ gnat_get_array_descr_info (const_tree const_type,
   /* If we have an implementation type for a packed array, get the original
      array type.  */
   if (TYPE_IMPL_PACKED_ARRAY_P (type) && TYPE_ORIGINAL_PACKED_ARRAY (type))
-    {
-      is_bit_packed_array = BIT_PACKED_ARRAY_TYPE_P (type);
-      type = TYPE_ORIGINAL_PACKED_ARRAY (type);
-    }
-  else
-    is_bit_packed_array = false;
+    type = TYPE_ORIGINAL_PACKED_ARRAY (type);
 
   /* First pass: gather all information about this array except everything
      related to dimensions.  */
@@ -833,6 +828,14 @@ gnat_get_array_descr_info (const_tree const_type,
       tree array_field = DECL_CHAIN (bounds_field);
       tree array_type = TREE_TYPE (array_field);
 
+      /* Replay the entire processing for array types.  */
+      if (TYPE_CAN_HAVE_DEBUG_TYPE_P (array_type)
+          && TYPE_DEBUG_TYPE (array_type))
+        array_type = TYPE_DEBUG_TYPE (array_type);
+      if (TYPE_IMPL_PACKED_ARRAY_P (array_type)
+          && TYPE_ORIGINAL_PACKED_ARRAY (array_type))
+        array_type = TYPE_ORIGINAL_PACKED_ARRAY (array_type);
+
       /* Shift back the address to get the address of the template.  */
       tree shift_amount
        = fold_build1 (NEGATE_EXPR, sizetype, byte_position (array_field));
@@ -859,9 +862,7 @@ gnat_get_array_descr_info (const_tree const_type,
   /* If this array has fortran convention, it's arranged in column-major
      order, so our view here has reversed dimensions.  */
   const bool convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (first_dimen);
-
-  if (BIT_PACKED_ARRAY_TYPE_P (first_dimen))
-    is_bit_packed_array = true;
+  const bool is_bit_packed_array = BIT_PACKED_ARRAY_TYPE_P (first_dimen);
 
   /* ??? For row major ordering, we probably want to emit nothing and
      instead specify it as the default in Dw_TAG_compile_unit.  */

Reply via email to