From 7c4c9fcc0de865876fb25fe75f4ed6e143bd48c0 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Fri, 7 May 2021 22:52:18 +0200 Subject: Fix incorrect array bounds with -fgnat-encodings=minimal in DWARF This makes add_subscript_info query the get_array_descr_info hook for the actual information when it is defined. gcc/ * cfgexpand.c (expand_gimple_basic_block): Do not inherit a current location for the outgoing edges of an empty block. * dwarf2out.c (add_subscript_info): Retrieve the bounds and index type by means of the get_array_descr_info langhook, if it is set and returns true. Remove obsolete code dealing with unnamed subtypes. gcc/testsuite/ * gnat.dg/debug18.adb: New test. --- gcc/dwarf2out.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'gcc/dwarf2out.c') diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 871362b..a5ec21a 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -21313,8 +21313,6 @@ add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, /* Add subscript info to TYPE_DIE, describing an array TYPE, collapsing possibly nested array subscripts in a flat sequence if COLLAPSE_P is true. - Note that the block of subscript information for an array type also - includes information about the element type of the given array type. This function reuses previously set type and bound information if available. */ @@ -21322,9 +21320,21 @@ add_bound_info (dw_die_ref subrange_die, enum dwarf_attribute bound_attr, static void add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p) { - unsigned dimension_number; - tree lower, upper; dw_die_ref child = type_die->die_child; + struct array_descr_info info; + int dimension_number; + + if (lang_hooks.types.get_array_descr_info) + { + memset (&info, 0, sizeof (info)); + if (lang_hooks.types.get_array_descr_info (type, &info)) + /* Fortran sometimes emits array types with no dimension. */ + gcc_assert (info.ndimensions >= 0 + && info.ndimensions + <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN); + } + else + info.ndimensions = 0; for (dimension_number = 0; TREE_CODE (type) == ARRAY_TYPE && (dimension_number == 0 || collapse_p); @@ -21372,26 +21382,22 @@ add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p) if (domain) { /* We have an array type with specified bounds. */ - lower = TYPE_MIN_VALUE (domain); - upper = TYPE_MAX_VALUE (domain); + tree lower = TYPE_MIN_VALUE (domain); + tree upper = TYPE_MAX_VALUE (domain); + tree index_type = TREE_TYPE (domain); - /* Define the index type. */ - if (TREE_TYPE (domain) - && !get_AT (subrange_die, DW_AT_type)) + if (dimension_number <= info.ndimensions - 1) { - /* ??? This is probably an Ada unnamed subrange type. Ignore the - TREE_TYPE field. We can't emit debug info for this - because it is an unnamed integral type. */ - if (TREE_CODE (domain) == INTEGER_TYPE - && TYPE_NAME (domain) == NULL_TREE - && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE - && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) - ; - else - add_type_attribute (subrange_die, TREE_TYPE (domain), - TYPE_UNQUALIFIED, false, type_die); + lower = info.dimen[dimension_number].lower_bound; + upper = info.dimen[dimension_number].upper_bound; + index_type = info.dimen[dimension_number].bounds_type; } + /* Define the index type. */ + if (index_type && !get_AT (subrange_die, DW_AT_type)) + add_type_attribute (subrange_die, index_type, TYPE_UNQUALIFIED, + false, type_die); + /* ??? If upper is NULL, the array has unspecified length, but it does have a lower bound. This happens with Fortran dimension arr(N:*) @@ -21399,8 +21405,9 @@ add_subscript_info (dw_die_ref type_die, tree type, bool collapse_p) to produce useful results, go ahead and output the lower bound solo, and hope the debugger can cope. */ - if (!get_AT (subrange_die, DW_AT_lower_bound)) + if (lower && !get_AT (subrange_die, DW_AT_lower_bound)) add_bound_info (subrange_die, DW_AT_lower_bound, lower, NULL); + if (!get_AT (subrange_die, DW_AT_upper_bound) && !get_AT (subrange_die, DW_AT_count)) { @@ -22129,6 +22136,7 @@ decl_start_label (tree decl) /* For variable-length arrays that have been previously generated, but may be incomplete due to missing subscript info, fill the subscript info. Return TRUE if this is one of those cases. */ + static bool fill_variable_array_bounds (tree type) { -- cgit v1.1