xref: /aosp_15_r20/external/clang/test/SemaCXX/ms_struct.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
2*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
3*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_ERROR -verify -triple armv7-apple-darwin9 -std=c++11 %s
4*67e74705SXin Li 
5*67e74705SXin Li #pragma ms_struct on
6*67e74705SXin Li 
7*67e74705SXin Li struct A {
8*67e74705SXin Li   unsigned long a:4;
9*67e74705SXin Li   unsigned char b;
10*67e74705SXin Li };
11*67e74705SXin Li 
12*67e74705SXin Li struct B : public A {
13*67e74705SXin Li #ifdef TEST_FOR_ERROR
14*67e74705SXin Li   // expected-error@-2 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
15*67e74705SXin Li #else
16*67e74705SXin Li   // expected-warning@-4 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
17*67e74705SXin Li #endif
18*67e74705SXin Li   unsigned long c:16;
19*67e74705SXin Li 	int d;
20*67e74705SXin Li   B();
21*67e74705SXin Li };
22*67e74705SXin Li 
23*67e74705SXin Li static_assert(__builtin_offsetof(B, d) == 12,
24*67e74705SXin Li   "We can't allocate the bitfield into the padding under ms_struct");
25*67e74705SXin Li 
26*67e74705SXin Li // rdar://16178895
27*67e74705SXin Li struct C {
28*67e74705SXin Li #ifdef TEST_FOR_ERROR
29*67e74705SXin Li   // expected-error@-2 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
30*67e74705SXin Li #else
31*67e74705SXin Li   // expected-warning@-4 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}}
32*67e74705SXin Li #endif
33*67e74705SXin Li   virtual void foo();
34*67e74705SXin Li   long long n;
35*67e74705SXin Li };
36*67e74705SXin Li 
37*67e74705SXin Li static_assert(__builtin_offsetof(C, n) == 8,
38*67e74705SXin Li               "long long field in ms_struct should be 8-byte aligned");
39