[PATCH] Avoid redundant DW_AT_const_type (take 2)

Jakub Jelinek jakub@redhat.com
Wed Oct 7 16:14:00 GMT 2009


Hi!

On Tue, Oct 06, 2009 at 05:59:05PM -0400, Jason Merrill wrote:
> On 10/06/2009 05:45 PM, Jakub Jelinek wrote:
>> +  /* Don't add DW_AT_const_value if abstract origin already has one.  */
>> +  origin_die = get_AT_ref (var_die, DW_AT_abstract_origin);
>> +  if (origin_die&&  get_AT (origin_die, DW_AT_const_value))
>> +    return false;
>
> get_AT looks into the abstract origin, so this could just be
>
>  if (get_AT (var_die, DW_AT_const_value)

You're right, this works too and I've bootstrapped/regtested it.

Ok for trunk?

2009-10-07  Jakub Jelinek  <jakub@redhat.com>

	* dwarf2out.c (tree_add_const_value_attribute_for_decl): Don't add
	DW_AT_const_value if VAR_DIE already has DW_AT_abstract_origin
	refering to a DIE with DW_AT_const_value.

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

--- gcc/dwarf2out.c.jj	2009-10-05 21:51:40.000000000 +0200
+++ gcc/dwarf2out.c	2009-10-07 09:19:20.000000000 +0200
@@ -15701,6 +15701,10 @@ tree_add_const_value_attribute_for_decl 
     else
       return false;
 
+  /* Don't add DW_AT_const_value if abstract origin already has one.  */
+  if (get_AT (var_die, DW_AT_const_value))
+    return false;
+
   return tree_add_const_value_attribute (var_die, DECL_INITIAL (decl));
 }
 
--- gcc/testsuite/gcc.dg/debug/dwarf2/inline3.c.jj	2009-10-06 17:41:06.000000000 +0200
+++ gcc/testsuite/gcc.dg/debug/dwarf2/inline3.c	2009-10-06 17:41:06.000000000 +0200
@@ -0,0 +1,22 @@
+/* Verify that only one DW_AT_const_value is emitted for baz,
+   not for baz abstract DIE and again inside of
+   DW_TAG_inlined_subroutine.  */
+/* { dg-options "-O2 -g -dA" } */
+/* { dg-do compile } */
+/* { dg-final { scan-assembler-times " DW_AT_const_value" 1 } } */
+
+struct A { const long i; const long j; };
+
+static inline long
+foo (void)
+{
+  const struct A baz = { .i = 2, .j = 21 };
+  asm volatile ("" : : : "memory");
+  return baz.i * baz.j;
+}
+
+int
+main ()
+{
+  return foo () - 42;
+}


	Jakub



More information about the Gcc-patches mailing list