1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base
3 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
4 // expected-no-diagnostics
6 #define SA(n, p) int a##n[(p) ? 1 : -1]
13 SA(0, sizeof(A
) == 8);
19 SA(1, sizeof(B
) == 12);
22 // Make fields private so C won't be a POD type.
28 SA(2, sizeof(C
) == 8);
34 SA(3, sizeof(D
) == 8);
36 struct __attribute__((packed
)) E
{
41 SA(4, sizeof(E
) == 5);
43 struct __attribute__((packed
)) F
: E
{
47 SA(5, sizeof(F
) == 6);
52 SA(6, sizeof(H
) == 1);
57 } __attribute__((packed
));
59 SA(6_1
, sizeof(I
) == 5);
64 class A
{ bool iv0
: 1; };
65 SA(7, sizeof(A
) == 1);
67 class B
: A
{ bool iv0
: 1; };
68 SA(8, sizeof(B
) == 2);
70 struct C
{ bool iv0
: 1; };
71 SA(9, sizeof(C
) == 1);
73 struct D
: C
{ bool iv0
: 1; };
74 SA(10, sizeof(D
) == 2);
80 // Test that we don't assert on this hierarchy.
82 struct B
: A
{ virtual void b(); };
83 class C
: virtual A
{ int c
; };
84 struct D
: virtual B
{ };
85 struct E
: C
, virtual D
{ };
86 class F
: virtual E
{ };
87 struct G
: virtual E
, F
{ };
89 SA(0, sizeof(G
) == 24);
95 // Test that this somewhat complex class structure is laid out correctly.
97 struct B
: A
{ virtual void b(); };
98 struct C
: virtual B
{ };
99 struct D
: virtual A
{ };
100 struct E
: virtual B
, D
{ };
101 struct F
: E
, virtual C
{ };
102 struct G
: virtual F
, A
{ };
105 SA(0, sizeof(H
) == 24);
111 struct pod_in_11_only
{
116 struct tail_padded_pod_in_11_only
{
117 pod_in_11_only pod11
;
121 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
{
122 char may_go_into_tail_padding
;
125 SA(0, sizeof(might_use_tail_padding
) == 16);
129 struct pod_in_11_only
{
134 struct tail_padded_pod_in_11_only
{
135 pod_in_11_only pod11
__attribute__((aligned(16)));
138 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
{
139 char may_go_into_tail_padding
;
142 SA(0, sizeof(might_use_tail_padding
) == 16);
146 struct pod_in_11_only
{
151 struct tail_padded_pod_in_11_only
{
152 pod_in_11_only pod11
;
160 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
163 SA(0, sizeof(might_use_tail_padding
) == 16);
167 struct pod_in_11_only
{
172 struct tail_padded_pod_in_11_only
{
173 pod_in_11_only pod11
;
181 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
182 char may_go_into_tail_padding
;
184 SA(0, sizeof(might_use_tail_padding
) == 16);
188 struct pod_in_11_only
{
193 struct pod_in_11_only2
{
198 struct tail_padded_pod_in_11_only
{
199 pod_in_11_only pod11
;
208 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
209 char may_go_into_tail_padding
;
211 SA(0, sizeof(might_use_tail_padding
) == 32);
215 struct pod_in_11_only
{
220 struct pod_in_11_only2
{
225 struct tail_padded_pod_in_11_only
{
226 pod_in_11_only pod11
;
235 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
236 char may_go_into_tail_padding
;
238 SA(0, sizeof(might_use_tail_padding
) == 32);
242 struct pod_in_11_only
{
247 struct tail_padded_pod_in_11_only
{
248 pod_in_11_only pod11
;
249 pod_in_11_only pod12
;
253 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
{
254 char may_go_into_tail_padding
;
257 SA(0, sizeof(might_use_tail_padding
) == 24);
261 struct pod_in_11_only
{
266 struct tail_padded_pod_in_11_only
{
267 pod_in_11_only pod11
;
271 struct another_layer
{
272 tail_padded_pod_in_11_only pod
;
276 struct might_use_tail_padding
: public another_layer
{
277 char may_go_into_tail_padding
;
280 SA(0, sizeof(might_use_tail_padding
) == 24);
284 struct pod_in_11_only
{
289 struct tail_padded_pod_in_11_only
{
290 pod_in_11_only pod11
;
294 struct another_layer
: tail_padded_pod_in_11_only
{
297 struct might_use_tail_padding
: public another_layer
{
298 char may_go_into_tail_padding
;
301 SA(0, sizeof(might_use_tail_padding
) == 16);
305 struct pod_in_11_only
{
328 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
331 SA(0, sizeof(might_use_tail_padding
) == 32);
335 struct pod_in_11_only
{
363 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
367 SA(0, sizeof(might_use_tail_padding
) == 88);
371 struct pod_in_11_only
{
377 pod_in_11_only a
__attribute__((aligned(128)));
392 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
395 SA(0, sizeof(might_use_tail_padding
) == 128);
399 struct pod_in_11_only
{
421 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
424 SA(0, sizeof(might_use_tail_padding
) == 40);
428 struct pod_in_11_only
{
438 struct might_use_tail_padding
: public A
{
443 SA(0, sizeof(might_use_tail_padding
) == 16);
447 struct pod_in_11_only
{
457 struct might_use_tail_padding
: public A
{
466 SA(0, sizeof(might_use_tail_padding
) == 16);
470 struct pod_in_11_only
{
486 struct C
: public A
, public B
{
489 struct D
: public C
{
492 struct might_use_tail_padding
: public D
{
495 SA(0, sizeof(might_use_tail_padding
) == 40);
499 struct pod_in_11_only
{
505 pod_in_11_only a
__attribute__((aligned(512)));
522 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
525 SA(0, sizeof(might_use_tail_padding
) == 512);
529 struct pod_in_11_only
{
556 struct C
: public A
, public B
{
559 struct D
: public A1
, public B1
{
562 struct E
: public D
, public C
{
565 struct F
: public E
{
568 struct might_use_tail_padding
: public F
{
571 SA(0, sizeof(might_use_tail_padding
) == 80);
573 } // namespace PR16537
576 struct X
{ char c
; };
579 _Static_assert(_Alignof(A
) == _Alignof(int), "");
581 // __attribute__((packed)) does not apply to base classes.
582 struct __attribute__((packed
)) B
: X
, A
{};
583 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 6
584 _Static_assert(_Alignof(B
) == 1, "");
585 _Static_assert(__builtin_offsetof(B
, n
) == 1, "");
587 _Static_assert(_Alignof(B
) == _Alignof(int), "");
588 _Static_assert(__builtin_offsetof(B
, n
) == 4, "");
591 // #pragma pack does, though.
592 #pragma pack(push, 2)
594 _Static_assert(_Alignof(C
) == 2, "");
595 _Static_assert(__builtin_offsetof(C
, n
) == 2, "");
597 struct __attribute__((packed
)) D
: X
, A
{};
598 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 6
599 _Static_assert(_Alignof(D
) == 1, "");
600 _Static_assert(__builtin_offsetof(D
, n
) == 1, "");
602 _Static_assert(_Alignof(D
) == 2, "");
603 _Static_assert(__builtin_offsetof(D
, n
) == 2, "");