1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base -Wno-invalid-offsetof -Wno-c++11-extensions
2 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
4 // RUN: %clang_cc1 -triple x86_64-scei-ps4 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
5 // RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
6 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
7 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
8 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
9 // RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
10 // RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
11 // RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
12 // RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
13 // RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
14 // RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
15 // RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
17 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions -Wno-invalid-offsetof
18 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
19 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-apple-darwin %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
20 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-scei-ps4 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6 -Wno-invalid-offsetof
21 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-sie-ps5 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6 -Wno-invalid-offsetof
22 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6 -Wno-invalid-offsetof
23 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14 -Wno-invalid-offsetof
24 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
25 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple x86_64-unknown-unknown %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16 -Wno-invalid-offsetof
26 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
27 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
28 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
29 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
30 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
31 // RUN: %clang_cc1 -fexperimental-new-constant-interpreter -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15 -Wno-invalid-offsetof
36 // expected-no-diagnostics
38 #if !defined(__MVS__) && !defined(_AIX)
40 #define SA(n, p) int a##n[(p) ? 1 : -1]
47 SA(0, sizeof(A
) == 8);
53 SA(1, sizeof(B
) == 12);
56 // Make fields private so C won't be a POD type.
62 SA(2, sizeof(C
) == 8);
68 SA(3, sizeof(D
) == 8);
70 struct __attribute__((packed
)) E
{
75 SA(4, sizeof(E
) == 5);
77 struct __attribute__((packed
)) F
: E
{
81 SA(5, sizeof(F
) == 6);
86 SA(6, sizeof(H
) == 1);
91 } __attribute__((packed
));
93 SA(6_1
, sizeof(I
) == 5);
98 class A
{ bool iv0
: 1; };
99 SA(7, sizeof(A
) == 1);
101 class B
: A
{ bool iv0
: 1; };
102 SA(8, sizeof(B
) == 2);
104 struct C
{ bool iv0
: 1; };
105 SA(9, sizeof(C
) == 1);
107 struct D
: C
{ bool iv0
: 1; };
108 SA(10, sizeof(D
) == 2);
114 // Test that we don't assert on this hierarchy.
116 struct B
: A
{ virtual void b(); };
117 class C
: virtual A
{ int c
; };
118 struct D
: virtual B
{ };
119 struct E
: C
, virtual D
{ };
120 class F
: virtual E
{ };
121 struct G
: virtual E
, F
{ };
123 SA(0, sizeof(G
) == 24);
129 // Test that this somewhat complex class structure is laid out correctly.
131 struct B
: A
{ virtual void b(); };
132 struct C
: virtual B
{ };
133 struct D
: virtual A
{ };
134 struct E
: virtual B
, D
{ };
135 struct F
: E
, virtual C
{ };
136 struct G
: virtual F
, A
{ };
139 SA(0, sizeof(H
) == 24);
145 struct pod_in_11_only
{
150 struct tail_padded_pod_in_11_only
{
151 pod_in_11_only pod11
;
155 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
{
156 char may_go_into_tail_padding
;
159 SA(0, sizeof(might_use_tail_padding
) == 16);
163 struct pod_in_11_only
{
168 struct tail_padded_pod_in_11_only
{
169 pod_in_11_only pod11
__attribute__((aligned(16)));
172 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
{
173 char may_go_into_tail_padding
;
176 SA(0, sizeof(might_use_tail_padding
) == 16);
180 struct pod_in_11_only
{
185 struct tail_padded_pod_in_11_only
{
186 pod_in_11_only pod11
;
194 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
197 SA(0, sizeof(might_use_tail_padding
) == 16);
201 struct pod_in_11_only
{
206 struct tail_padded_pod_in_11_only
{
207 pod_in_11_only pod11
;
215 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
216 char may_go_into_tail_padding
;
218 SA(0, sizeof(might_use_tail_padding
) == 16);
222 struct pod_in_11_only
{
227 struct pod_in_11_only2
{
232 struct tail_padded_pod_in_11_only
{
233 pod_in_11_only pod11
;
242 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
243 char may_go_into_tail_padding
;
245 SA(0, sizeof(might_use_tail_padding
) == 32);
249 struct pod_in_11_only
{
254 struct pod_in_11_only2
{
259 struct tail_padded_pod_in_11_only
{
260 pod_in_11_only pod11
;
269 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
, public second_base
{
270 char may_go_into_tail_padding
;
272 SA(0, sizeof(might_use_tail_padding
) == 32);
276 struct pod_in_11_only
{
281 struct tail_padded_pod_in_11_only
{
282 pod_in_11_only pod11
;
283 pod_in_11_only pod12
;
287 struct might_use_tail_padding
: public tail_padded_pod_in_11_only
{
288 char may_go_into_tail_padding
;
291 SA(0, sizeof(might_use_tail_padding
) == 24);
295 struct pod_in_11_only
{
300 struct tail_padded_pod_in_11_only
{
301 pod_in_11_only pod11
;
305 struct another_layer
{
306 tail_padded_pod_in_11_only pod
;
310 struct might_use_tail_padding
: public another_layer
{
311 char may_go_into_tail_padding
;
314 SA(0, sizeof(might_use_tail_padding
) == 24);
318 struct pod_in_11_only
{
323 struct tail_padded_pod_in_11_only
{
324 pod_in_11_only pod11
;
328 struct another_layer
: tail_padded_pod_in_11_only
{
331 struct might_use_tail_padding
: public another_layer
{
332 char may_go_into_tail_padding
;
335 SA(0, sizeof(might_use_tail_padding
) == 16);
339 struct pod_in_11_only
{
362 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
365 SA(0, sizeof(might_use_tail_padding
) == 32);
369 struct pod_in_11_only
{
397 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
401 SA(0, sizeof(might_use_tail_padding
) == 88);
405 struct pod_in_11_only
{
411 pod_in_11_only a
__attribute__((aligned(128)));
426 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
429 SA(0, sizeof(might_use_tail_padding
) == 128);
433 struct pod_in_11_only
{
455 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
458 SA(0, sizeof(might_use_tail_padding
) == 40);
462 struct pod_in_11_only
{
472 struct might_use_tail_padding
: public A
{
477 SA(0, sizeof(might_use_tail_padding
) == 16);
481 struct pod_in_11_only
{
491 struct might_use_tail_padding
: public A
{
500 SA(0, sizeof(might_use_tail_padding
) == 16);
504 struct pod_in_11_only
{
520 struct C
: public A
, public B
{
523 struct D
: public C
{
526 struct might_use_tail_padding
: public D
{
529 SA(0, sizeof(might_use_tail_padding
) == 40);
533 struct pod_in_11_only
{
539 pod_in_11_only a
__attribute__((aligned(512)));
556 struct might_use_tail_padding
: public A
, public B
, public C
, public D
{
559 SA(0, sizeof(might_use_tail_padding
) == 512);
563 struct pod_in_11_only
{
590 struct C
: public A
, public B
{
593 struct D
: public A1
, public B1
{
596 struct E
: public D
, public C
{
599 struct F
: public E
{
602 struct might_use_tail_padding
: public F
{
605 SA(0, sizeof(might_use_tail_padding
) == 80);
607 } // namespace PR16537
610 struct X
{ char c
; };
613 _Static_assert(_Alignof(A
) == _Alignof(int), "");
615 // __attribute__((packed)) does not apply to base classes.
616 struct __attribute__((packed
)) B
: X
, A
{};
617 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 6
618 _Static_assert(_Alignof(B
) == 1, "");
619 _Static_assert(__builtin_offsetof(B
, n
) == 1, "");
621 _Static_assert(_Alignof(B
) == _Alignof(int), "");
622 _Static_assert(__builtin_offsetof(B
, n
) == 4, "");
625 // #pragma pack does, though.
626 #pragma pack(push, 2)
628 _Static_assert(_Alignof(C
) == 2, "");
629 _Static_assert(__builtin_offsetof(C
, n
) == 2, "");
631 struct __attribute__((packed
)) D
: X
, A
{};
632 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 6
633 _Static_assert(_Alignof(D
) == 1, "");
634 _Static_assert(__builtin_offsetof(D
, n
) == 1, "");
636 _Static_assert(_Alignof(D
) == 2, "");
637 _Static_assert(__builtin_offsetof(D
, n
) == 2, "");
642 #endif // !defined(__MVS__) && !defined(__AIX__)
649 // GCC prints warning: ignoring packed attribute because of unpacked non-POD field 't1 t2::v1'`
655 } __attribute__((packed
));
656 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15
657 _Static_assert(_Alignof(t1
) == 4, "");
658 _Static_assert(_Alignof(t2
) == 1, "");
660 _Static_assert(_Alignof(t1
) == 4, "");
661 _Static_assert(_Alignof(t2
) == 4, "");
663 _Static_assert(sizeof(t2
) == 8, ""); // it's still packing the rest of the struct
664 } // namespace non_pod
666 namespace non_pod_packed
{
670 } __attribute__((packed
));
673 } __attribute__((packed
));
674 _Static_assert(_Alignof(t1
) == 1, "");
675 _Static_assert(_Alignof(t2
) == 1, "");
676 } // namespace non_pod_packed
678 namespace non_pod_packed_packed
{
683 } __attribute__((packed
));
687 } __attribute__((packed
));
688 _Static_assert(__builtin_offsetof(C
, b
) == 3, "");
691 namespace cxx11_pod
{
694 t1(const t1
&) = delete;
702 } __attribute__((packed
));
703 #if (defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15) || !defined(__MVS__)
704 _Static_assert(_Alignof(t2
) == 1, "");
706 _Static_assert(_Alignof(t2
) == 4, "");
711 #if (defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 15) || defined(__MVS__)
712 _Static_assert(sizeof(t3
) == 8, "");
714 _Static_assert(sizeof(t3
) == 12, "");