xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/microsoft-abi-structors.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1 // RUN: %clang_cc1 -emit-llvm -fno-rtti %s -std=c++11 -o - -mconstructor-aliases -triple=i386-pc-win32 -fno-rtti > %t
2 // RUN: FileCheck %s < %t
3 // vftables are emitted very late, so do another pass to try to keep the checks
4 // in source order.
5 // RUN: FileCheck --check-prefix DTORS %s < %t
6 // RUN: FileCheck --check-prefix DTORS2 %s < %t
7 // RUN: FileCheck --check-prefix DTORS3 %s < %t
8 //
9 // RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=x86_64-pc-win32 -fno-rtti | FileCheck --check-prefix DTORS-X64 %s
10 
11 namespace basic {
12 
13 class A {
14  public:
A()15   A() { }
16   ~A();
17 };
18 
no_constructor_destructor_infinite_recursion()19 void no_constructor_destructor_infinite_recursion() {
20   A a;
21 
22 // CHECK:      define linkonce_odr x86_thiscallcc %"class.basic::A"* @"\01??0A@basic@@QAE@XZ"(%"class.basic::A"* returned %this)
23 // CHECK:        [[THIS_ADDR:%[.0-9A-Z_a-z]+]] = alloca %"class.basic::A"*, align 4
24 // CHECK-NEXT:   store %"class.basic::A"* %this, %"class.basic::A"** [[THIS_ADDR]], align 4
25 // CHECK-NEXT:   [[T1:%[.0-9A-Z_a-z]+]] = load %"class.basic::A"** [[THIS_ADDR]]
26 // CHECK-NEXT:   ret %"class.basic::A"* [[T1]]
27 // CHECK-NEXT: }
28 }
29 
~A()30 A::~A() {
31 // Make sure that the destructor doesn't call itself:
32 // CHECK: define {{.*}} @"\01??1A@basic@@QAE@XZ"
33 // CHECK-NOT: call void @"\01??1A@basic@@QAE@XZ"
34 // CHECK: ret
35 }
36 
37 struct B {
38   B();
39 };
40 
41 // Tests that we can define constructors outside the class (PR12784).
B()42 B::B() {
43   // CHECK: define x86_thiscallcc %"struct.basic::B"* @"\01??0B@basic@@QAE@XZ"(%"struct.basic::B"* returned %this)
44   // CHECK: ret
45 }
46 
47 struct C {
~Cbasic::C48   virtual ~C() {
49 // DTORS:      define linkonce_odr x86_thiscallcc i8* @"\01??_GC@basic@@UAEPAXI@Z"(%"struct.basic::C"* %this, i32 %should_call_delete)
50 // DTORS:        store i32 %should_call_delete, i32* %[[SHOULD_DELETE_VAR:[0-9a-z._]+]], align 4
51 // DTORS:        store i8* %{{.*}}, i8** %[[RETVAL:[0-9a-z._]+]]
52 // DTORS:        %[[SHOULD_DELETE_VALUE:[0-9a-z._]+]] = load i32* %[[SHOULD_DELETE_VAR]]
53 // DTORS:        call x86_thiscallcc void @"\01??1C@basic@@UAE@XZ"(%"struct.basic::C"* %[[THIS:[0-9a-z]+]])
54 // DTORS-NEXT:   %[[CONDITION:[0-9]+]] = icmp eq i32 %[[SHOULD_DELETE_VALUE]], 0
55 // DTORS-NEXT:   br i1 %[[CONDITION]], label %[[CONTINUE_LABEL:[0-9a-z._]+]], label %[[CALL_DELETE_LABEL:[0-9a-z._]+]]
56 //
57 // DTORS:      [[CALL_DELETE_LABEL]]
58 // DTORS-NEXT:   %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
59 // DTORS-NEXT:   call void @"\01??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
60 // DTORS-NEXT:   br label %[[CONTINUE_LABEL]]
61 //
62 // DTORS:      [[CONTINUE_LABEL]]
63 // DTORS-NEXT:   %[[RET:.*]] = load i8** %[[RETVAL]]
64 // DTORS-NEXT:   ret i8* %[[RET]]
65 
66 // Check that we do the mangling correctly on x64.
67 // DTORS-X64:  @"\01??_GC@basic@@UEAAPEAXI@Z"
68   }
69   virtual void foo();
70 };
71 
72 // Emits the vftable in the output.
foo()73 void C::foo() {}
74 
check_vftable_offset()75 void check_vftable_offset() {
76   C c;
77 // The vftable pointer should point at the beginning of the vftable.
78 // CHECK: [[THIS_PTR:%[0-9]+]] = bitcast %"struct.basic::C"* {{.*}} to i32 (...)***
79 // CHECK: store i32 (...)** bitcast ([2 x i8*]* @"\01??_7C@basic@@6B@" to i32 (...)**), i32 (...)*** [[THIS_PTR]]
80 }
81 
call_complete_dtor(C * obj_ptr)82 void call_complete_dtor(C *obj_ptr) {
83 // CHECK: define void @"\01?call_complete_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
84   obj_ptr->~C();
85 // CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4
86 // CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to i8* (%"struct.basic::C"*, i32)***
87 // CHECK-NEXT: %[[VTABLE:.*]] = load i8* (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
88 // CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
89 // CHECK-NEXT: %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
90 // CHECK-NEXT: call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 0)
91 // CHECK-NEXT: ret void
92 }
93 
call_deleting_dtor(C * obj_ptr)94 void call_deleting_dtor(C *obj_ptr) {
95 // CHECK: define void @"\01?call_deleting_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
96   delete obj_ptr;
97 // CHECK:      %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4
98 // CHECK:      br i1 {{.*}}, label %[[DELETE_NULL:.*]], label %[[DELETE_NOTNULL:.*]]
99 
100 // CHECK:      [[DELETE_NOTNULL]]
101 // CHECK-NEXT:   %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to i8* (%"struct.basic::C"*, i32)***
102 // CHECK-NEXT:   %[[VTABLE:.*]] = load i8* (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
103 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
104 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
105 // CHECK-NEXT:   call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 1)
106 // CHECK:      ret void
107 }
108 
call_deleting_dtor_and_global_delete(C * obj_ptr)109 void call_deleting_dtor_and_global_delete(C *obj_ptr) {
110 // CHECK: define void @"\01?call_deleting_dtor_and_global_delete@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
111   ::delete obj_ptr;
112 // CHECK:      %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4
113 // CHECK:      br i1 {{.*}}, label %[[DELETE_NULL:.*]], label %[[DELETE_NOTNULL:.*]]
114 
115 // CHECK:      [[DELETE_NOTNULL]]
116 // CHECK-NEXT:   %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to i8* (%"struct.basic::C"*, i32)***
117 // CHECK-NEXT:   %[[VTABLE:.*]] = load i8* (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
118 // CHECK-NEXT:   %[[PVDTOR:.*]] = getelementptr inbounds i8* (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
119 // CHECK-NEXT:   %[[VDTOR:.*]] = load i8* (%"struct.basic::C"*, i32)** %[[PVDTOR]]
120 // CHECK-NEXT:   %[[CALL:.*]] = call x86_thiscallcc i8* %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 0)
121 // CHECK-NEXT:   call void @"\01??3@YAXPAX@Z"(i8* %[[CALL]])
122 // CHECK:      ret void
123 }
124 
125 struct D {
126   static int foo();
127 
Dbasic::D128   D() {
129     static int ctor_static = foo();
130     // CHECK that the static in the ctor gets mangled correctly:
131     // CHECK: @"\01?ctor_static@?1???0D@basic@@QAE@XZ@4HA"
132   }
~Dbasic::D133   ~D() {
134     static int dtor_static = foo();
135     // CHECK that the static in the dtor gets mangled correctly:
136     // CHECK: @"\01?dtor_static@?1???1D@basic@@QAE@XZ@4HA"
137   }
138 };
139 
use_D()140 void use_D() { D c; }
141 
142 } // end namespace basic
143 
144 namespace dtor_in_second_nvbase {
145 
146 struct A {
147   virtual void f();  // A needs vftable to be primary.
148 };
149 struct B {
150   virtual ~B();
151 };
152 struct C : A, B {
153   virtual ~C();
154 };
155 
~C()156 C::~C() {
157 // CHECK-LABEL: define x86_thiscallcc void @"\01??1C@dtor_in_second_nvbase@@UAE@XZ"
158 // CHECK:       (%"struct.dtor_in_second_nvbase::C"* %this)
159 //      No this adjustment!
160 // CHECK-NOT: getelementptr
161 // CHECK:   load %"struct.dtor_in_second_nvbase::C"** %{{.*}}
162 //      Now we this-adjust before calling ~B.
163 // CHECK:   bitcast %"struct.dtor_in_second_nvbase::C"* %{{.*}} to i8*
164 // CHECK:   getelementptr inbounds i8* %{{.*}}, i64 4
165 // CHECK:   bitcast i8* %{{.*}} to %"struct.dtor_in_second_nvbase::B"*
166 // CHECK:   call x86_thiscallcc void @"\01??1B@dtor_in_second_nvbase@@UAE@XZ"
167 // CHECK:       (%"struct.dtor_in_second_nvbase::B"* %{{.*}})
168 // CHECK:   ret void
169 }
170 
foo()171 void foo() {
172   C c;
173 }
174 // DTORS2-LABEL: define linkonce_odr x86_thiscallcc i8* @"\01??_EC@dtor_in_second_nvbase@@W3AEPAXI@Z"
175 // DTORS2:       (%"struct.dtor_in_second_nvbase::C"* %this, i32 %should_call_delete)
176 //      Do an adjustment from B* to C*.
177 // DTORS2:   getelementptr i8* %{{.*}}, i32 -4
178 // DTORS2:   bitcast i8* %{{.*}} to %"struct.dtor_in_second_nvbase::C"*
179 // DTORS2:   %[[CALL:.*]] = call x86_thiscallcc i8* @"\01??_GC@dtor_in_second_nvbase@@UAEPAXI@Z"
180 // DTORS2:   ret i8* %[[CALL]]
181 
182 }
183 
184 namespace test2 {
185 // Just like dtor_in_second_nvbase, except put that in a vbase of a diamond.
186 
187 // C's dtor is in the non-primary base.
188 struct A { virtual void f(); };
189 struct B { virtual ~B(); };
190 struct C : A, B { virtual ~C(); int c; };
191 
192 // Diamond hierarchy, with C as the shared vbase.
193 struct D : virtual C { int d; };
194 struct E : virtual C { int e; };
195 struct F : D, E { ~F(); int f; };
196 
~F()197 F::~F() {
198 // CHECK-LABEL: define x86_thiscallcc void @"\01??1F@test2@@UAE@XZ"(%"struct.test2::F"*)
199 //      Do an adjustment from C vbase subobject to F as though F was the
200 //      complete type.
201 // CHECK:   getelementptr inbounds i8* %{{.*}}, i32 -20
202 // CHECK:   bitcast i8* %{{.*}} to %"struct.test2::F"*
203 // CHECK:   store %"struct.test2::F"*
204 }
205 
foo()206 void foo() {
207   F f;
208 }
209 // DTORS3-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_DF@test2@@UAE@XZ"
210 //      Do an adjustment from C* to F*.
211 // DTORS3:   getelementptr i8* %{{.*}}, i32 20
212 // DTORS3:   bitcast i8* %{{.*}} to %"struct.test2::F"*
213 // DTORS3:   call x86_thiscallcc void @"\01??1F@test2@@UAE@XZ"
214 // DTORS3:   ret void
215 
216 }
217 
218 namespace constructors {
219 
220 struct A {
Aconstructors::A221   A() {}
222 };
223 
224 struct B : A {
225   B();
226   ~B();
227 };
228 
B()229 B::B() {
230   // CHECK: define x86_thiscallcc %"struct.constructors::B"* @"\01??0B@constructors@@QAE@XZ"(%"struct.constructors::B"* returned %this)
231   // CHECK: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
232   // CHECK: ret
233 }
234 
235 struct C : virtual A {
236   C();
237 };
238 
C()239 C::C() {
240   // CHECK: define x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* returned %this, i32 %is_most_derived)
241   // TODO: make sure this works in the Release build too;
242   // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
243   // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]]
244   // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
245   // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
246   //
247   // CHECK: [[INIT_VBASES]]
248   // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::C"* %{{.*}} to i8*
249   // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0
250   // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
251   // CHECK-NEXT: store i32* getelementptr inbounds ([2 x i32]* @"\01??_8C@constructors@@7B@", i32 0, i32 0), i32** %[[vbptr]]
252   // CHECK-NEXT: bitcast %"struct.constructors::C"* %{{.*}} to i8*
253   // CHECK-NEXT: getelementptr inbounds i8* %{{.*}}, i64 4
254   // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
255   // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
256   // CHECK-NEXT: br label %[[SKIP_VBASES]]
257   //
258   // CHECK: [[SKIP_VBASES]]
259   // Class C does not define or override methods, so shouldn't change the vfptr.
260   // CHECK-NOT: @"\01??_7C@constructors@@6B@"
261   // CHECK: ret
262 }
263 
create_C()264 void create_C() {
265   C c;
266   // CHECK: define void @"\01?create_C@constructors@@YAXXZ"()
267   // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %c, i32 1)
268   // CHECK: ret
269 }
270 
271 struct D : C {
272   D();
273 };
274 
D()275 D::D() {
276   // CHECK: define x86_thiscallcc %"struct.constructors::D"* @"\01??0D@constructors@@QAE@XZ"(%"struct.constructors::D"* returned %this, i32 %is_most_derived) unnamed_addr
277   // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
278   // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]]
279   // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
280   // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
281   //
282   // CHECK: [[INIT_VBASES]]
283   // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::D"* %{{.*}} to i8*
284   // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0
285   // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
286   // CHECK-NEXT: store i32* getelementptr inbounds ([2 x i32]* @"\01??_8D@constructors@@7B@", i32 0, i32 0), i32** %[[vbptr]]
287   // CHECK-NEXT: bitcast %"struct.constructors::D"* %{{.*}} to i8*
288   // CHECK-NEXT: getelementptr inbounds i8* %{{.*}}, i64 4
289   // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
290   // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
291   // CHECK-NEXT: br label %[[SKIP_VBASES]]
292   //
293   // CHECK: [[SKIP_VBASES]]
294   // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0)
295   // CHECK: ret
296 }
297 
298 struct E : virtual C {
299   E();
300 };
301 
E()302 E::E() {
303   // CHECK: define x86_thiscallcc %"struct.constructors::E"* @"\01??0E@constructors@@QAE@XZ"(%"struct.constructors::E"* returned %this, i32 %is_most_derived) unnamed_addr
304   // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
305   // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]]
306   // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
307   // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
308   //
309   // CHECK: [[INIT_VBASES]]
310   // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::E"* %{{.*}} to i8*
311   // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0
312   // CHECK-NEXT: %[[vbptr_E:.*]] = bitcast i8* %[[offs]] to i32**
313   // CHECK-NEXT: store i32* getelementptr inbounds ([3 x i32]* @"\01??_8E@constructors@@7B01@@", i32 0, i32 0), i32** %[[vbptr_E]]
314   // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 4
315   // CHECK-NEXT: %[[vbptr_C:.*]] = bitcast i8* %[[offs]] to i32**
316   // CHECK-NEXT: store i32* getelementptr inbounds ([2 x i32]* @"\01??_8E@constructors@@7BC@1@@", i32 0, i32 0), i32** %[[vbptr_C]]
317   // CHECK-NEXT: bitcast %"struct.constructors::E"* %{{.*}} to i8*
318   // CHECK-NEXT: getelementptr inbounds i8* %{{.*}}, i64 4
319   // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
320   // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
321   // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0)
322   // CHECK-NEXT: br label %[[SKIP_VBASES]]
323   //
324   // CHECK: [[SKIP_VBASES]]
325   // CHECK: ret
326 }
327 
328 // PR16735 - even abstract classes should have a constructor emitted.
329 struct F {
330   F();
331   virtual void f() = 0;
332 };
333 
F()334 F::F() {}
335 // CHECK: define x86_thiscallcc %"struct.constructors::F"* @"\01??0F@constructors@@QAE@XZ"
336 
337 } // end namespace constructors
338 
339 namespace dtors {
340 
341 struct A {
342   ~A();
343 };
344 
call_nv_complete(A * a)345 void call_nv_complete(A *a) {
346   a->~A();
347 // CHECK: define void @"\01?call_nv_complete@dtors@@YAXPAUA@1@@Z"
348 // CHECK: call x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ"
349 // CHECK: ret
350 }
351 
352 // CHECK: declare x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ"
353 
354 // Now try some virtual bases, where we need the complete dtor.
355 
356 struct B : virtual A { ~B(); };
357 struct C : virtual A { ~C(); };
358 struct D : B, C { ~D(); };
359 
call_vbase_complete(D * d)360 void call_vbase_complete(D *d) {
361   d->~D();
362 // CHECK: define void @"\01?call_vbase_complete@dtors@@YAXPAUD@1@@Z"
363 // CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}})
364 // CHECK: ret
365 }
366 
367 // The complete dtor should call the base dtors for D and the vbase A (once).
368 // CHECK: define linkonce_odr x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"
369 // CHECK-NOT: call
370 // CHECK: call x86_thiscallcc void @"\01??1D@dtors@@QAE@XZ"
371 // CHECK-NOT: call
372 // CHECK: call x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ"
373 // CHECK-NOT: call
374 // CHECK: ret
375 
destroy_d_complete()376 void destroy_d_complete() {
377   D d;
378 // CHECK: define void @"\01?destroy_d_complete@dtors@@YAXXZ"
379 // CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}})
380 // CHECK: ret
381 }
382 
383 // FIXME: Clang manually inlines the deletion, so we don't get a call to the
384 // deleting dtor (_G).  The only way to call deleting dtors currently is through
385 // a vftable.
call_nv_deleting_dtor(D * d)386 void call_nv_deleting_dtor(D *d) {
387   delete d;
388 // CHECK: define void @"\01?call_nv_deleting_dtor@dtors@@YAXPAUD@1@@Z"
389 // CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}})
390 // CHECK: call void @"\01??3@YAXPAX@Z"
391 // CHECK: ret
392 }
393 
394 }
395 
396 namespace test1 {
397 struct A { };
398 struct B : virtual A {
399   B(int *a);
400   B(const char *a, ...);
401   __cdecl B(short *a);
402 };
B(int * a)403 B::B(int *a) {}
B(const char * a,...)404 B::B(const char *a, ...) {}
B(short * a)405 B::B(short *a) {}
406 // CHECK: define x86_thiscallcc %"struct.test1::B"* @"\01??0B@test1@@QAE@PAH@Z"
407 // CHECK:               (%"struct.test1::B"* returned %this, i32* %a, i32 %is_most_derived)
408 // CHECK: define %"struct.test1::B"* @"\01??0B@test1@@QAA@PBDZZ"
409 // CHECK:               (%"struct.test1::B"* returned %this, i32 %is_most_derived, i8* %a, ...)
410 
411 // FIXME: This should be x86_thiscallcc.  MSVC ignores explicit CCs on structors.
412 // CHECK: define %"struct.test1::B"* @"\01??0B@test1@@QAA@PAF@Z"
413 // CHECK:               (%"struct.test1::B"* returned %this, i16* %a, i32 %is_most_derived)
414 
construct_b()415 void construct_b() {
416   int a;
417   B b1(&a);
418   B b2("%d %d", 1, 2);
419 }
420 // CHECK-LABEL: define void @"\01?construct_b@test1@@YAXXZ"()
421 // CHECK: call x86_thiscallcc %"struct.test1::B"* @"\01??0B@test1@@QAE@PAH@Z"
422 // CHECK:               (%"struct.test1::B"* {{.*}}, i32* {{.*}}, i32 1)
423 // CHECK: call %"struct.test1::B"* (%"struct.test1::B"*, i32, i8*, ...)* @"\01??0B@test1@@QAA@PBDZZ"
424 // CHECK:               (%"struct.test1::B"* {{.*}}, i32 1, i8* {{.*}}, i32 1, i32 2)
425 }
426 
427 namespace implicit_copy_vtable {
428 // This was a crash that only reproduced in ABIs without key functions.
429 struct ImplicitCopy {
430   // implicit copy ctor
431   virtual ~ImplicitCopy();
432 };
CreateCopy(ImplicitCopy * a)433 void CreateCopy(ImplicitCopy *a) {
434   new ImplicitCopy(*a);
435 }
436 // CHECK: store {{.*}} @"\01??_7ImplicitCopy@implicit_copy_vtable@@6B@"
437 
438 struct MoveOnly {
439   MoveOnly(MoveOnly &&o) = default;
440   virtual ~MoveOnly();
441 };
442 MoveOnly &&f();
g()443 void g() { new MoveOnly(f()); }
444 // CHECK: store {{.*}} @"\01??_7MoveOnly@implicit_copy_vtable@@6B@"
445 }
446 
447 // Dtor thunks for classes in anonymous namespaces should be internal, not
448 // linkonce_odr.
449 namespace {
450 struct A {
~A__anon49af16620111::A451   virtual ~A() { }
452 };
453 }
getA()454 void *getA() {
455   return (void*)new A();
456 }
457 // CHECK: define internal x86_thiscallcc i8* @"\01??_GA@?A@@UAEPAXI@Z"
458 // CHECK:               (%"struct.(anonymous namespace)::A"* %this, i32 %should_call_delete)
459 // CHECK: define internal x86_thiscallcc void @"\01??1A@?A@@UAE@XZ"
460 // CHECK:               (%"struct.(anonymous namespace)::A"* %this)
461