Debian Codegraph @

clang/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp

raw
1 // RUN: %clang_cc1 %s -fno-rtti -std=c++11 -Wno-inaccessible-base -triple=i386-pc-win32 -emit-llvm -o %t
2 // RUN: FileCheck %s < %t
3 // RUN: FileCheck --check-prefix=CHECK2 %s < %t
4
5 // For now, just make sure x86_64 doesn't crash.
6 // RUN: %clang_cc1 %s -fno-rtti -std=c++11 -Wno-inaccessible-base -triple=x86_64-pc-win32 -emit-llvm -o %t
7
8 struct VBase {
9 virtual ~VBase();
10 virtual void foo();
11 virtual void bar();
12 int field;
13 };
14
15 struct B : virtual VBase {
16 B();
17 virtual ~B();
18 virtual void foo();
19 virtual void bar();
20 };
21
22 B::B() {
23 // CHECK-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0B@@QAE@XZ"
24 // CHECK: %[[THIS:.*]] = load ptr, ptr
25 // CHECK: br i1 %{{.*}}, label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
26
27 // Don't check the INIT_VBASES case as it's covered by the ctor tests.
28
29 // CHECK: %[[SKIP_VBASES]]
30 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 0
31 // ...
32 // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 %{{.*}}
33 // CHECK: store ptr @"??_7B@@6B@", ptr %[[VFPTR_i8]]
34
35 // Initialize vtorDisp:
36 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 0
37 // ...
38 // CHECK: %[[VBASE_OFFSET:.*]] = add nsw i32 0, %{{.*}}
39 // CHECK: %[[VTORDISP_VAL:.*]] = sub i32 %[[VBASE_OFFSET]], 8
40 // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 %[[VBASE_OFFSET]]
41 // CHECK: %[[VTORDISP_i8:.*]] = getelementptr i8, ptr %[[VBASE_i8]], i32 -4
42 // CHECK: store i32 %[[VTORDISP_VAL]], ptr %[[VTORDISP_i8]]
43
44 // CHECK: ret
45 }
46
47 B::~B() {
48 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1B@@UAE@XZ"
49 // Store initial this:
50 // CHECK: %[[THIS_ADDR:.*]] = alloca ptr
51 // CHECK: store ptr %{{.*}}, ptr %[[THIS_ADDR]], align 4
52 // Reload and adjust the this parameter:
53 // CHECK: %[[THIS_RELOAD:.*]] = load ptr, ptr %[[THIS_ADDR]]
54 // CHECK: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -8
55
56 // Restore the vfptr that could have been changed by a subclass.
57 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 0
58 // ...
59 // CHECK: %[[VFPTR_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 %{{.*}}
60 // CHECK: store ptr @"??_7B@@6B@", ptr %[[VFPTR_i8]]
61
62 // Initialize vtorDisp:
63 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 0
64 // ...
65 // CHECK: %[[VBASE_OFFSET:.*]] = add nsw i32 0, %{{.*}}
66 // CHECK: %[[VTORDISP_VAL:.*]] = sub i32 %[[VBASE_OFFSET]], 8
67 // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 %[[VBASE_OFFSET]]
68 // CHECK: %[[VTORDISP_i8:.*]] = getelementptr i8, ptr %[[VBASE_i8]], i32 -4
69 // CHECK: store i32 %[[VTORDISP_VAL]], ptr %[[VTORDISP_i8]]
70
71 foo(); // Avoid the "trivial destructor" optimization.
72
73 // CHECK: ret
74
75 // CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc void @"??_DB@@QAEXXZ"(ptr
76 // CHECK2: %[[THIS:.*]] = load ptr, ptr {{.*}}
77 // CHECK2: %[[B_i8:.*]] = getelementptr i8, ptr %[[THIS]], i32 8
78 // CHECK2: call x86_thiscallcc void @"??1B@@UAE@XZ"(ptr{{[^,]*}} %[[B_i8]])
79 // CHECK2: %[[VBASE_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 8
80 // CHECK2: call x86_thiscallcc void @"??1VBase@@UAE@XZ"(ptr {{[^,]*}} %[[VBASE_i8]])
81 // CHECK2: ret
82
83 // CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??0B@test2@@QAE@XZ"
84 // CHECK2: (ptr {{[^,]*}} returned align 4 dereferenceable(4) %this, i32 noundef %is_most_derived)
85 // CHECK2: call x86_thiscallcc noundef ptr @"??0A@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}})
86 // CHECK2: ret
87
88 // CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_GD@pr36921@@UAEPAXI@Z"(
89 // CHECK2: %[[THIS_RELOAD:.*]] = load ptr, ptr
90 // CHECK2: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -4
91
92 // CHECK2-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??_GB@@UAEPAXI@Z"
93 // CHECK2: store ptr %{{.*}}, ptr %[[THIS_ADDR:.*]], align 4
94 // CHECK2: %[[THIS_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_PARAM_i8:.*]], i32 -8
95 // CHECK2: call x86_thiscallcc void @"??_DB@@QAEXXZ"(ptr {{[^,]*}} %[[THIS_i8]])
96 // ...
97 // CHECK2: ret
98 }
99
100 void B::foo() {
101 // CHECK-LABEL: define dso_local x86_thiscallcc void @"?foo@B@@UAEXXZ"(ptr
102 //
103 // B::foo gets 'this' cast to VBase* in ECX (i.e. this+8) so we
104 // need to adjust 'this' before use.
105 //
106 // Coerce this to correct type:
107 // CHECK: %[[THIS_ADDR:.*]] = alloca ptr
108 //
109 // Store initial this:
110 // CHECK: store ptr {{.*}}, ptr %[[THIS_ADDR]], align 4
111 //
112 // Reload and adjust the this parameter:
113 // CHECK: %[[THIS_RELOAD:.*]] = load ptr, ptr %[[THIS_ADDR]]
114 // CHECK: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -8
115
116 field = 42;
117 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 0
118 // CHECK: %[[VBTABLE:.*]] = load ptr, ptr %[[VBPTR]]
119 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, ptr %[[VBTABLE]], i32 1
120 // CHECK: %[[VBOFFSET32:.*]] = load i32, ptr %[[VBENTRY]]
121 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
122 // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 %[[VBOFFSET]]
123 // CHECK: %[[FIELD:.*]] = getelementptr inbounds nuw %struct.VBase, ptr %[[VBASE_i8]], i32 0, i32 1
124 // CHECK: store i32 42, ptr %[[FIELD]], align 4
125 //
126 // CHECK: ret void
127 }
128
129 void call_vbase_bar(B *obj) {
130 // CHECK-LABEL: define dso_local void @"?call_vbase_bar@@YAXPAUB@@@Z"(ptr noundef %obj)
131 // CHECK: %[[OBJ:.*]] = load ptr
132
133 obj->bar();
134 // When calling a vbase's virtual method, one needs to adjust 'this'
135 // at the caller site.
136 //
137 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 0
138 // CHECK: %[[VBTABLE:.*]] = load ptr, ptr %[[VBPTR]]
139 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, ptr %[[VBTABLE]], i32 1
140 // CHECK: %[[VBOFFSET32:.*]] = load i32, ptr %[[VBENTRY]]
141 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
142 // CHECK: %[[VBASE:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 %[[VBOFFSET]]
143 //
144 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 0
145 // CHECK: %[[VBTABLE:.*]] = load ptr, ptr %[[VBPTR]]
146 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, ptr %[[VBTABLE]], i32 1
147 // CHECK: %[[VBOFFSET32:.*]] = load i32, ptr %[[VBENTRY]]
148 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
149 // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 %[[VBOFFSET]]
150 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[VBASE_i8]]
151 // CHECK: %[[VFUN:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 2
152 // CHECK: %[[VFUN_VALUE:.*]] = load ptr, ptr %[[VFUN]]
153 //
154 // CHECK: call x86_thiscallcc void %[[VFUN_VALUE]](ptr noundef %[[VBASE]])
155 //
156 // CHECK: ret void
157 }
158
159 void delete_B(B *obj) {
160 // CHECK-LABEL: define dso_local void @"?delete_B@@YAXPAUB@@@Z"(ptr noundef %obj)
161 // CHECK: %[[OBJ:.*]] = load ptr
162
163 delete obj;
164 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 0
165 // CHECK: %[[VBTABLE:.*]] = load ptr, ptr %[[VBPTR]]
166 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, ptr %[[VBTABLE]], i32 1
167 // CHECK: %[[VBOFFSET32:.*]] = load i32, ptr %[[VBENTRY]]
168 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
169 // CHECK: %[[VBASE:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 %[[VBOFFSET]]
170 //
171 // CHECK: %[[VBPTR:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 0
172 // CHECK: %[[VBTABLE:.*]] = load ptr, ptr %[[VBPTR]]
173 // CHECK: %[[VBENTRY:.*]] = getelementptr inbounds i32, ptr %[[VBTABLE]], i32 1
174 // CHECK: %[[VBOFFSET32:.*]] = load i32, ptr %[[VBENTRY]]
175 // CHECK: %[[VBOFFSET:.*]] = add nsw i32 0, %[[VBOFFSET32]]
176 // CHECK: %[[VBASE_i8:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 %[[VBOFFSET]]
177 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[VBASE_i8]]
178 // CHECK: %[[VFUN:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
179 // CHECK: %[[VFUN_VALUE:.*]] = load ptr, ptr %[[VFUN]]
180 //
181 // CHECK: call x86_thiscallcc noundef ptr %[[VFUN_VALUE]](ptr {{[^,]*}} %[[VBASE]], i32 noundef 1)
182 // CHECK: ret void
183 }
184
185 void call_complete_dtor() {
186 // CHECK-LABEL: define dso_local void @"?call_complete_dtor@@YAXXZ"
187 B b;
188 // CHECK: call x86_thiscallcc noundef ptr @"??0B@@QAE@XZ"(ptr {{[^,]*}} %[[B:.*]], i32 noundef 1)
189 // CHECK-NOT: getelementptr
190 // CHECK: call x86_thiscallcc void @"??_DB@@QAEXXZ"(ptr {{[^,]*}} %[[B]])
191 // CHECK: ret
192 }
193
194 struct C : B {
195 C();
196 // has an implicit vdtor.
197 };
198
199 // Used to crash on an assertion.
200 C::C() {
201 // CHECK-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0C@@QAE@XZ"
202 }
203
204 namespace multiple_vbases {
205 struct A {
206 virtual void a();
207 };
208
209 struct B {
210 virtual void b();
211 };
212
213 struct C {
214 virtual void c();
215 };
216
217 struct D : virtual A, virtual B, virtual C {
218 virtual void a();
219 virtual void b();
220 virtual void c();
221 D();
222 };
223
224 D::D() {
225 // CHECK-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0D@multiple_vbases@@QAE@XZ"
226 // Just make sure we emit 3 vtordisps after initializing vfptrs.
227 // CHECK: store ptr @"??_7D@multiple_vbases@@6BA@1@@", ptr %{{.*}}
228 // CHECK: store ptr @"??_7D@multiple_vbases@@6BB@1@@", ptr %{{.*}}
229 // CHECK: store ptr @"??_7D@multiple_vbases@@6BC@1@@", ptr %{{.*}}
230 // ...
231 // CHECK: store i32 %{{.*}}, ptr %{{.*}}
232 // CHECK: store i32 %{{.*}}, ptr %{{.*}}
233 // CHECK: store i32 %{{.*}}, ptr %{{.*}}
234 // CHECK: ret
235 }
236 }
237
238 namespace diamond {
239 struct A {
240 A();
241 virtual ~A();
242 };
243
244 struct B : virtual A {
245 B();
246 ~B();
247 };
248
249 struct C : virtual A {
250 C();
251 ~C();
252 int c1, c2, c3;
253 };
254
255 struct Z {
256 int z;
257 };
258
259 struct D : virtual Z, B, C {
260 D();
261 ~D();
262 } d;
263
264 D::~D() {
265 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1D@diamond@@UAE@XZ"(ptr{{.*}})
266 // Store initial this:
267 // CHECK: %[[THIS_ADDR:.*]] = alloca ptr
268 // CHECK: store ptr %{{.*}}, ptr %[[THIS_ADDR]], align 4
269 //
270 // Reload and adjust the this parameter:
271 // CHECK: %[[THIS_RELOAD:.*]] = load ptr, ptr %[[THIS_ADDR]]
272 // CHECK: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_RELOAD]], i32 -24
273 //
274 // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8, ptr %[[THIS_ADJ_i8]], i32 4
275 // CHECK: %[[ARG:.*]] = getelementptr i8, ptr %{{.*}}, i32 16
276 // CHECK: call x86_thiscallcc void @"??1C@diamond@@UAE@XZ"(ptr{{[^,]*}} %[[ARG]])
277
278 // CHECK: %[[ARG:.*]] = getelementptr i8, ptr %[[THIS_ADJ_i8]], i32 4
279 // CHECK: call x86_thiscallcc void @"??1B@diamond@@UAE@XZ"(ptr{{[^,]*}} %[[ARG]])
280 // CHECK: ret void
281 }
282
283 }
284
285 namespace test2 {
286 struct A { A(); };
287 struct B : virtual A { B() {} };
288 struct C : B, A { C() {} };
289
290 // PR18435: Order mattered here. We were generating code for the delegating
291 // call to B() from C().
292 void callC() { C x; }
293
294 // CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc noundef ptr @"??0C@test2@@QAE@XZ"
295 // CHECK: (ptr {{[^,]*}} returned align 4 dereferenceable(8) %this, i32 noundef %is_most_derived)
296 // CHECK: br i1
297 // Virtual bases
298 // CHECK: call x86_thiscallcc noundef ptr @"??0A@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}})
299 // CHECK: br label
300 // Non-virtual bases
301 // CHECK: call x86_thiscallcc noundef ptr @"??0B@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}}, i32 noundef 0)
302 // CHECK: call x86_thiscallcc noundef ptr @"??0A@test2@@QAE@XZ"(ptr {{[^,]*}} %{{.*}})
303 // CHECK: ret
304
305 }
306
307 namespace test3 {
308 // PR19104: A non-virtual call of a virtual method doesn't use vftable thunks,
309 // so requires only static adjustment which is different to the one used
310 // for virtual calls.
311 struct A {
312 virtual void foo();
313 };
314
315 struct B : virtual A {
316 virtual void bar();
317 };
318
319 struct C : virtual A {
320 virtual void foo();
321 };
322
323 struct D : B, C {
324 virtual void bar();
325 int field; // Laid out between C and A subobjects in D.
326 };
327
328 void D::bar() {
329 // CHECK-LABEL: define dso_local x86_thiscallcc void @"?bar@D@test3@@UAEXXZ"(ptr {{[^,]*}} %this)
330
331 C::foo();
332 // Shouldn't need any vbtable lookups. All we have to do is adjust to C*,
333 // then compensate for the adjustment performed in the C::foo() prologue.
334 // CHECK: %[[C_i8:.*]] = getelementptr inbounds i8, ptr %{{.*}}, i32 8
335 // CHECK: %[[ARG:.*]] = getelementptr i8, ptr %[[C_i8]], i32 4
336 // CHECK: call x86_thiscallcc void @"?foo@C@test3@@UAEXXZ"(ptr noundef %[[ARG]])
337 // CHECK: ret
338 }
339 }
340
341 namespace test4{
342 // PR19172: We used to merge method vftable locations wrong.
343
344 struct A {
345 virtual ~A() {}
346 };
347
348 struct B {
349 virtual ~B() {}
350 };
351
352 struct C : virtual A, B {
353 virtual ~C();
354 };
355
356 void foo(void*);
357
358 C::~C() {
359 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1C@test4@@UAE@XZ"(ptr {{[^,]*}} %this)
360
361 // In this case "this" points to the most derived class, so no GEPs needed.
362 // CHECK-NOT: getelementptr
363 // CHECK: store ptr @"??_7C@test4@@6BB@1@@", ptr %{{.*}}
364
365 foo(this);
366 // CHECK: ret
367 }
368
369 void destroy(C *obj) {
370 // CHECK-LABEL: define dso_local void @"?destroy@test4@@YAXPAUC@1@@Z"(ptr noundef %obj)
371
372 delete obj;
373 // CHECK: %[[OBJ:.*]] = load ptr, ptr
374 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[OBJ]]
375 // CHECK: %[[VFTENTRY:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
376 // CHECK: %[[VFUN:.*]] = load ptr, ptr %[[VFTENTRY]]
377 // CHECK: call x86_thiscallcc noundef ptr %[[VFUN]](ptr {{[^,]*}} %[[OBJ]], i32 noundef 1)
378 // CHECK: ret
379 }
380
381 struct D {
382 virtual void d();
383 };
384
385 // The first non-virtual base doesn't have a vdtor,
386 // but "this adjustment" is not needed.
387 struct E : D, B, virtual A {
388 virtual ~E();
389 };
390
391 E::~E() {
392 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1E@test4@@UAE@XZ"(ptr{{[^,]*}} %this)
393
394 // In this case "this" points to the most derived class, so no GEPs needed.
395 // CHECK-NOT: getelementptr
396 // CHECK: store ptr @"??_7E@test4@@6BD@1@@", ptr %{{.*}}
397 foo(this);
398 }
399
400 void destroy(E *obj) {
401 // CHECK-LABEL: define dso_local void @"?destroy@test4@@YAXPAUE@1@@Z"(ptr noundef %obj)
402
403 // CHECK-NOT: getelementptr
404 // CHECK: %[[THIS_i8:.*]] = getelementptr inbounds i8, ptr %[[OBJ]], i32 4
405 // CHECK: %[[B_i8:.*]] = getelementptr inbounds i8, ptr %[[OBJ:.*]], i32 4
406 // CHECK: %[[VFTABLE:.*]] = load ptr, ptr %[[B_i8]]
407 // CHECK: %[[VFTENTRY:.*]] = getelementptr inbounds ptr, ptr %[[VFTABLE]], i64 0
408 // CHECK: %[[VFUN:.*]] = load ptr, ptr %[[VFTENTRY]]
409 // CHECK: call x86_thiscallcc noundef ptr %[[VFUN]](ptr{{[^,]*}} %[[THIS_i8]], i32 noundef 1)
410 delete obj;
411 }
412
413 }
414
415 namespace test5 {
416 // PR25370: Don't zero-initialize vbptrs in virtual bases.
417 struct A {
418 virtual void f();
419 };
420
421 struct B : virtual A {
422 int Field;
423 };
424
425 struct C : B {
426 C();
427 };
428
429 C::C() : B() {}
430 // CHECK-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0C@test5@@QAE@XZ"(
431 // CHECK: %[[THIS:.*]] = load ptr, ptr
432 // CHECK: br i1 %{{.*}}, label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
433
434 // CHECK: %[[SKIP_VBASES]]
435 // CHECK: %[[FIELD:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 4
436 // CHECK: call void @llvm.memset.p0.i32(ptr align 4 %[[FIELD]], i8 0, i32 4, i1 false)
437 }
438
439 namespace pr27621 {
440 // Devirtualization through a static_cast used to make us compute the 'this'
441 // adjustment for B::g instead of C::g. When we directly call C::g, 'this' is a
442 // B*, and the prologue of C::g will adjust it to a C*.
443 struct A { virtual void f(); };
444 struct B { virtual void g(); };
445 struct C final : A, B {
446 virtual void h();
447 void g() override;
448 };
449 void callit(C *p) {
450 static_cast<B*>(p)->g();
451 }
452 // CHECK-LABEL: define dso_local void @"?callit@pr27621@@YAXPAUC@1@@Z"(ptr noundef %{{.*}})
453 // CHECK: %[[B_i8:.*]] = getelementptr i8, ptr %{{.*}}, i32 4
454 // CHECK: call x86_thiscallcc void @"?g@C@pr27621@@UAEXXZ"(ptr noundef %[[B_i8]])
455 }
456
457 namespace test6 {
458 class A {};
459 class B : virtual A {};
460 class C : virtual B {
461 virtual void m_fn1();
462 float field;
463 };
464 class D : C {
465 D();
466 };
467 D::D() : C() {}
468 // CHECK-LABEL: define dso_local x86_thiscallcc noundef ptr @"??0D@test6@@AAE@XZ"(
469 // CHECK: %[[THIS:.*]] = load ptr, ptr
470 // CHECK: br i1 %{{.*}}, label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
471
472 // CHECK: %[[SKIP_VBASES]]
473 // CHECK: %[[FIELD:.*]] = getelementptr inbounds i8, ptr %[[THIS]], i32 8
474 // CHECK: call void @llvm.memset.p0.i32(ptr align 4 %[[FIELD]], i8 0, i32 4, i1 false)
475 }
476
477 namespace pr36921 {
478 struct A {
479 virtual ~A() {}
480 };
481 struct B {
482 virtual ~B() {}
483 };
484 struct C : virtual B {};
485 struct D : virtual A, C {};
486 D d;
487 }
488
489 namespace issue_60465 {
490 // We used to assume the first argument to all destructors was the derived type
491 // even when there was a 'this' adjustment.
492 struct A {
493 virtual ~A();
494 };
495
496 struct alignas(2 * sizeof(void *)) B : virtual A {
497 ~B();
498 void *x, *y;
499 };
500
501 B::~B() {
502 // The 'this' parameter should not have a type of ptr and
503 // must not have 'align 8', since at least B's copy of A is only 'align 4'.
504 // CHECK-LABEL: define dso_local x86_thiscallcc void @"??1B@issue_60465@@UAE@XZ"(ptr noundef %this)
505 // CHECK: %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, ptr %{{.*}}, i32 -12
506 // CHECK: %[[X:.*]] = getelementptr inbounds nuw %"struct.issue_60465::B", ptr %[[THIS_ADJ_i8]], i32 0, i32 1
507 // CHECK: store ptr null, ptr %[[X]], align 4
508 // CHECK: %[[Y:.*]] = getelementptr inbounds nuw %"struct.issue_60465::B", ptr %[[THIS_ADJ_i8]], i32 0, i32 2
509 // CHECK: store ptr null, ptr %[[Y]], align 8
510 x = nullptr;
511 y = nullptr;
512 }
513 }