aboutsummaryrefslogtreecommitdiff
path: root/test/CodeGenCXX/rtti-layout.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-12-30 23:47:56 +0000
committerAnders Carlsson <andersca@mac.com>2009-12-30 23:47:56 +0000
commit0814809e5bc27cccd59b63e99ab1eb52042dc13c (patch)
treeaa2bda7284ff4c7a5c256db2130ce90015134286 /test/CodeGenCXX/rtti-layout.cpp
parenta8c6c448c9d3b09efdaf05023427bb8baafcc9dc (diff)
Fix a bunch of bugs with VMI RTTI building, and add a whole bunch of tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92319 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/rtti-layout.cpp')
-rw-r--r--test/CodeGenCXX/rtti-layout.cpp71
1 files changed, 67 insertions, 4 deletions
diff --git a/test/CodeGenCXX/rtti-layout.cpp b/test/CodeGenCXX/rtti-layout.cpp
index 6b3b26747f..1ad87fbc7e 100644
--- a/test/CodeGenCXX/rtti-layout.cpp
+++ b/test/CodeGenCXX/rtti-layout.cpp
@@ -38,6 +38,30 @@ public:
const __class_type_info *__base_type;
};
+struct __base_class_type_info {
+public:
+ const __class_type_info *__base_type;
+ long __offset_flags;
+
+ enum __offset_flags_masks {
+ __virtual_mask = 0x1,
+ __public_mask = 0x2,
+ __offset_shift = 8
+ };
+};
+
+class __vmi_class_type_info : public __class_type_info {
+public:
+ unsigned int __flags;
+ unsigned int __base_count;
+ __base_class_type_info __base_info[1];
+
+ enum __flags_masks {
+ __non_diamond_repeat_mask = 0x1,
+ __diamond_shaped_mask = 0x2
+ };
+};
+
template<typename T> const T& to(const std::type_info &info) {
return static_cast<const T&>(info);
}
@@ -55,8 +79,19 @@ struct VMI2 : virtual A { };
struct VMI3 : A { virtual void f() { } };
struct VMI4 : A, Empty { };
+struct VMIBase1 { int a; };
+struct VMIBase2 : VMIBase1 { int a; };
+struct VMI5 : VMIBase1, VMIBase2 { int a; };
+
+struct VMIBase3 : virtual VMIBase1 { int a; };
+struct VMI6 : virtual VMIBase1, VMIBase3 { int a; };
+
+struct VMI7 : VMIBase1, VMI5, private VMI6 { };
+
#define CHECK(x) if (!(x)) return __LINE__
-#define CHECK_VTABLE(type, vtable) if (&vtable##_type_info_vtable + 2 != (((void **)&(typeid(type)))[0])) return __LINE__
+#define CHECK_VTABLE(type, vtable) CHECK(&vtable##_type_info_vtable + 2 == (((void **)&(typeid(type)))[0]))
+#define CHECK_BASE_INFO_TYPE(type, index, base) CHECK(to<__vmi_class_type_info>(typeid(type)).__base_info[(index)].__base_type == &typeid(base))
+#define CHECK_BASE_INFO_OFFSET_FLAGS(type, index, offset, flags) CHECK(to<__vmi_class_type_info>(typeid(type)).__base_info[(index)].__offset_flags == (((offset) << 8) | (flags)))
// CHECK: define i32 @_Z1fv()
int f() {
@@ -69,13 +104,16 @@ int f() {
// SI1 has a single public base.
CHECK_VTABLE(SI1, si_class);
+ CHECK(to<__si_class_type_info>(typeid(SI1)).__base_type == &typeid(A));
// SI2 has a single public empty base.
CHECK_VTABLE(SI2, si_class);
+ CHECK(to<__si_class_type_info>(typeid(SI2)).__base_type == &typeid(Empty));
// SI3 has a single public empty base. SI3 is dynamic whereas Empty is not, but since Empty is
// an empty class, it will still be at offset zero.
CHECK_VTABLE(SI3, si_class);
+ CHECK(to<__si_class_type_info>(typeid(SI3)).__base_type == &typeid(Empty));
// VMI1 has a single base, but it is private.
CHECK_VTABLE(VMI1, vmi_class);
@@ -88,10 +126,35 @@ int f() {
// VMI4 has two bases.
CHECK_VTABLE(VMI4, vmi_class);
+
+ // VMI5 has non-diamond shaped inheritance.
+ CHECK_VTABLE(VMI5, vmi_class);
+ CHECK(to<__vmi_class_type_info>(typeid(VMI5)).__flags == __vmi_class_type_info::__non_diamond_repeat_mask);
+ CHECK(to<__vmi_class_type_info>(typeid(VMI5)).__base_count == 2);
+ CHECK_BASE_INFO_TYPE(VMI5, 0, VMIBase1);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI5, 0, 0, __base_class_type_info::__public_mask);
+ CHECK_BASE_INFO_TYPE(VMI5, 1, VMIBase2);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI5, 1, 4, __base_class_type_info::__public_mask);
- CHECK(to<__si_class_type_info>(typeid(SI1)).__base_type == &typeid(A));
- CHECK(to<__si_class_type_info>(typeid(SI2)).__base_type == &typeid(Empty));
- CHECK(to<__si_class_type_info>(typeid(SI3)).__base_type == &typeid(Empty));
+ // VMI6 has diamond shaped inheritance.
+ CHECK_VTABLE(VMI6, vmi_class);
+ CHECK(to<__vmi_class_type_info>(typeid(VMI6)).__flags == __vmi_class_type_info::__diamond_shaped_mask);
+ CHECK(to<__vmi_class_type_info>(typeid(VMI6)).__base_count == 2);
+ CHECK_BASE_INFO_TYPE(VMI6, 0, VMIBase1);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI6, 0, -24, __base_class_type_info::__public_mask | __base_class_type_info::__virtual_mask);
+ CHECK_BASE_INFO_TYPE(VMI6, 1, VMIBase3);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI6, 1, 0, __base_class_type_info::__public_mask);
+
+ // VMI7 has both non-diamond and diamond shaped inheritance.
+ CHECK_VTABLE(VMI7, vmi_class);
+ CHECK(to<__vmi_class_type_info>(typeid(VMI7)).__flags == (__vmi_class_type_info::__non_diamond_repeat_mask | __vmi_class_type_info::__diamond_shaped_mask));
+ CHECK(to<__vmi_class_type_info>(typeid(VMI7)).__base_count == 3);
+ CHECK_BASE_INFO_TYPE(VMI7, 0, VMIBase1);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI7, 0, 16, __base_class_type_info::__public_mask);
+ CHECK_BASE_INFO_TYPE(VMI7, 1, VMI5);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI7, 1, 20, __base_class_type_info::__public_mask);
+ CHECK_BASE_INFO_TYPE(VMI7, 2, VMI6);
+ CHECK_BASE_INFO_OFFSET_FLAGS(VMI7, 2, 0, 0);
// Pointers to incomplete classes.
CHECK_VTABLE(Incomplete *, pointer);