[lto] fixup UNION_TYPEs as early as possible

Nathan Froyd froydnj@codesourcery.com
Mon Dec 24 19:34:00 GMT 2007

The patch below fixes an issue when compiling 176.gcc.  We'd incorrectly
compute the alignment of an array member (struct rtx_def, member fld if
anybody was curious) because we were consulting a UNION_TYPE that was in
the process of being constructed.  The call chain looked something like

read DIE for rtunion_def
  read DIE for rtx_def
    read DIE for rtx_def.fld, consulting the (incomplete) DIE for rtunion_def
    compute layout for rtx_def, using bad information

Since the DWARF tells us how big our unions are, we can go ahead and set
the mode and alignment of our union type prior to reading any members of
the union.  Everything comes out swimmingly at that point.

Committed to the LTO branch.


2007-12-24  Nathan Froyd  <froydnj@codesourcery.com>

	* lto.c (lto_read_structure_union_class_type_DIE): Set TYPE_MODE
	and TYPE_ALIGN on UNION_TYPEs as soon as possible.

Index: lto/lto.c
--- lto/lto.c	(revision 131119)
+++ lto/lto.c	(working copy)
@@ -1698,6 +1698,17 @@ lto_read_structure_union_class_type_DIE 
       TYPE_SIZE (type) = bitsize_int (size * BITS_PER_UNIT);
       TYPE_SIZE_UNIT (type) = size_int (size);
+      /* Since we already know the size, go ahead and set TYPE_MODE and
+	 TYPE_ALIGN on the type, so future uses of this type come out
+	 sane.  There are special rules for RECORD_TYPE as regards
+	 TYPE_MODE, so just do this for UNION_TYPE.  */
+      if (TREE_CODE (type) == UNION_TYPE)
+	{
+	  compute_record_mode (type);
+	}
   /* Store this entry so that cases like:

More information about the Gcc-patches mailing list