[PATCH] Fix dwarf2out/dbxout ICE on anonymous variable length structs/unions (PR debug/33316)

Jakub Jelinek jakub@redhat.com
Thu Sep 20 20:22:00 GMT 2007


Hi!

This is another fallout of the
http://gcc.gnu.org/ml/gcc-patches/2006-10/msg00239.html
change, {dwarf2,dbx}out don't expect DECL_NAME to be NULL on
TYPE_DECL provided as TYPE_NAME () of some RECORD_TYPE/UNION_TYPE.

The TYPE_DECL is there to make sure the sizes are gimplified
at the right place, but the type really doesn't have a name
and so no name should be emitted into the debugging info.

Ok for 4.2/trunk?

BTW, unrelated to this debug change, the testcase below
will die because of infinite recursion if compiled with
-fdump-tree-original (or various other dumps).

2007-09-20  Jakub Jelinek  <jakub@redhat.com>

	PR debug/33316
	* dwarf2out.c (modified_type_die): Handle TYPE_DECL with NULL
	DECL_NAME.
	* dbxout.c (dbxout_type): Likewise.

	* gcc.dg/debug/pr33316.c: New test.

--- gcc/dwarf2out.c.jj	2007-09-05 21:38:53.000000000 +0200
+++ gcc/dwarf2out.c	2007-09-20 20:20:09.000000000 +0200
@@ -8724,7 +8724,8 @@ modified_type_die (tree type, int is_con
      don't output a DW_TAG_typedef, since there isn't one in the
      user's program; just attach a DW_AT_name to the type.  */
   if (name
-      && (TREE_CODE (name) != TYPE_DECL || TREE_TYPE (name) == qualified_type))
+      && (TREE_CODE (name) != TYPE_DECL
+	  || (TREE_TYPE (name) == qualified_type && DECL_NAME (name))))
     {
       if (TREE_CODE (name) == TYPE_DECL)
 	/* Could just call add_name_and_src_coords_attributes here,
--- gcc/dbxout.c.jj	2007-09-20 20:32:42.000000000 +0200
+++ gcc/dbxout.c	2007-09-20 20:32:42.000000000 +0200
@@ -2029,7 +2029,11 @@ dbxout_type (tree type, int full)
 	       another type's definition; instead, output an xref
 	       and let the definition come when the name is defined.  */
 	    stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
-	    if (TYPE_NAME (type) != 0)
+	    if (TYPE_NAME (type) != 0
+		/* The C frontend creates for anonymous variable length
+		   records/unions TYPE_NAME with DECL_NAME NULL.  */
+		&& (TREE_CODE (TYPE_NAME (type)) != TYPE_DECL
+		    || DECL_NAME (TYPE_NAME (type))))
 	      dbxout_type_name (type);
 	    else
 	      {
--- gcc/testsuite/gcc.dg/debug/pr33316.c.jj	2007-09-20 20:27:11.000000000 +0200
+++ gcc/testsuite/gcc.dg/debug/pr33316.c	2007-09-20 20:26:29.000000000 +0200
@@ -0,0 +1,15 @@
+/* PR debug/33316 */
+
+int
+foo (void *x, int y)
+{
+  const struct { int d[y]; } *a = x;
+  return a[0].d[0];
+}
+
+int
+bar (void *x, int y)
+{
+  const struct S { int d[y]; } *a = x;
+  return a[0].d[0];
+}

	Jakub



More information about the Gcc-patches mailing list