summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/ms_struct.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2014-02-27 20:30:49 +0000
committerJohn McCall <rjmccall@apple.com>2014-02-27 20:30:49 +0000
commit95833f33bda6c92e746e0b0007b69c2c30bfc693 (patch)
tree3f0dd01a6f42e90cd650d1d1be1e4c0bf8e9d1fe /clang/test/SemaCXX/ms_struct.cpp
parentd6efa2a9775790b8662393a9f9634516b647e091 (diff)
downloadbcm5719-llvm-95833f33bda6c92e746e0b0007b69c2c30bfc693.tar.gz
bcm5719-llvm-95833f33bda6c92e746e0b0007b69c2c30bfc693.zip
Diagnose attempts to apply ms_struct to records with base classes
or virtual functions, but permit that error to be downgraded to a warning (with -Wno-error=incompatible-ms-struct), and officially support this kind of dual, ABI-mixing layout. The basic problem here is that projects which use ms_struct are often not very circumspect about what types they annotate; for example, some projects enable the pragma in a prefix header and then only selectively disable it around system header inclusions. They may only care about binary compatibility with MSVC for a subset of those structs, but that doesn't mean they have no binary compatibility concerns at all for the rest; thus we are essentially forced into supporting this hybrid ABI. But it's reasonable for us to at least point out the places where we're not making any guarantees. The original diagnostic was for dynamic classes, i.e. those with virtual functions or virtual bases; I've extended it to include all classes with bases, because we are not actually making any attempt to duplicate MSVC's base subobject layout in ms_struct (and it is indeed quite different from Itanium, even for non-virtual bases). rdar://16178895 llvm-svn: 202427
Diffstat (limited to 'clang/test/SemaCXX/ms_struct.cpp')
-rw-r--r--clang/test/SemaCXX/ms_struct.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/clang/test/SemaCXX/ms_struct.cpp b/clang/test/SemaCXX/ms_struct.cpp
index 37fa9a7c687..2832b5620f3 100644
--- a/clang/test/SemaCXX/ms_struct.cpp
+++ b/clang/test/SemaCXX/ms_struct.cpp
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-apple-darwin9 -std=c++11 %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple i686-apple-darwin9 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -Wno-error=incompatible-ms-struct -verify -triple armv7-apple-darwin9 -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -DTEST_FOR_ERROR -verify -triple armv7-apple-darwin9 -std=c++11 %s
#pragma ms_struct on
@@ -9,10 +10,29 @@ struct A {
};
struct B : public A {
+#ifdef TEST_FOR_ERROR
+ // expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
+#else
+ // expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
+#endif
unsigned long c:16;
int d;
B();
};
static_assert(__builtin_offsetof(B, d) == 12,
- "We can't allocate the bitfield into the padding under ms_struct"); \ No newline at end of file
+ "We can't allocate the bitfield into the padding under ms_struct");
+
+// rdar://16178895
+struct C {
+#ifdef TEST_FOR_ERROR
+ // expected-error@-2 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
+#else
+ // expected-warning@-4 {{ms_struct may not produce MSVC-compatible layouts for classes with base classes or virtual functions}}
+#endif
+ virtual void foo();
+ long long n;
+};
+
+static_assert(__builtin_offsetof(C, n) == 8,
+ "long long field in ms_struct should be 8-byte aligned");
OpenPOWER on IntegriCloud