From 0212e31edbd4603853f3cbc9c9397aa8a9ae6bc3 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 9 Apr 2015 22:11:44 +0200 Subject: [PATCH] re PR c++/65690 (typedef alignment lost since r219705) PR c++/65690 * tree.c (cp_build_qualified_type_real): Copy TYPE_ALIGN and TYPE_USER_ALIGN. From-SVN: r221960 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/tree.c | 2 ++ gcc/testsuite/c-c++-common/attr-aligned-1.c | 24 +++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/attr-aligned-1.c diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 065cd75f3589..91ddee0233c1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2015-04-09 Jakub Jelinek + PR c++/65690 + * tree.c (cp_build_qualified_type_real): Copy TYPE_ALIGN and + TYPE_USER_ALIGN. + PR c++/65690 * tree.c (build_cplus_array_type): Layout type before variants are set, but copy over TYPE_SIZE and TYPE_SIZE_UNIT from the main diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 6802909a2bff..71c84ae38ef7 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1079,6 +1079,8 @@ cp_build_qualified_type_real (tree type, { t = build_variant_type_copy (t); TYPE_NAME (t) = TYPE_NAME (type); + TYPE_ALIGN (t) = TYPE_ALIGN (type); + TYPE_USER_ALIGN (t) = TYPE_USER_ALIGN (type); } } diff --git a/gcc/testsuite/c-c++-common/attr-aligned-1.c b/gcc/testsuite/c-c++-common/attr-aligned-1.c new file mode 100644 index 000000000000..671e86baeb60 --- /dev/null +++ b/gcc/testsuite/c-c++-common/attr-aligned-1.c @@ -0,0 +1,24 @@ +/* PR c++/65690 */ +/* { dg-do run } */ + +typedef double T[4][4] __attribute__((aligned (2 * __alignof__ (double)))); +void foo (const T); +struct S { T s; }; + +int +main () +{ + if (__alignof__ (struct S) != 2 * __alignof__ (double) + || __alignof__ (T) != 2 * __alignof__ (double) + || __alignof__ (const struct S) != 2 * __alignof__ (double) + || __alignof__ (const T) != 2 * __alignof__ (double)) + __builtin_abort (); + return 0; +} + +#if defined(__cplusplus) && __cplusplus >= 201103L +static_assert (alignof (S) == 2 * alignof (double), "alignment of S"); +static_assert (alignof (T) == 2 * alignof (double), "alignment of T"); +static_assert (alignof (const S) == 2 * alignof (double), "alignment of const S"); +static_assert (alignof (const T) == 2 * alignof (double), "alignment of const T"); +#endif -- 2.43.5