This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR debug/43325
- From: Dodji Seketeli <dodji at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 1 Apr 2010 15:15:44 +0200
- Subject: Re: [PATCH] PR debug/43325
- References: <20100331094403.GD20524@redhat.com> <4BB38219.5010201@redhat.com> <20100331192207.GE20524@redhat.com> <4BB3BCDE.6020906@redhat.com>
On Wed, Mar 31, 2010 at 05:21:34PM -0400, Jason Merrill wrote:
> Good point. We don't want to emit anything for the automatic file
> scope decl of static data members.
>
> Maybe context_die != old_die->die_parent && context_die != comp_unit_die?
I think we don't want to emit duplicates at namespace scope either e.g,
in testsuite/g++.dg/debug/dwarf2/imported-decl-1.C:
namespace A
{
static int var2 = 2; // <--
}
int
func ()
{
using A::var2;
return var2;
}
The patch below does what you propose and adds a clause to prevent the
namespace scope case.
Tested on x86_64-unknown-linux-gnu against trunk.
Dodji
commit 91d729647c15c042474c49e5273ce796124c12ce
Author: Dodji Seketeli <dodji@redhat.com>
Date: Thu Mar 25 20:50:17 2010 +0100
Fix for PR debug/43325
gcc/ChangeLog:
PR debug/43325
* dwarf2out.c (gen_variable_die): Allow debug info for variable
re-declaration when it doesn't happen at namespace or global scope.
gcc/testsuite/ChangeLog:
PR debug/43325
* g++.dg/debug/dwarf2/redeclaration-1.C: New test case.
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 84a5fe7..640439b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -18236,11 +18236,14 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
return;
}
- /* If the compiler emitted a definition for the DECL declaration
- and if we already emitted a DIE for it, don't emit a second
- DIE for it again. */
- if (old_die
- && declaration)
+ /* If the compiler emitted a definition for DECL
+ and if we already emitted a DIE for it, don't
+ emit a second DIE for it again neither in the
+ same scope nor in namespace scope. */
+ if (old_die && declaration
+ && (context_die == old_die->die_parent
+ || context_die == comp_unit_die
+ || context_die->die_tag == DW_TAG_namespace))
return;
/* For static data members, the declaration in the class is supposed
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/redeclaration-1.C b/gcc/testsuite/g++.dg/debug/dwarf2/redeclaration-1.C
new file mode 100644
index 0000000..8aaff8e
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/redeclaration-1.C
@@ -0,0 +1,18 @@
+// Origin: PR debug/43325
+// { dg-options "-g -dA" }
+// { dg-do compile }
+
+// { dg-final { scan-assembler-times "\[^\n\r\]*\\(DIE \[^\n\r\]*DW_TAG_lexical_block\\)\[\n\r\]{1,2}\[^\n\r\]*DW_AT_low_pc\[\n\r\]{1,2}\[^\n\r\]*DW_AT_high_pc\[\n\r\]{1,2}\[^\n\r\]*\\(DIE \[^\n\r\]*DW_TAG_variable\\)\[\n\r\]{1,2}\[^\n\r\]*DW_AT_name" 2 } }
+
+namespace S
+{
+ int
+ f()
+ {
+ int i = 42;
+ {
+ extern int i;
+ return i;
+ }
+ }
+}