Patchwork RX: Fix packed strcuture field layout.

login
register
mail settings
Submitter Nick Clifton
Date Nov. 16, 2010, 4:31 p.m.
Message ID <m3wrod8c38.fsf@redhat.com>
Download mbox | patch
Permalink /patch/71428/
State New
Headers show

Comments

Nick Clifton - Nov. 16, 2010, 4:31 p.m.
Hi Guys,

  I am checking in the patch below to fix a small problem with the RX
  backend.  The problem was that the presence of the "packed" attribute
  should override the default field and bitfield layout behaviour, but
  this was not happening.  This patch fixes the problem and adds a test
  case to make sure that it does not arise again.

Cheers
  Nick

gcc/ChangeLog
2010-11-16  Nick Clifton  <nickc@redhat.com>

	* config/rx/rx.c (rx_is_ms_bitfield_layout): Return false if the
	record is packed.

gcc/testsuite/ChangeLog
2010-11-16  Nick Clifton  <nickc@redhat.com>

	* gcc.target/rx/pack.c: New test.

Patch

Index: gcc/config/rx/rx.c
===================================================================
--- gcc/config/rx/rx.c	(revision 166792)
+++ gcc/config/rx/rx.c	(working copy)
@@ -2306,7 +2306,8 @@ 
 static bool
 rx_is_ms_bitfield_layout (const_tree record_type ATTRIBUTE_UNUSED)
 {
-  return TRUE;
+  /* The packed attribute overrides the MS behaviour.  */
+  return ! TYPE_PACKED (record_type);
 }
 
 /* Try to generate code for the "isnv" pattern which inserts bits

Index: gcc/testsuite/gcc.target/rx/pack.c
===================================================================
--- gcc/testsuite/gcc.target/rx/pack.c	(revision 0)
+++ gcc/testsuite/gcc.target/rx/pack.c	(revision 0)
@@ -0,0 +1,25 @@ 
+/* { dg-do run } */
+
+typedef unsigned short	INT16U;
+
+typedef struct tst_2
+{
+  INT16U	f0;	// [+0]
+  INT16U *	f1;	// [+2]
+  INT16U	f2;	// [+6]
+  INT16U *	f3;	// [+8]
+} __attribute__ ((__packed__)) t2;
+
+#include <stddef.h>
+#include <stdlib.h>
+
+int main (void)
+{
+  if (offsetof (t2, f1) != 2)
+    abort ();
+  if (offsetof (t2, f2) != 6)
+    abort ();
+  if (offsetof (t2, f3) != 8)
+    abort ();
+  exit (0);
+}