blob: 2832b5620f3b6f6e22bcbd9ed5ddf010effd84ac [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
2// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
3// RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_ERROR -verify -triple armv7-apple-darwin9 -std=c++11 %s
Eli Friedmancd06f262013-06-26 20:50:34 +00004
5#pragma ms_struct on
6
7struct A {
8 unsigned long a:4;
9 unsigned char b;
Eli Friedmancd06f262013-06-26 20:50:34 +000010};
11
12struct B : public A {
Stephen Hines651f13c2014-04-23 16:59:28 -070013#ifdef TEST_FOR_ERROR
14 // expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
15#else
16 // expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
17#endif
Eli Friedmancd06f262013-06-26 20:50:34 +000018 unsigned long c:16;
19 int d;
20 B();
21};
22
23static_assert(__builtin_offsetof(B, d) == 12,
Stephen Hines651f13c2014-04-23 16:59:28 -070024 "We can't allocate the bitfield into the padding under ms_struct");
25
26// rdar://16178895
27struct C {
28#ifdef TEST_FOR_ERROR
29 // expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
30#else
31 // expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
32#endif
33 virtual void foo();
34 long long n;
35};
36
37static_assert(__builtin_offsetof(C, n) == 8,
38 "long long field in ms_struct should be 8-byte aligned");