From dbda07b889c36b947e4e2cd5eeae9b92fe948a1f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 14 Nov 2012 12:33:32 +0100 Subject: Backported from mainline 2012-02-14 Jakub Jelinek PR c/52181 * c-decl.c (merge_decls): Copy DECL_USER_ALIGN bit from olddecl to newdecl. * decl.c (duplicate_decls): If olddecl has bigger DECL_ALIGN than newdecl, copy DECL_ALIGN to newdecl and or DECL_USER_ALIGN bits. * c-c++-common/pr52181.c: New test. --- gcc-4.6/gcc/c-decl.c | 1 + gcc-4.6/gcc/cp/decl.c | 7 ++++++- gcc-4.6/gcc/testsuite/c-c++-common/pr52181.c | 13 +++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc-4.6/gcc/testsuite/c-c++-common/pr52181.c diff --git a/gcc-4.6/gcc/c-decl.c b/gcc-4.6/gcc/c-decl.c index e3f02c597..3a6e8aaa9 100644 --- a/gcc-4.6/gcc/c-decl.c +++ b/gcc-4.6/gcc/c-decl.c @@ -2486,6 +2486,7 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) memcpy ((char *) olddecl + sizeof (struct tree_common), (char *) newdecl + sizeof (struct tree_common), sizeof (struct tree_decl_common) - sizeof (struct tree_common)); + DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl); switch (TREE_CODE (olddecl)) { case FUNCTION_DECL: diff --git a/gcc-4.6/gcc/cp/decl.c b/gcc-4.6/gcc/cp/decl.c index ff3baa54b..69595a97b 100644 --- a/gcc-4.6/gcc/cp/decl.c +++ b/gcc-4.6/gcc/cp/decl.c @@ -2156,7 +2156,12 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) SET_DECL_INIT_PRIORITY (olddecl, DECL_INIT_PRIORITY (newdecl)); DECL_HAS_INIT_PRIORITY_P (olddecl) = 1; } - /* Likewise for DECL_USER_ALIGN and DECL_PACKED. */ + /* Likewise for DECL_ALIGN, DECL_USER_ALIGN and DECL_PACKED. */ + if (DECL_ALIGN (olddecl) > DECL_ALIGN (newdecl)) + { + DECL_ALIGN (newdecl) = DECL_ALIGN (olddecl); + DECL_USER_ALIGN (newdecl) |= DECL_USER_ALIGN (olddecl); + } DECL_USER_ALIGN (olddecl) = DECL_USER_ALIGN (newdecl); if (TREE_CODE (newdecl) == FIELD_DECL) DECL_PACKED (olddecl) = DECL_PACKED (newdecl); diff --git a/gcc-4.6/gcc/testsuite/c-c++-common/pr52181.c b/gcc-4.6/gcc/testsuite/c-c++-common/pr52181.c new file mode 100644 index 000000000..e09bc92fc --- /dev/null +++ b/gcc-4.6/gcc/testsuite/c-c++-common/pr52181.c @@ -0,0 +1,13 @@ +/* PR c/52181 */ +/* { dg-do compile } */ + +extern const int v1[]; +const int __attribute__((aligned(16))) v1[] = { 1 }; +extern const int __attribute__((aligned(16))) v2[]; +const int v2[] = { 1 }; +extern const int __attribute__((aligned(16))) v3[]; +const int __attribute__((aligned(16))) v3[] = { 1 }; +const int __attribute__((aligned(16))) v4[] = { 1 }; +int test[(__alignof__ (v4) != __alignof__ (v1) /* { dg-bogus "is negative" } */ + || __alignof__ (v4) != __alignof__ (v2) + || __alignof__ (v4) != __alignof__ (v3)) ? -1 : 0]; -- cgit v1.2.3