From: Eric Botcazou <[email protected]>
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.
Tested on x86_64-pc-linux-gnu, committed on master.
---
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 f77629ce70b..13cb39e91cb 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. */
--
2.45.2