extern const int v1[]; const int __attribute__((aligned(16))) v1[] = { 0 }; extern const int __attribute__((aligned(16))) v2[]; const int v2[] = { 0 }; extern const int __attribute__((aligned(16))) v3[]; const int __attribute__((aligned(16))) v3[] = { 0 }; const int __attribute__((aligned(16))) v4[] = { 0 }; int test[(__alignof__ (v4) != __alignof__ (v1)/* { dg-bogus "is negative" } */ || __alignof__ (v4) != __alignof__ (v2) || __alignof__ (v4) != __alignof__ (v3)) ? -1 : 0]; fails with gcc 4.7, worked with 4.6, but it looks like the actual bug is of an earlier date, when DECL_USER_ALIGN bit has been moved from tree_decl_common etc. down into tree_base.
Created attachment 26621 [details] gcc47-pr52181.patch Untested fix. The testcase shows that the C++ FE has a similar bug, but in the other direction, when olddecl has aligned attribute and newdecl doesn't.
The regression is present on tip of 4.6 branch as well, exposed by recent backports from mainline.
Author: jakub Date: Tue Feb 14 06:15:35 2012 New Revision: 184193 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184193 Log: 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. Added: trunk/gcc/testsuite/c-c++-common/pr52181.c Modified: trunk/gcc/ChangeLog trunk/gcc/c-decl.c trunk/gcc/cp/ChangeLog trunk/gcc/cp/decl.c trunk/gcc/testsuite/ChangeLog
Fixed.
Thanks for the quick fix! Are you planning to backport to 4.6 as well?
Author: jakub Date: Tue Feb 14 23:34:34 2012 New Revision: 184242 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=184242 Log: Backported from mainline 2012-02-14 Jakub Jelinek <jakub@redhat.com> 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. Added: branches/gcc-4_6-branch/gcc/testsuite/c-c++-common/pr52181.c Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/c-decl.c branches/gcc-4_6-branch/gcc/cp/ChangeLog branches/gcc-4_6-branch/gcc/cp/decl.c branches/gcc-4_6-branch/gcc/testsuite/ChangeLog