diff mbox

C++ PATCH to c++/45088 (injected-class-name in dwarf output)

Message ID 4F85C3DF.5060705@redhat.com
State New
Headers show

Commit Message

Jason Merrill April 11, 2012, 5:48 p.m. UTC
Dodji's final patch for 45088 fixed the GDB regression, but as Jakub 
recently pointed out to me, we still end up with redundant 
DW_TAG_pointer_types in some cases, with one for pointer-to-class and 
the other for pointer-to-injected-class-name.  We strip the 
injected-class-name in dwarf2out so that both pointers point to the same 
target type.  To avoid this, let's strip the injected-class-name earlier 
in the front end.

Of course, this is what Dodji first proposed to do for this issue, and I 
steered him wrong...

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 9a2db2e62c441147007f520a3983f6bc12a7385f
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Apr 11 11:05:28 2012 -0400

    	* decl.c (grokdeclarator): Strip the injected-class-name typedef
    	if we are building a declaration or compound type.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 8b22192..711ceef 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8943,6 +8943,17 @@  grokdeclarator (const cp_declarator *declarator,
     error ("qualifiers are not allowed on declaration of %<operator %T%>",
 	   ctor_return_type);
 
+  /* If we're using the injected-class-name to form a compound type or a
+     declaration, replace it with the underlying class so we don't get
+     redundant typedefs in the debug output.  But if we are returning the
+     type unchanged, leave it alone so that it's available to
+     maybe_get_template_decl_from_type_decl.  */
+  if (CLASS_TYPE_P (type)
+      && DECL_SELF_REFERENCE_P (TYPE_NAME (type))
+      && type == TREE_TYPE (TYPE_NAME (type))
+      && (declarator || type_quals))
+    type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
+
   type_quals |= cp_type_quals (type);
   type = cp_build_qualified_type_real
     (type, type_quals, ((typedef_decl && !DECL_ARTIFICIAL (typedef_decl)
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C
index 81bcb27..06db9dc 100644
--- a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-1.C
@@ -5,7 +5,7 @@ 
 
 struct A
 {
-    virtual ~A();
+    virtual ~A(){}
 };
 
 struct B : public A
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C
index b1c5401..d5463c0 100644
--- a/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/self-ref-2.C
@@ -6,7 +6,7 @@ 
 template<class T>
 struct A
 {
-    virtual ~A();
+    virtual ~A(){}
 };
 
 struct B : public A<int>