@@ -880,12 +880,19 @@ build_cplus_array_type (tree elt_type, t
{
t = build_min_array_type (elt_type, index_type);
set_array_type_canon (t, elt_type, index_type);
+ if (!dependent)
+ {
+ layout_type (t);
+ /* Make sure sizes are shared with the main variant.
+ layout_type can't be called after setting TYPE_NEXT_VARIANT,
+ as it will overwrite alignment etc. of all variants. */
+ TYPE_SIZE (t) = TYPE_SIZE (m);
+ TYPE_SIZE_UNIT (t) = TYPE_SIZE_UNIT (m);
+ }
TYPE_MAIN_VARIANT (t) = m;
TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
TYPE_NEXT_VARIANT (m) = t;
- if (!dependent)
- layout_type (t);
}
}
@@ -0,0 +1,22 @@
+/* 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))
+ __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");
+#endif
On Thu, Apr 09, 2015 at 10:48:29AM -0400, Jason Merrill wrote: > So the first hunk of the first patch is OK. Ok, I've committed this to fix the regression. 2015-04-09 Jakub Jelinek <jakub@redhat.com> 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 variant. * c-c++-common/attr-aligned-1.c: New test. Jakub