This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

DWARF2 PATCH for debug/26965


In this PR we were emitting unneeded type/enumeration information because we were incorrectly emitting a definition DIE for a static data member which is not actually defined in the translation unit.

The fix is just not to emit a definition DIE if it would be another declaration. To support this we need to not treat unemitted COMDAT variables as declarations when they are actually defined; the situation that code was dealing with is now handled properly by add_location_or_const_value_attribute.

Tested x86_64-pc-linux-gnu (including GDB testsuite), applied to trunk.
commit 6857ab90006c804b65c5442fa86b226f22b8ae44
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Nov 13 10:34:52 2009 -0500

    	PR debug/26965
    	* dwarf2out.c (gen_variable_die): Don't worry about DECL_COMDAT.
    	Don't emit a second declaration at any scope.

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index e3a6412..2ebe0ae 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -17926,26 +17926,6 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
   dw_die_ref old_die = decl ? lookup_decl_die (decl) : NULL;
   dw_die_ref origin_die;
   int declaration = (DECL_EXTERNAL (decl_or_origin)
-		     /* If DECL is COMDAT and has not actually been
-			emitted, we cannot take its address; there
-			might end up being no definition anywhere in
-			the program.  For example, consider the C++
-			test case:
-
-			  template <class T>
-			  struct S { static const int i = 7; };
-
-			  template <class T>
-			  const int S<T>::i;
-
-			  int f() { return S<int>::i; }
-
-			Here, S<int>::i is not DECL_EXTERNAL, but no
-			definition is required, so the compiler will
-			not emit a definition.  */
-		     || (TREE_CODE (decl_or_origin) == VAR_DECL
-			 && DECL_COMDAT (decl_or_origin)
-			 && !TREE_ASM_WRITTEN (decl_or_origin))
 		     || class_or_namespace_scope_p (context_die));
 
   if (!origin)
@@ -18059,8 +18039,7 @@ gen_variable_die (tree decl, tree origin, dw_die_ref context_die)
      and if we already emitted a DIE for it, don't emit a second
      DIE for it again.  */
   if (old_die
-      && declaration
-      && old_die->die_parent == context_die)
+      && declaration)
     return;
 
   /* For static data members, the declaration in the class is supposed
diff --git a/gcc/testsuite/g++.dg/debug/dwarf2/static-data-member2.C b/gcc/testsuite/g++.dg/debug/dwarf2/static-data-member2.C
new file mode 100644
index 0000000..5681445
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/dwarf2/static-data-member2.C
@@ -0,0 +1,12 @@
+// PR debug/26965
+// { dg-options "-gdwarf-2 -dA" }
+// { dg-final { scan-assembler-not "DW_TAG_variable" } }
+// { dg-final { scan-assembler-not "DW_TAG_enumerator" } }
+// { dg-final { scan-assembler-not "DW_TAG_enumeration_type" } }
+
+enum x { i = 1 };
+class c {
+  static const x beg = i;
+  int foo () { return (int) beg; }
+};
+void bar () { }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]