From 1740f8a1cd06cd92e17be4396e527d8d25591210 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 10 Oct 2014 19:43:21 +0200 Subject: [PATCH] re PR c/63495 (struct __attribute__ ((aligned (8))) broken on x86) PR c/63495 * stor-layout.c (min_align_of_type): Don't decrease alignment through BIGGEST_FIELD_ALIGNMENT or ADJUST_FIELD_ALIGN if TYPE_USER_ALIGN is set. * gcc.target/i386/pr63495.c: New test. From-SVN: r216101 --- gcc/ChangeLog | 7 +++++++ gcc/stor-layout.c | 16 +++++++++------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/i386/pr63495.c | 6 ++++++ 4 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr63495.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d418235e08f..55c99d40357 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2014-10-10 Jakub Jelinek + + PR c/63495 + * stor-layout.c (min_align_of_type): Don't decrease alignment + through BIGGEST_FIELD_ALIGNMENT or ADJUST_FIELD_ALIGN if + TYPE_USER_ALIGN is set. + 2014-10-10 Uros Bizjak PR rtl-optimization/63483 diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 8328326facf..eefc52a5893 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -2400,17 +2400,19 @@ min_align_of_type (tree type) { unsigned int align = TYPE_ALIGN (type); align = MIN (align, BIGGEST_ALIGNMENT); + if (!TYPE_USER_ALIGN (type)) + { #ifdef BIGGEST_FIELD_ALIGNMENT - align = MIN (align, BIGGEST_FIELD_ALIGNMENT); + align = MIN (align, BIGGEST_FIELD_ALIGNMENT); #endif - unsigned int field_align = align; + unsigned int field_align = align; #ifdef ADJUST_FIELD_ALIGN - tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, - type); - field_align = ADJUST_FIELD_ALIGN (field, field_align); - ggc_free (field); + tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, type); + field_align = ADJUST_FIELD_ALIGN (field, field_align); + ggc_free (field); #endif - align = MIN (align, field_align); + align = MIN (align, field_align); + } return align / BITS_PER_UNIT; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b8cd638dd7d..e77c6a1ff32 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-10 Jakub Jelinek + + PR c/63495 + * gcc.target/i386/pr63495.c: New test. + 2014-10-10 Marek Polacek * c-c++-common/ubsan/object-size-1.c: New test. diff --git a/gcc/testsuite/gcc.target/i386/pr63495.c b/gcc/testsuite/gcc.target/i386/pr63495.c new file mode 100644 index 00000000000..7f02f37d8ce --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr63495.c @@ -0,0 +1,6 @@ +/* PR c/63495 */ +/* { dg-do compile { target { i?86-*-linux* x86_64-*-linux* } } } */ +/* { dg-options "-std=gnu11" } */ + +struct __attribute__ ((aligned (8))) S { char c; }; +_Static_assert (_Alignof (struct S) >= 8, "wrong alignment"); -- 2.30.2