summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKai Tietz <ktietz@redhat.com>2012-02-20 23:05:08 +0100
committerKai Tietz <ktietz@gcc.gnu.org>2012-02-20 23:05:08 +0100
commit9954e17f70b8212a51603332d6c15991b7ada434 (patch)
tree76fcb1843cfb01eb15783e1bd2edaeb026e72dcf /gcc
parentd74703744533a360a30ed5d62a6174072fb3bdf9 (diff)
downloadgcc-9954e17f70b8212a51603332d6c15991b7ada434.tar.gz
re PR target/52238 (-mms-bitfields: __attribute__ ((aligned (n))) ignored for struct members)
PR target/52238 * stor-layout.c (place_field): Handle desired_align for ms-bitfields, too. * gcc.dg/bf-ms-layout-3.c: New testcase. From-SVN: r184409
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/stor-layout.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/bf-ms-layout-3.c51
4 files changed, 67 insertions, 6 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b8366f41959..c579214456a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2012-02-20 Kai Tietz <ktietz@redhat.com>
+
+ PR target/52238
+ * stor-layout.c (place_field): Handle desired_align for
+ ms-bitfields, too.
+
2012-02-20 Richard Guenther <rguenther@suse.de>
PR tree-optimization/52298
diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c
index 35320c2fad9..a1ac0008c75 100644
--- a/gcc/stor-layout.c
+++ b/gcc/stor-layout.c
@@ -1141,15 +1141,14 @@ place_field (record_layout_info rli, tree field)
}
/* Does this field automatically have alignment it needs by virtue
- of the fields that precede it and the record's own alignment?
- We already align ms_struct fields, so don't re-align them. */
- if (known_align < desired_align
- && !targetm.ms_bitfield_layout_p (rli->t))
+ of the fields that precede it and the record's own alignment? */
+ if (known_align < desired_align)
{
/* No, we need to skip space before this field.
Bump the cumulative size to multiple of field alignment. */
- if (DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION)
+ if (!targetm.ms_bitfield_layout_p (rli->t)
+ && DECL_SOURCE_LOCATION (field) != BUILTINS_LOCATION)
warning (OPT_Wpadded, "padding struct to align %q+D", field);
/* If the alignment is still within offset_align, just align
@@ -1171,7 +1170,8 @@ place_field (record_layout_info rli, tree field)
if (! TREE_CONSTANT (rli->offset))
rli->offset_align = desired_align;
-
+ if (targetm.ms_bitfield_layout_p (rli->t))
+ rli->prev_field = NULL;
}
/* Handle compatibility with PCC. Note that if the record has any
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6632b58b418..df818afcaeb 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2012-02-20 Kai Tietz <ktietz@redhat.com>
+
+ * gcc.dg/bf-ms-layout-3.c: New testcase.
+
2012-02-20 Thomas Koenig <tkoenig@gcc.gnu.org>
PR testsuite/52229
diff --git a/gcc/testsuite/gcc.dg/bf-ms-layout-3.c b/gcc/testsuite/gcc.dg/bf-ms-layout-3.c
new file mode 100644
index 00000000000..9abb9dc2d06
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bf-ms-layout-3.c
@@ -0,0 +1,51 @@
+/* Test for MS bitfield layout */
+/* { dg-do run { target *-*-interix* *-*-mingw* *-*-cygwin* i?86-*-* x86_64-*-* } } */
+
+extern void abort();
+
+struct s1_t {
+ char a;
+ char b __attribute__ ((aligned (16)));
+} __attribute__ ((ms_struct));
+struct s1_t s1;
+
+struct s2_t {
+ char a;
+ char b;
+} __attribute__ ((ms_struct));
+struct s2_t s2;
+
+struct s3_t {
+ char a : 6;
+ char b __attribute__ ((aligned (16)));
+} __attribute__ ((ms_struct));
+struct s3_t s3;
+
+struct s4_t {
+ char a : 6;
+ char b __attribute__ ((aligned (2)));
+} __attribute__ ((ms_struct));
+struct s4_t s4;
+
+struct s5_t {
+ char a : 6;
+ char b __attribute__ ((aligned (1)));
+} __attribute__ ((ms_struct));
+struct s5_t s5;
+
+__PTRDIFF_TYPE__ offs (const void *a, const void *b)
+{
+ return (__PTRDIFF_TYPE__) ((const char*)a - (const char*)b);
+}
+
+int main()
+{
+ if (offs (&s1.b, &s1) != 16
+ || offs (&s2.b, &s2) != 1
+ || offs (&s3.b, &s3) != 16
+ || offs (&s4.b, &s4) != 2
+ || offs (&s5.b, &s5) != 1)
+ abort ();
+ return 0;
+}
+