annotate clang/test/CodeGenCXX/rtti-layout.cpp @ 206:f17a3b42b08b

Added tag before-12 for changeset b7591485f4cd
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 07 Jun 2021 21:25:57 +0900 (2021-06-07)
parents 1d019706d866
children 2e18cbf3894f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
anatofuz
parents:
diff changeset
2 #include <typeinfo>
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 // vtables.
anatofuz
parents:
diff changeset
5 extern "C" {
anatofuz
parents:
diff changeset
6 const void *_ZTVN10__cxxabiv123__fundamental_type_infoE;
anatofuz
parents:
diff changeset
7 const void *_ZTVN10__cxxabiv117__class_type_infoE;
anatofuz
parents:
diff changeset
8 const void *_ZTVN10__cxxabiv120__si_class_type_infoE;
anatofuz
parents:
diff changeset
9 const void *_ZTVN10__cxxabiv121__vmi_class_type_infoE;
anatofuz
parents:
diff changeset
10 const void *_ZTVN10__cxxabiv119__pointer_type_infoE;
anatofuz
parents:
diff changeset
11 const void *_ZTVN10__cxxabiv129__pointer_to_member_type_infoE;
anatofuz
parents:
diff changeset
12 };
anatofuz
parents:
diff changeset
13 #define fundamental_type_info_vtable _ZTVN10__cxxabiv123__fundamental_type_infoE
anatofuz
parents:
diff changeset
14 #define class_type_info_vtable _ZTVN10__cxxabiv117__class_type_infoE
anatofuz
parents:
diff changeset
15 #define si_class_type_info_vtable _ZTVN10__cxxabiv120__si_class_type_infoE
anatofuz
parents:
diff changeset
16 #define vmi_class_type_info_vtable _ZTVN10__cxxabiv121__vmi_class_type_infoE
anatofuz
parents:
diff changeset
17 #define pointer_type_info_vtable _ZTVN10__cxxabiv119__pointer_type_infoE
anatofuz
parents:
diff changeset
18 #define pointer_to_member_type_info_vtable _ZTVN10__cxxabiv129__pointer_to_member_type_infoE
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20 class __pbase_type_info : public std::type_info {
anatofuz
parents:
diff changeset
21 public:
anatofuz
parents:
diff changeset
22 unsigned int __flags;
anatofuz
parents:
diff changeset
23 const std::type_info *__pointee;
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 enum __masks {
anatofuz
parents:
diff changeset
26 __const_mask = 0x1,
anatofuz
parents:
diff changeset
27 __volatile_mask = 0x2,
anatofuz
parents:
diff changeset
28 __restrict_mask = 0x4,
anatofuz
parents:
diff changeset
29 __incomplete_mask = 0x8,
anatofuz
parents:
diff changeset
30 __incomplete_class_mask = 0x10
anatofuz
parents:
diff changeset
31 };
anatofuz
parents:
diff changeset
32 };
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 class __class_type_info : public std::type_info { };
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 class __si_class_type_info : public __class_type_info {
anatofuz
parents:
diff changeset
37 public:
anatofuz
parents:
diff changeset
38 const __class_type_info *__base_type;
anatofuz
parents:
diff changeset
39 };
anatofuz
parents:
diff changeset
40
anatofuz
parents:
diff changeset
41 struct __base_class_type_info {
anatofuz
parents:
diff changeset
42 public:
anatofuz
parents:
diff changeset
43 const __class_type_info *__base_type;
anatofuz
parents:
diff changeset
44 long __offset_flags;
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 enum __offset_flags_masks {
anatofuz
parents:
diff changeset
47 __virtual_mask = 0x1,
anatofuz
parents:
diff changeset
48 __public_mask = 0x2,
anatofuz
parents:
diff changeset
49 __offset_shift = 8
anatofuz
parents:
diff changeset
50 };
anatofuz
parents:
diff changeset
51 };
anatofuz
parents:
diff changeset
52
anatofuz
parents:
diff changeset
53 class __vmi_class_type_info : public __class_type_info {
anatofuz
parents:
diff changeset
54 public:
anatofuz
parents:
diff changeset
55 unsigned int __flags;
anatofuz
parents:
diff changeset
56 unsigned int __base_count;
anatofuz
parents:
diff changeset
57 __base_class_type_info __base_info[1];
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59 enum __flags_masks {
anatofuz
parents:
diff changeset
60 __non_diamond_repeat_mask = 0x1,
anatofuz
parents:
diff changeset
61 __diamond_shaped_mask = 0x2
anatofuz
parents:
diff changeset
62 };
anatofuz
parents:
diff changeset
63 };
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 template<typename T> const T& to(const std::type_info &info) {
anatofuz
parents:
diff changeset
66 return static_cast<const T&>(info);
anatofuz
parents:
diff changeset
67 }
anatofuz
parents:
diff changeset
68 struct Incomplete;
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 struct A { int a; };
anatofuz
parents:
diff changeset
71 struct Empty { };
anatofuz
parents:
diff changeset
72
anatofuz
parents:
diff changeset
73 struct SI1 : A { };
anatofuz
parents:
diff changeset
74 struct SI2 : Empty { };
anatofuz
parents:
diff changeset
75 struct SI3 : Empty { virtual void f() { } };
anatofuz
parents:
diff changeset
76
anatofuz
parents:
diff changeset
77 struct VMI1 : private A { };
anatofuz
parents:
diff changeset
78 struct VMI2 : virtual A { };
anatofuz
parents:
diff changeset
79 struct VMI3 : A { virtual void f() { } };
anatofuz
parents:
diff changeset
80 struct VMI4 : A, Empty { };
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82 struct VMIBase1 { int a; };
anatofuz
parents:
diff changeset
83 struct VMIBase2 : VMIBase1 { int a; };
anatofuz
parents:
diff changeset
84 struct VMI5 : VMIBase1, VMIBase2 { int a; };
anatofuz
parents:
diff changeset
85
anatofuz
parents:
diff changeset
86 struct VMIBase3 : virtual VMIBase1 { int a; };
anatofuz
parents:
diff changeset
87 struct VMI6 : virtual VMIBase1, VMIBase3 { int a; };
anatofuz
parents:
diff changeset
88
anatofuz
parents:
diff changeset
89 struct VMI7 : VMIBase1, VMI5, private VMI6 { };
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 #define CHECK(x) if (!(x)) return __LINE__
anatofuz
parents:
diff changeset
92 #define CHECK_VTABLE(type, vtable) CHECK(&vtable##_type_info_vtable + 2 == (((void **)&(typeid(type)))[0]))
anatofuz
parents:
diff changeset
93 #define CHECK_BASE_INFO_TYPE(type, index, base) CHECK(to<__vmi_class_type_info>(typeid(type)).__base_info[(index)].__base_type == &typeid(base))
anatofuz
parents:
diff changeset
94 #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)))
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 struct B {
anatofuz
parents:
diff changeset
97 static int const volatile (*a)[10];
anatofuz
parents:
diff changeset
98 static int (*b)[10];
anatofuz
parents:
diff changeset
99
anatofuz
parents:
diff changeset
100 static int const volatile (B::*c)[10];
anatofuz
parents:
diff changeset
101 static int (B::*d)[10];
anatofuz
parents:
diff changeset
102 };
anatofuz
parents:
diff changeset
103
anatofuz
parents:
diff changeset
104 // CHECK-LABEL: define i32 @_Z1fv()
anatofuz
parents:
diff changeset
105 int f() {
anatofuz
parents:
diff changeset
106 // Vectors should be treated as fundamental types.
anatofuz
parents:
diff changeset
107 typedef short __v4hi __attribute__ ((__vector_size__ (8)));
anatofuz
parents:
diff changeset
108 CHECK_VTABLE(__v4hi, fundamental);
anatofuz
parents:
diff changeset
109
anatofuz
parents:
diff changeset
110 // A does not have any bases.
anatofuz
parents:
diff changeset
111 CHECK_VTABLE(A, class);
anatofuz
parents:
diff changeset
112
anatofuz
parents:
diff changeset
113 // SI1 has a single public base.
anatofuz
parents:
diff changeset
114 CHECK_VTABLE(SI1, si_class);
anatofuz
parents:
diff changeset
115 CHECK(to<__si_class_type_info>(typeid(SI1)).__base_type == &typeid(A));
anatofuz
parents:
diff changeset
116
anatofuz
parents:
diff changeset
117 // SI2 has a single public empty base.
anatofuz
parents:
diff changeset
118 CHECK_VTABLE(SI2, si_class);
anatofuz
parents:
diff changeset
119 CHECK(to<__si_class_type_info>(typeid(SI2)).__base_type == &typeid(Empty));
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 // SI3 has a single public empty base. SI3 is dynamic whereas Empty is not, but since Empty is
anatofuz
parents:
diff changeset
122 // an empty class, it will still be at offset zero.
anatofuz
parents:
diff changeset
123 CHECK_VTABLE(SI3, si_class);
anatofuz
parents:
diff changeset
124 CHECK(to<__si_class_type_info>(typeid(SI3)).__base_type == &typeid(Empty));
anatofuz
parents:
diff changeset
125
anatofuz
parents:
diff changeset
126 // VMI1 has a single base, but it is private.
anatofuz
parents:
diff changeset
127 CHECK_VTABLE(VMI1, vmi_class);
anatofuz
parents:
diff changeset
128
anatofuz
parents:
diff changeset
129 // VMI2 has a single base, but it is virtual.
anatofuz
parents:
diff changeset
130 CHECK_VTABLE(VMI2, vmi_class);
anatofuz
parents:
diff changeset
131
anatofuz
parents:
diff changeset
132 // VMI3 has a single base, but VMI3 is dynamic whereas A is not, and A is not empty.
anatofuz
parents:
diff changeset
133 CHECK_VTABLE(VMI3, vmi_class);
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 // VMI4 has two bases.
anatofuz
parents:
diff changeset
136 CHECK_VTABLE(VMI4, vmi_class);
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 // VMI5 has non-diamond shaped inheritance.
anatofuz
parents:
diff changeset
139 CHECK_VTABLE(VMI5, vmi_class);
anatofuz
parents:
diff changeset
140 CHECK(to<__vmi_class_type_info>(typeid(VMI5)).__flags == __vmi_class_type_info::__non_diamond_repeat_mask);
anatofuz
parents:
diff changeset
141 CHECK(to<__vmi_class_type_info>(typeid(VMI5)).__base_count == 2);
anatofuz
parents:
diff changeset
142 CHECK_BASE_INFO_TYPE(VMI5, 0, VMIBase1);
anatofuz
parents:
diff changeset
143 CHECK_BASE_INFO_OFFSET_FLAGS(VMI5, 0, 0, __base_class_type_info::__public_mask);
anatofuz
parents:
diff changeset
144 CHECK_BASE_INFO_TYPE(VMI5, 1, VMIBase2);
anatofuz
parents:
diff changeset
145 CHECK_BASE_INFO_OFFSET_FLAGS(VMI5, 1, 4, __base_class_type_info::__public_mask);
anatofuz
parents:
diff changeset
146
anatofuz
parents:
diff changeset
147 // VMI6 has diamond shaped inheritance.
anatofuz
parents:
diff changeset
148 CHECK_VTABLE(VMI6, vmi_class);
anatofuz
parents:
diff changeset
149 CHECK(to<__vmi_class_type_info>(typeid(VMI6)).__flags == __vmi_class_type_info::__diamond_shaped_mask);
anatofuz
parents:
diff changeset
150 CHECK(to<__vmi_class_type_info>(typeid(VMI6)).__base_count == 2);
anatofuz
parents:
diff changeset
151 CHECK_BASE_INFO_TYPE(VMI6, 0, VMIBase1);
anatofuz
parents:
diff changeset
152 CHECK_BASE_INFO_OFFSET_FLAGS(VMI6, 0, -24, __base_class_type_info::__public_mask | __base_class_type_info::__virtual_mask);
anatofuz
parents:
diff changeset
153 CHECK_BASE_INFO_TYPE(VMI6, 1, VMIBase3);
anatofuz
parents:
diff changeset
154 CHECK_BASE_INFO_OFFSET_FLAGS(VMI6, 1, 0, __base_class_type_info::__public_mask);
anatofuz
parents:
diff changeset
155
anatofuz
parents:
diff changeset
156 // VMI7 has both non-diamond and diamond shaped inheritance.
anatofuz
parents:
diff changeset
157 CHECK_VTABLE(VMI7, vmi_class);
anatofuz
parents:
diff changeset
158 CHECK(to<__vmi_class_type_info>(typeid(VMI7)).__flags == (__vmi_class_type_info::__non_diamond_repeat_mask | __vmi_class_type_info::__diamond_shaped_mask));
anatofuz
parents:
diff changeset
159 CHECK(to<__vmi_class_type_info>(typeid(VMI7)).__base_count == 3);
anatofuz
parents:
diff changeset
160 CHECK_BASE_INFO_TYPE(VMI7, 0, VMIBase1);
anatofuz
parents:
diff changeset
161 CHECK_BASE_INFO_OFFSET_FLAGS(VMI7, 0, 16, __base_class_type_info::__public_mask);
anatofuz
parents:
diff changeset
162 CHECK_BASE_INFO_TYPE(VMI7, 1, VMI5);
anatofuz
parents:
diff changeset
163 CHECK_BASE_INFO_OFFSET_FLAGS(VMI7, 1, 20, __base_class_type_info::__public_mask);
anatofuz
parents:
diff changeset
164 CHECK_BASE_INFO_TYPE(VMI7, 2, VMI6);
anatofuz
parents:
diff changeset
165 CHECK_BASE_INFO_OFFSET_FLAGS(VMI7, 2, 0, 0);
anatofuz
parents:
diff changeset
166
anatofuz
parents:
diff changeset
167 // Pointers to incomplete classes.
anatofuz
parents:
diff changeset
168 CHECK_VTABLE(Incomplete *, pointer);
anatofuz
parents:
diff changeset
169 CHECK(to<__pbase_type_info>(typeid(Incomplete *)).__flags == __pbase_type_info::__incomplete_mask);
anatofuz
parents:
diff changeset
170 CHECK(to<__pbase_type_info>(typeid(Incomplete **)).__flags == __pbase_type_info::__incomplete_mask);
anatofuz
parents:
diff changeset
171 CHECK(to<__pbase_type_info>(typeid(Incomplete ***)).__flags == __pbase_type_info::__incomplete_mask);
anatofuz
parents:
diff changeset
172
anatofuz
parents:
diff changeset
173 // Member pointers.
anatofuz
parents:
diff changeset
174 CHECK_VTABLE(int Incomplete::*, pointer_to_member);
anatofuz
parents:
diff changeset
175 CHECK(to<__pbase_type_info>(typeid(int Incomplete::*)).__flags == __pbase_type_info::__incomplete_class_mask);
anatofuz
parents:
diff changeset
176 CHECK(to<__pbase_type_info>(typeid(Incomplete Incomplete::*)).__flags == (__pbase_type_info::__incomplete_class_mask | __pbase_type_info::__incomplete_mask));
anatofuz
parents:
diff changeset
177 CHECK(to<__pbase_type_info>(typeid(Incomplete A::*)).__flags == (__pbase_type_info::__incomplete_mask));
anatofuz
parents:
diff changeset
178
anatofuz
parents:
diff changeset
179 // Check that when stripping qualifiers off the pointee type, we correctly handle arrays.
anatofuz
parents:
diff changeset
180 CHECK(to<__pbase_type_info>(typeid(B::a)).__flags == (__pbase_type_info::__const_mask | __pbase_type_info::__volatile_mask));
anatofuz
parents:
diff changeset
181 CHECK(to<__pbase_type_info>(typeid(B::a)).__pointee == to<__pbase_type_info>(typeid(B::b)).__pointee);
anatofuz
parents:
diff changeset
182 CHECK(to<__pbase_type_info>(typeid(B::c)).__flags == (__pbase_type_info::__const_mask | __pbase_type_info::__volatile_mask));
anatofuz
parents:
diff changeset
183 CHECK(to<__pbase_type_info>(typeid(B::c)).__pointee == to<__pbase_type_info>(typeid(B::d)).__pointee);
anatofuz
parents:
diff changeset
184
anatofuz
parents:
diff changeset
185 // Success!
anatofuz
parents:
diff changeset
186 // CHECK: ret i32 0
anatofuz
parents:
diff changeset
187 return 0;
anatofuz
parents:
diff changeset
188 }
anatofuz
parents:
diff changeset
189
anatofuz
parents:
diff changeset
190 #ifdef HARNESS
anatofuz
parents:
diff changeset
191 extern "C" void printf(const char *, ...);
anatofuz
parents:
diff changeset
192
anatofuz
parents:
diff changeset
193 int main() {
anatofuz
parents:
diff changeset
194 int result = f();
anatofuz
parents:
diff changeset
195
anatofuz
parents:
diff changeset
196 if (result == 0)
anatofuz
parents:
diff changeset
197 printf("success!\n");
anatofuz
parents:
diff changeset
198 else
anatofuz
parents:
diff changeset
199 printf("test on line %d failed!\n", result);
anatofuz
parents:
diff changeset
200
anatofuz
parents:
diff changeset
201 return result;
anatofuz
parents:
diff changeset
202 }
anatofuz
parents:
diff changeset
203 #endif
anatofuz
parents:
diff changeset
204
anatofuz
parents:
diff changeset
205