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]

[PATCH] Fix ICE with -feliminate-dwarf2-dups or -gdwarf-4 (PR debug/46123)


Hi!

As mentioned in the PR, reusing a DW_TAG_subprogram DW_AT_declaration DIE
for the definition doesn't work with -feliminate-dwarf2-dups or -gdwarf-4,
there we really want to avoid DW_TAG_subprograms for actual routine
definitions, otherwise we ICE because .debug_aranges isn't split to point to
those units (but the comdat CUs don't seem to be meant to contain debug info
for code).

Fixed thusly, bootstrapped/regtested on x86_64-linux, ok for trunk?

2010-11-18  Jakub Jelinek  <jakub@redhat.com>

	PR debug/46123
	* dwarf2out.c (gen_subprogram_die): Don't reuse the old
	die if -feliminate-dwarf2-dups or -gdwarf-4.

	* g++.dg/debug/pr46123.C: New test.
	* g++.dg/debug/dwarf2/pr46123.C: New test.

--- gcc/dwarf2out.c.jj	2010-11-15 23:28:02.000000000 +0100
+++ gcc/dwarf2out.c	2010-11-18 13:45:10.189654791 +0100
@@ -18840,6 +18840,21 @@ gen_subprogram_die (tree decl, dw_die_re
 		  && (get_AT_unsigned (old_die, DW_AT_decl_line)
 		      == (unsigned) s.line))))
 	{
+	 /* Don't use the old DIE if eliminating DWARF dups using
+	    break_out_includes or DWARF4 .debug_types, as that could
+	    leave subprogram DIEs with *_pc attributes in the comdat CUs
+	    or .debug_types.  */
+	  if ((flag_eliminate_dwarf2_dups || dwarf_version >= 4)
+	      && !is_cu_die (old_die->die_parent))
+	    {
+	      if (decl_function_context (decl)
+		  && DECL_CONTEXT (decl)
+		  && TREE_CODE (DECL_CONTEXT (decl)) != FUNCTION_DECL
+		  && TREE_CODE (DECL_CONTEXT (decl)) != NAMESPACE_DECL)
+		context_die = comp_unit_die ();
+	      goto new_subr_die;
+	    }
+	    
 	  subr_die = old_die;
 
 	  /* Clear out the declaration attribute and the formal parameters.
@@ -18853,6 +18868,7 @@ gen_subprogram_die (tree decl, dw_die_re
 	}
       else
 	{
+	new_subr_die:
 	  subr_die = new_die (DW_TAG_subprogram, context_die, decl);
 	  add_AT_specification (subr_die, old_die);
 	  if (get_AT_file (old_die, DW_AT_decl_file) != file_index)
--- gcc/testsuite/g++.dg/debug/dwarf2/pr46123.C.jj	2010-11-18 13:31:40.000000000 +0100
+++ gcc/testsuite/g++.dg/debug/dwarf2/pr46123.C	2010-11-18 13:46:09.889261025 +0100
@@ -0,0 +1,47 @@
+// PR debug/46123
+// { dg-do compile }
+// { dg-options "-gdwarf-4" }
+
+struct foo
+{
+  static int bar ()
+  {
+    int i;
+    static int baz = 1;
+    {
+      static int baz = 2;
+      i = baz++;
+    }
+    {
+      struct baz
+      {
+	static int m ()
+	{
+	  static int n;
+	  return n += 10;
+	}
+      };
+      baz a;
+      i += a.m ();
+    }
+    {
+      static int baz = 3;
+      i += baz;
+      baz += 30;
+    }
+    i += baz;
+    baz += 60;
+    return i;
+  }
+};
+
+int main ()
+{
+  foo x;
+
+  if (x.bar () != 16)
+    return 1;
+  if (x.bar() != 117)
+    return 1;
+  return 0;
+}
--- gcc/testsuite/g++.dg/debug/pr46123.C.jj	2010-11-18 13:31:40.078247818 +0100
+++ gcc/testsuite/g++.dg/debug/pr46123.C	2010-11-18 13:34:06.486261122 +0100
@@ -0,0 +1,47 @@
+// PR debug/46123
+// { dg-do compile }
+// { dg-options "-g -feliminate-dwarf2-dups" }
+
+struct foo
+{
+  static int bar ()
+  {
+    int i;
+    static int baz = 1;
+    {
+      static int baz = 2;
+      i = baz++;
+    }
+    {
+      struct baz
+      {
+	static int m ()
+	{
+	  static int n;
+	  return n += 10;
+	}
+      };
+      baz a;
+      i += a.m ();
+    }
+    {
+      static int baz = 3;
+      i += baz;
+      baz += 30;
+    }
+    i += baz;
+    baz += 60;
+    return i;
+  }
+};
+
+int main ()
+{
+  foo x;
+
+  if (x.bar () != 16)
+    return 1;
+  if (x.bar() != 117)
+    return 1;
+  return 0;
+}

	Jakub


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