public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] dwarf2out: Don't move variable sized aggregates to comdat [PR114015]
@ 2024-02-29 12:10 Jakub Jelinek
  2024-03-01 13:39 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2024-02-29 12:10 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

Hi!

The following testcase ICEs, because we decide to move that
struct { char a[n]; } DW_TAG_structure_type into .debug_types section
/ DW_UT_type DWARF5 unit, but refer from there to a DW_TAG_variable
(created artificially for the array bounds).
Even with non-bitint, I think it is just wrong to use .debug_types
section / DW_UT_type for something that uses DW_OP_fbreg and similar
in it, things clearly dependent on a particular function.
In most cases, is_nested_in_subprogram (die) check results in such
aggregates not being moved, but in the function parameter type case
that is not the case.

The following patch fixes it by returning false from should_move_die_to_comdat
for non-constant sized aggregate types, i.e. when either we gave up on
adding DW_AT_byte_size for it because it wasn't expressable, or when
it is something non-constant (location description, reference, ...).

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2024-02-29  Jakub Jelinek  <jakub@redhat.com>

	PR debug/114015
	* dwarf2out.cc (should_move_die_to_comdat): Return false for
	aggregates without DW_AT_byte_size attribute or with non-constant
	DW_AT_byte_size.

	* gcc.dg/debug/dwarf2/pr114015.c: New test.

--- gcc/dwarf2out.cc.jj	2024-02-17 01:14:48.157790666 +0100
+++ gcc/dwarf2out.cc	2024-02-28 17:11:44.259252850 +0100
@@ -8215,6 +8215,15 @@ should_move_die_to_comdat (dw_die_ref di
           || is_nested_in_subprogram (die)
           || contains_subprogram_definition (die))
 	return false;
+      if (die->die_tag != DW_TAG_enumeration_type)
+	{
+	  /* Don't move non-constant size aggregates.  */
+	  dw_attr_node *sz = get_AT (die, DW_AT_byte_size);
+	  if (sz == NULL
+	      || (AT_class (sz) != dw_val_class_unsigned_const
+		  && AT_class (sz) != dw_val_class_unsigned_const_implicit))
+	    return false;
+	}
       return true;
     case DW_TAG_array_type:
     case DW_TAG_interface_type:
--- gcc/testsuite/gcc.dg/debug/dwarf2/pr114015.c.jj	2024-02-28 17:22:33.206221495 +0100
+++ gcc/testsuite/gcc.dg/debug/dwarf2/pr114015.c	2024-02-28 17:21:49.357831730 +0100
@@ -0,0 +1,14 @@
+/* PR debug/114015 */
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-g -fvar-tracking-assignments -fdebug-types-section -w" } */
+
+#if __BITINT_MAXWIDTH__ >= 236
+typedef _BitInt(236) B;
+#else
+typedef _BitInt(63) B;
+#endif
+
+int
+foo (B n, struct { char a[n]; } o)
+{
+}

	Jakub


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

* Re: [PATCH] dwarf2out: Don't move variable sized aggregates to comdat [PR114015]
  2024-02-29 12:10 [PATCH] dwarf2out: Don't move variable sized aggregates to comdat [PR114015] Jakub Jelinek
@ 2024-03-01 13:39 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2024-03-01 13:39 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On 2/29/24 07:10, Jakub Jelinek wrote:
> Hi!
> 
> The following testcase ICEs, because we decide to move that
> struct { char a[n]; } DW_TAG_structure_type into .debug_types section
> / DW_UT_type DWARF5 unit, but refer from there to a DW_TAG_variable
> (created artificially for the array bounds).
> Even with non-bitint, I think it is just wrong to use .debug_types
> section / DW_UT_type for something that uses DW_OP_fbreg and similar
> in it, things clearly dependent on a particular function.
> In most cases, is_nested_in_subprogram (die) check results in such
> aggregates not being moved, but in the function parameter type case
> that is not the case.
> 
> The following patch fixes it by returning false from should_move_die_to_comdat
> for non-constant sized aggregate types, i.e. when either we gave up on
> adding DW_AT_byte_size for it because it wasn't expressable, or when
> it is something non-constant (location description, reference, ...).
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2024-02-29  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR debug/114015
> 	* dwarf2out.cc (should_move_die_to_comdat): Return false for
> 	aggregates without DW_AT_byte_size attribute or with non-constant
> 	DW_AT_byte_size.
> 
> 	* gcc.dg/debug/dwarf2/pr114015.c: New test.
> 
> --- gcc/dwarf2out.cc.jj	2024-02-17 01:14:48.157790666 +0100
> +++ gcc/dwarf2out.cc	2024-02-28 17:11:44.259252850 +0100
> @@ -8215,6 +8215,15 @@ should_move_die_to_comdat (dw_die_ref di
>             || is_nested_in_subprogram (die)
>             || contains_subprogram_definition (die))
>   	return false;
> +      if (die->die_tag != DW_TAG_enumeration_type)
> +	{
> +	  /* Don't move non-constant size aggregates.  */
> +	  dw_attr_node *sz = get_AT (die, DW_AT_byte_size);
> +	  if (sz == NULL
> +	      || (AT_class (sz) != dw_val_class_unsigned_const
> +		  && AT_class (sz) != dw_val_class_unsigned_const_implicit))
> +	    return false;
> +	}
>         return true;
>       case DW_TAG_array_type:
>       case DW_TAG_interface_type:
> --- gcc/testsuite/gcc.dg/debug/dwarf2/pr114015.c.jj	2024-02-28 17:22:33.206221495 +0100
> +++ gcc/testsuite/gcc.dg/debug/dwarf2/pr114015.c	2024-02-28 17:21:49.357831730 +0100
> @@ -0,0 +1,14 @@
> +/* PR debug/114015 */
> +/* { dg-do compile { target bitint } } */
> +/* { dg-options "-g -fvar-tracking-assignments -fdebug-types-section -w" } */
> +
> +#if __BITINT_MAXWIDTH__ >= 236
> +typedef _BitInt(236) B;
> +#else
> +typedef _BitInt(63) B;
> +#endif
> +
> +int
> +foo (B n, struct { char a[n]; } o)
> +{
> +}
> 
> 	Jakub
> 


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

end of thread, other threads:[~2024-03-01 13:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 12:10 [PATCH] dwarf2out: Don't move variable sized aggregates to comdat [PR114015] Jakub Jelinek
2024-03-01 13:39 ` Jason Merrill

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).