public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Fix incorrect array bounds with -fgnat-encodings=minimal in DWARF
@ 2021-05-07 11:09 Eric Botcazou
  2021-05-07 18:48 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Botcazou @ 2021-05-07 11:09 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 529 bytes --]

Hi,

this makes add_subscript_info query the get_array_descr_info hook for the
actual information when it is defined.

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


2021-05-07  Eric Botcazou  <ebotcazou@adacore.com>

	* dwarf2out.c (add_subscript_info): Retrieve the bounds and the 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.


2021-05-07  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/debug18.adb: New test.

-- 
Eric Botcazou

[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 3832 bytes --]

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 5b819ab1a92..ad948d94da9 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -21223,8 +21223,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.  */
@@ -21232,9 +21230,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);
@@ -21282,26 +21292,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:*)
@@ -21309,8 +21315,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))
 	    {
@@ -22039,6 +22046,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)
 {

[-- Attachment #3: debug18.adb --]
[-- Type: text/x-adasrc, Size: 510 bytes --]

-- { dg-do compile }
-- { dg-skip-if "No Dwarf" { { hppa*-*-hpux* } && { ! lp64 } } }
-- { dg-options "-cargs -O0 -g -dA -fgnat-encodings=minimal -margs" }

procedure Debug18 is

   procedure Check (Size : Integer) is
      type Bit_Array_Type is array (1 .. Size) of boolean;
      pragma Pack (Bit_Array_Type);

      Bits : Bit_Array_Type := (others => False);
   begin
      Bits (Bits'First) := True;
   end;
  
begin
   Check (Size => 9);
end;

-- { dg-final { scan-assembler-not "DW_AT_lower_bound" } }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch] Fix incorrect array bounds with -fgnat-encodings=minimal in DWARF
  2021-05-07 11:09 [patch] Fix incorrect array bounds with -fgnat-encodings=minimal in DWARF Eric Botcazou
@ 2021-05-07 18:48 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2021-05-07 18:48 UTC (permalink / raw)
  To: Eric Botcazou, gcc-patches


On 5/7/2021 5:09 AM, Eric Botcazou wrote:
> Hi,
>
> this makes add_subscript_info query the get_array_descr_info hook for the
> actual information when it is defined.
>
> Tested on x86-64/Linux, OK for mainline?
>
>
> 2021-05-07  Eric Botcazou  <ebotcazou@adacore.com>
>
> 	* dwarf2out.c (add_subscript_info): Retrieve the bounds and the 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.
>
>
> 2021-05-07  Eric Botcazou  <ebotcazou@adacore.com>
>
> 	* gnat.dg/debug18.adb: New test.

OK

jeff



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-07 18:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 11:09 [patch] Fix incorrect array bounds with -fgnat-encodings=minimal in DWARF Eric Botcazou
2021-05-07 18:48 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).