[patch RFA] Fix PR 27942 (Was: Packed union doesn't make the unaligned magic on ms_bitfield)

Kaz Kojima kkojima@rr.iij4u.or.jp
Sun Jun 11 13:51:00 GMT 2006


I'd like to resend the patch with the testcase for approval.
Tested with bootstrap and "make -k check" on i686-pc-linux-gnu
and i686-pc-cygwin with no new failures.

Regards,
	kaz
--
:ADDPATCH middle-end:

[gcc/ChangeLog]
2006-06-11  Kaz Kojima  <kkojima@gcc.gnu.org>

	PR middle-end/27942
	*stor-layout.c (update_alignment_for_field): Don't add extra
	alignment for packed non-bitfield fields in ms_bitfield_layout_p
	code.

[gcc/testsuite/ChangeLog]
2006-06-11  Kaz Kojima  <kkojima@gcc.gnu.org>

	* gcc.dg/attr-ms_struct-packed1.c: New.

diff -uprN ORIG/trunk/gcc/stor-layout.c LOCAL/trunk/gcc/stor-layout.c
--- ORIG/trunk/gcc/stor-layout.c	2006-06-06 10:02:03.000000000 +0900
+++ TMP/trunk/gcc/stor-layout.c	2006-06-09 19:43:50.000000000 +0900
@@ -693,7 +693,7 @@ update_alignment_for_field (record_layou
 	 the type, except that for zero-size bitfields this only
 	 applies if there was an immediately prior, nonzero-size
 	 bitfield.  (That's the way it is, experimentally.) */
-      if (!is_bitfield
+      if ((!is_bitfield && !DECL_PACKED (field))
 	  || (!integer_zerop (DECL_SIZE (field))
 	      ? !DECL_PACKED (field)
 	      : (rli->prev_field
diff -uprN ORIG/trunk/gcc/testsuite/gcc.dg/attr-ms_struct-packed1.c LOCAL/trunk/gcc/testsuite/gcc.dg/attr-ms_struct-packed1.c
--- ORIG/trunk/gcc/testsuite/gcc.dg/attr-ms_struct-packed1.c	1970-01-01 09:00:00.000000000 +0900
+++ TMP/trunk/gcc/testsuite/gcc.dg/attr-ms_struct-packed1.c	2006-06-10 07:13:00.000000000 +0900
@@ -0,0 +1,25 @@
+/* Test for MS structure with packed attribute.  */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-darwin* } }
+/* { dg-options "-std=gnu99" } */
+
+extern void abort ();
+
+union u
+{
+  int a;
+} __attribute__((__ms_struct__, __packed__));
+
+struct s
+{
+  char c;
+  union u u;
+};
+
+int
+main (void)
+{
+  if (sizeof (struct s) != (sizeof (char) + sizeof (union u))) 
+    abort ();
+
+  return 0;
+}



More information about the Gcc-patches mailing list