John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 1 | // 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 Friedman | 2782dac | 2013-06-26 20:50:34 +0000 | [diff] [blame] | 4 | |
| 5 | #pragma ms_struct on |
| 6 | |
| 7 | struct A { |
| 8 | unsigned long a:4; |
| 9 | unsigned char b; |
Eli Friedman | 2782dac | 2013-06-26 20:50:34 +0000 | [diff] [blame] | 10 | }; |
| 11 | |
| 12 | struct B : public A { |
John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 13 | #ifdef TEST_FOR_ERROR |
Nico Weber | 5672e67 | 2015-07-28 16:48:12 +0000 | [diff] [blame] | 14 | // expected-error@-2 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}} |
John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 15 | #else |
Nico Weber | 5672e67 | 2015-07-28 16:48:12 +0000 | [diff] [blame] | 16 | // expected-warning@-4 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}} |
John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 17 | #endif |
Eli Friedman | 2782dac | 2013-06-26 20:50:34 +0000 | [diff] [blame] | 18 | unsigned long c:16; |
| 19 | int d; |
| 20 | B(); |
| 21 | }; |
| 22 | |
| 23 | static_assert(__builtin_offsetof(B, d) == 12, |
John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 24 | "We can't allocate the bitfield into the padding under ms_struct"); |
| 25 | |
| 26 | // rdar://16178895 |
| 27 | struct C { |
| 28 | #ifdef TEST_FOR_ERROR |
Nico Weber | 5672e67 | 2015-07-28 16:48:12 +0000 | [diff] [blame] | 29 | // expected-error@-2 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}} |
John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 30 | #else |
Nico Weber | 5672e67 | 2015-07-28 16:48:12 +0000 | [diff] [blame] | 31 | // expected-warning@-4 {{ms_struct may not produce Microsoft-compatible layouts for classes with base classes or virtual functions}} |
John McCall | 95833f3 | 2014-02-27 20:30:49 +0000 | [diff] [blame] | 32 | #endif |
| 33 | virtual void foo(); |
| 34 | long long n; |
| 35 | }; |
| 36 | |
| 37 | static_assert(__builtin_offsetof(C, n) == 8, |
| 38 | "long long field in ms_struct should be 8-byte aligned"); |