Patchwork Fix PR debug/45088

login
register
mail settings
Submitter Dodji Seketeli
Date Dec. 12, 2010, 3:04 p.m.
Message ID <m31v5nnib0.fsf@redhat.com>
Download mbox | patch
Permalink /patch/75249/
State New
Headers show

Comments

Dodji Seketeli - Dec. 12, 2010, 3:04 p.m.
Jason Merrill <jason@redhat.com> writes:

[...]

> What about just having gen_type_die_with_usage check is_redundant_typedef?

Like the patch below?

Bootrapped and tested on x86_64-unknown-linux-gnu against trunk.

commit d9f6a81775a92638d2c50d8478b261dd71ee2442
Author: Dodji Seketeli <dodji@seketeli.org>
Date:   Thu Nov 11 23:42:51 2010 +0100

    Fix PR debug/45088
    
    gcc/
    	* dwarf2out.c (gen_type_die_with_usage): Don't try to generate a
    	typedef DIE for an injected-class-name. Consider it as a class
    	name instead.
    
    gcc/testsuite/
    
    	* g++.dg/debug/dwarf2/self-ref-1.C: New test.
    	* g++.dg/debug/dwarf2/self-ref-2.C: Likewise.
Jason Merrill - Dec. 13, 2010, 1:36 p.m.
On 12/12/2010 10:04 AM, Dodji Seketeli wrote:
>     /* If TYPE is a typedef type variant, let's generate debug info
>        for the parent typedef which TYPE is a type of.  */
> -  if (typedef_variant_p (type))
> +  if (typedef_variant_p (type)
> +      &&  !is_redundant_typedef (TYPE_NAME (type)))

I would expect this to cause problems when things use both the main type 
and the injected variant, since the two types have different 
TREE_ASM_WRITTEN.  Rather, if type is a redundant typedef, we should 
strip it to get the underlying type.

Jason

Patch

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index c985527..38e96a8 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -20260,7 +20260,8 @@  gen_type_die_with_usage (tree type, dw_die_ref context_die,
 
   /* If TYPE is a typedef type variant, let's generate debug info
      for the parent typedef which TYPE is a type of.  */
-  if (typedef_variant_p (type))
+  if (typedef_variant_p (type)
+      && !is_redundant_typedef (TYPE_NAME (type)))
     {
       if (TREE_ASM_WRITTEN (type))
 	return;
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C
new file mode 100644
index 0000000..81bcb27
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C
@@ -0,0 +1,28 @@ 
+// Origin: PR debug/45088
+// { dg-do compile }
+// { dg-options "-g -dA" }
+// { dg-final { scan-assembler-times "\[^\n\r\]*\\(DIE\[^\n\r\]*DW_TAG_pointer_type\\)\[\n\r\]{1,2}\[^\n\r\]*DW_AT_byte_size\[\n\r\]{1,2}\[^\n\r\]*DW_AT_type" 4 } }
+
+struct A
+{
+    virtual ~A();
+};
+
+struct B : public A
+{
+    virtual ~B(){}
+};
+
+struct C : public B
+{
+    A* a1;
+};
+
+int
+main()
+{
+    C c;
+    c.a1 = 0;
+    return 0;
+}
+
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C
new file mode 100644
index 0000000..b1c5401
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C
@@ -0,0 +1,29 @@ 
+// Origin: PR debug/45088
+// { dg-do compile }
+// { dg-options "-g -dA" }
+// { dg-final { scan-assembler-times "\[^\n\r\]*\\(DIE\[^\n\r\]*DW_TAG_pointer_type\\)\[\n\r\]{1,2}\[^\n\r\]*DW_AT_byte_size\[\n\r\]{1,2}\[^\n\r\]*DW_AT_type" 4 } }
+
+template<class T>
+struct A
+{
+    virtual ~A();
+};
+
+struct B : public A<int>
+{
+    virtual ~B(){}
+};
+
+struct C : public B
+{
+    A<int>* a1;
+};
+
+int
+main()
+{
+    C c;
+    c.a1 = 0;
+    return 0;
+}
+