blob: b79da8d6cb183e782e7c788f00e875e3e63dbd8b [file] [log] [blame]
Hans Wennborgc9bd88e2014-01-14 19:35:09 +00001// RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=i386-pc-win32 -fno-rtti > %t
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +00002// RUN: FileCheck %s < %t
Reid Klecknere7de47e2013-07-22 13:51:44 +00003// 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
Reid Kleckner0c12b362014-02-18 22:51:52 +00006// RUN: FileCheck --check-prefix DTORS2 %s < %t
7// RUN: FileCheck --check-prefix DTORS3 %s < %t
Timur Iskhodzhanovf46993e2013-08-26 10:32:04 +00008//
Hans Wennborgc9bd88e2014-01-14 19:35:09 +00009// RUN: %clang_cc1 -emit-llvm %s -o - -mconstructor-aliases -triple=x86_64-pc-win32 -fno-rtti | FileCheck --check-prefix DTORS-X64 %s
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000010
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000011namespace basic {
12
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000013class A {
14 public:
15 A() { }
Reid Klecknere7de47e2013-07-22 13:51:44 +000016 ~A();
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000017};
18
Timur Iskhodzhanov584248c2013-02-12 13:22:47 +000019void no_constructor_destructor_infinite_recursion() {
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000020 A a;
21
Stephen Lin9dc6eef2013-06-30 20:40:16 +000022// CHECK: define linkonce_odr x86_thiscallcc %"class.basic::A"* @"\01??0A@basic@@QAE@XZ"(%"class.basic::A"* returned %this)
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000023// 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]]
John McCall0f999f32012-09-25 08:00:39 +000027// CHECK-NEXT: }
Reid Klecknere7de47e2013-07-22 13:51:44 +000028}
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000029
Reid Klecknere7de47e2013-07-22 13:51:44 +000030A::~A() {
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000031// Make sure that the destructor doesn't call itself:
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000032// CHECK: define {{.*}} @"\01??1A@basic@@QAE@XZ"
33// CHECK-NOT: call void @"\01??1A@basic@@QAE@XZ"
Timur Iskhodzhanovf32a3772012-04-20 08:05:00 +000034// CHECK: ret
35}
John McCall0f999f32012-09-25 08:00:39 +000036
Timur Iskhodzhanov52b8a052013-01-21 13:02:41 +000037struct B {
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000038 B();
39};
40
41// Tests that we can define constructors outside the class (PR12784).
42B::B() {
Stephen Lin9dc6eef2013-06-30 20:40:16 +000043 // CHECK: define x86_thiscallcc %"struct.basic::B"* @"\01??0B@basic@@QAE@XZ"(%"struct.basic::B"* returned %this)
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000044 // CHECK: ret
45}
46
47struct C {
48 virtual ~C() {
Timur Iskhodzhanov701981f2013-08-27 10:38:19 +000049// DTORS: define linkonce_odr x86_thiscallcc void @"\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: %[[SHOULD_DELETE_VALUE:[0-9a-z._]+]] = load i32* %[[SHOULD_DELETE_VAR]]
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000052// DTORS: call x86_thiscallcc void @"\01??1C@basic@@UAE@XZ"(%"struct.basic::C"* %[[THIS:[0-9a-z]+]])
Timur Iskhodzhanov701981f2013-08-27 10:38:19 +000053// DTORS-NEXT: %[[CONDITION:[0-9]+]] = icmp eq i32 %[[SHOULD_DELETE_VALUE]], 0
Timur Iskhodzhanov6d5dbc62013-02-13 12:14:25 +000054// DTORS-NEXT: br i1 %[[CONDITION]], label %[[CONTINUE_LABEL:[0-9a-z._]+]], label %[[CALL_DELETE_LABEL:[0-9a-z._]+]]
55//
56// DTORS: [[CALL_DELETE_LABEL]]
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000057// DTORS-NEXT: %[[THIS_AS_VOID:[0-9a-z]+]] = bitcast %"struct.basic::C"* %[[THIS]] to i8*
Reid Klecknere7de47e2013-07-22 13:51:44 +000058// DTORS-NEXT: call void @"\01??3@YAXPAX@Z"(i8* %[[THIS_AS_VOID]])
Timur Iskhodzhanov6d5dbc62013-02-13 12:14:25 +000059// DTORS-NEXT: br label %[[CONTINUE_LABEL]]
60//
61// DTORS: [[CONTINUE_LABEL]]
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000062// DTORS-NEXT: ret void
Timur Iskhodzhanovf46993e2013-08-26 10:32:04 +000063
64// Check that we do the mangling correctly on x64.
65// DTORS-X64: @"\01??_GC@basic@@UEAAPEAXI@Z"
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000066 }
Timur Iskhodzhanov52b8a052013-01-21 13:02:41 +000067 virtual void foo();
68};
69
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000070// Emits the vftable in the output.
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000071void C::foo() {}
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000072
Timur Iskhodzhanov52b8a052013-01-21 13:02:41 +000073void check_vftable_offset() {
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000074 C c;
Timur Iskhodzhanov52b8a052013-01-21 13:02:41 +000075// The vftable pointer should point at the beginning of the vftable.
Timur Iskhodzhanov8b5987e2013-09-27 14:48:01 +000076// CHECK: [[THIS_PTR:%[0-9]+]] = bitcast %"struct.basic::C"* {{.*}} to [2 x i8*]**
77// CHECK: store [2 x i8*]* @"\01??_7C@basic@@6B@", [2 x i8*]** [[THIS_PTR]]
Timur Iskhodzhanov52b8a052013-01-21 13:02:41 +000078}
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000079
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000080void call_complete_dtor(C *obj_ptr) {
81// CHECK: define void @"\01?call_complete_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
82 obj_ptr->~C();
83// CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4
Timur Iskhodzhanov701981f2013-08-27 10:38:19 +000084// CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to void (%"struct.basic::C"*, i32)***
85// CHECK-NEXT: %[[VTABLE:.*]] = load void (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
86// CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds void (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
87// CHECK-NEXT: %[[VDTOR:.*]] = load void (%"struct.basic::C"*, i32)** %[[PVDTOR]]
88// CHECK-NEXT: call x86_thiscallcc void %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 0)
Timur Iskhodzhanovd6197112013-02-15 14:45:22 +000089// CHECK-NEXT: ret void
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000090}
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000091
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000092void call_deleting_dtor(C *obj_ptr) {
93// CHECK: define void @"\01?call_deleting_dtor@basic@@YAXPAUC@1@@Z"(%"struct.basic::C"* %obj_ptr)
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +000094 delete obj_ptr;
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +000095// CHECK: %[[OBJ_PTR_VALUE:.*]] = load %"struct.basic::C"** %{{.*}}, align 4
96// CHECK: br i1 {{.*}}, label %[[DELETE_NULL:.*]], label %[[DELETE_NOTNULL:.*]]
97
98// CHECK: [[DELETE_NOTNULL]]
Timur Iskhodzhanov701981f2013-08-27 10:38:19 +000099// CHECK-NEXT: %[[PVTABLE:.*]] = bitcast %"struct.basic::C"* %[[OBJ_PTR_VALUE]] to void (%"struct.basic::C"*, i32)***
100// CHECK-NEXT: %[[VTABLE:.*]] = load void (%"struct.basic::C"*, i32)*** %[[PVTABLE]]
101// CHECK-NEXT: %[[PVDTOR:.*]] = getelementptr inbounds void (%"struct.basic::C"*, i32)** %[[VTABLE]], i64 0
102// CHECK-NEXT: %[[VDTOR:.*]] = load void (%"struct.basic::C"*, i32)** %[[PVDTOR]]
103// CHECK-NEXT: call x86_thiscallcc void %[[VDTOR]](%"struct.basic::C"* %[[OBJ_PTR_VALUE]], i32 1)
Timur Iskhodzhanovd6197112013-02-15 14:45:22 +0000104// CHECK: ret void
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +0000105}
106
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000107struct D {
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +0000108 static int foo();
109
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000110 D() {
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +0000111 static int ctor_static = foo();
112 // CHECK that the static in the ctor gets mangled correctly:
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000113 // CHECK: @"\01?ctor_static@?1???0D@basic@@QAE@XZ@4HA"
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +0000114 }
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000115 ~D() {
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +0000116 static int dtor_static = foo();
117 // CHECK that the static in the dtor gets mangled correctly:
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000118 // CHECK: @"\01?dtor_static@?1???1D@basic@@QAE@XZ@4HA"
Timur Iskhodzhanovee6bc532013-02-13 08:37:51 +0000119 }
120};
121
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000122void use_D() { D c; }
Bill Wendlinge1c4a1b2013-02-22 09:10:20 +0000123
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000124} // end namespace basic
125
Reid Kleckner0c12b362014-02-18 22:51:52 +0000126namespace dtor_in_second_nvbase {
127
128struct A {
129 virtual void f(); // A needs vftable to be primary.
130};
131struct B {
132 virtual ~B();
133};
134struct C : A, B {
135 virtual ~C();
136};
137
138C::~C() {
139// CHECK-LABEL: define x86_thiscallcc void @"\01??1C@dtor_in_second_nvbase@@UAE@XZ"
140// CHECK: (%"struct.dtor_in_second_nvbase::C"* %this)
141// No this adjustment!
142// CHECK-NOT: getelementptr
143// CHECK: load %"struct.dtor_in_second_nvbase::C"** %{{.*}}
144// Now we this-adjust before calling ~B.
145// CHECK: bitcast %"struct.dtor_in_second_nvbase::C"* %{{.*}} to i8*
146// CHECK: getelementptr inbounds i8* %{{.*}}, i64 4
147// CHECK: bitcast i8* %{{.*}} to %"struct.dtor_in_second_nvbase::B"*
148// CHECK: call x86_thiscallcc void @"\01??1B@dtor_in_second_nvbase@@UAE@XZ"
149// CHECK: (%"struct.dtor_in_second_nvbase::B"* %{{.*}})
150// CHECK: ret void
151}
152
153void foo() {
154 C c;
155}
156// DTORS2-LABEL: define weak x86_thiscallcc void @"\01??_EC@dtor_in_second_nvbase@@W3AEPAXI@Z"
157// DTORS2: (%"struct.dtor_in_second_nvbase::C"* %this, i32 %should_call_delete)
158// Do an adjustment from B* to C*.
159// DTORS2: getelementptr i8* %{{.*}}, i32 -4
160// DTORS2: bitcast i8* %{{.*}} to %"struct.dtor_in_second_nvbase::C"*
161// DTORS2: call x86_thiscallcc void @"\01??_GC@dtor_in_second_nvbase@@UAEPAXI@Z"
162// DTORS2: ret void
163
164}
165
166namespace test2 {
167// Just like dtor_in_second_nvbase, except put that in a vbase of a diamond.
168
169// C's dtor is in the non-primary base.
170struct A { virtual void f(); };
171struct B { virtual ~B(); };
172struct C : A, B { virtual ~C(); int c; };
173
174// Diamond hierarchy, with C as the shared vbase.
175struct D : virtual C { int d; };
176struct E : virtual C { int e; };
177struct F : D, E { ~F(); int f; };
178
179F::~F() {
180// CHECK-LABEL: define x86_thiscallcc void @"\01??1F@test2@@UAE@XZ"(%"struct.test2::F"*)
181// Do an adjustment from C vbase subobject to F as though F was the
182// complete type.
183// CHECK: getelementptr inbounds i8* %{{.*}}, i32 -20
184// CHECK: bitcast i8* %{{.*}} to %"struct.test2::F"*
185// CHECK: store %"struct.test2::F"*
186}
187
188void foo() {
189 F f;
190}
191// DTORS3-LABEL: define linkonce_odr x86_thiscallcc void @"\01??_DF@test2@@UAE@XZ"
192// Do an adjustment from C* to F*.
193// DTORS3: getelementptr i8* %{{.*}}, i32 20
194// DTORS3: bitcast i8* %{{.*}} to %"struct.test2::F"*
195// DTORS3: call x86_thiscallcc void @"\01??1F@test2@@UAE@XZ"
196// DTORS3: ret void
197
198}
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000199
200namespace constructors {
201
202struct A {
203 A() {}
204};
205
206struct B : A {
207 B();
208 ~B();
209};
210
211B::B() {
Stephen Lin9dc6eef2013-06-30 20:40:16 +0000212 // CHECK: define x86_thiscallcc %"struct.constructors::B"* @"\01??0B@constructors@@QAE@XZ"(%"struct.constructors::B"* returned %this)
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000213 // CHECK: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
214 // CHECK: ret
215}
216
217struct C : virtual A {
218 C();
219};
220
221C::C() {
Stephen Lin9dc6eef2013-06-30 20:40:16 +0000222 // CHECK: define x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* returned %this, i32 %is_most_derived)
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000223 // TODO: make sure this works in the Release build too;
224 // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
225 // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]]
226 // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
227 // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
228 //
229 // CHECK: [[INIT_VBASES]]
Reid Kleckner7810af02013-06-19 15:20:38 +0000230 // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::C"* %{{.*}} to i8*
231 // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0
232 // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to [2 x i32]**
233 // CHECK-NEXT: store [2 x i32]* @"\01??_8C@constructors@@7B@", [2 x i32]** %[[vbptr]]
Warren Hunt8f8bad72013-10-11 20:19:00 +0000234 // CHECK-NEXT: bitcast %"struct.constructors::C"* %{{.*}} to i8*
235 // CHECK-NEXT: getelementptr inbounds i8* %{{.*}}, i64 4
236 // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000237 // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
238 // CHECK-NEXT: br label %[[SKIP_VBASES]]
239 //
240 // CHECK: [[SKIP_VBASES]]
Timur Iskhodzhanov8b5987e2013-09-27 14:48:01 +0000241 // Class C does not define or override methods, so shouldn't change the vfptr.
242 // CHECK-NOT: @"\01??_7C@constructors@@6B@"
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000243 // CHECK: ret
244}
245
246void create_C() {
247 C c;
248 // CHECK: define void @"\01?create_C@constructors@@YAXXZ"()
249 // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %c, i32 1)
250 // CHECK: ret
251}
252
253struct D : C {
254 D();
255};
256
257D::D() {
Stephen Lin9dc6eef2013-06-30 20:40:16 +0000258 // CHECK: define x86_thiscallcc %"struct.constructors::D"* @"\01??0D@constructors@@QAE@XZ"(%"struct.constructors::D"* returned %this, i32 %is_most_derived) unnamed_addr
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000259 // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
260 // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]]
261 // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
262 // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
263 //
264 // CHECK: [[INIT_VBASES]]
Reid Kleckner7810af02013-06-19 15:20:38 +0000265 // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::D"* %{{.*}} to i8*
266 // CHECK-NEXT: %[[vbptr_off:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0
267 // CHECK-NEXT: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to [2 x i32]**
268 // CHECK-NEXT: store [2 x i32]* @"\01??_8D@constructors@@7B@", [2 x i32]** %[[vbptr]]
Warren Hunt8f8bad72013-10-11 20:19:00 +0000269 // CHECK-NEXT: bitcast %"struct.constructors::D"* %{{.*}} to i8*
270 // CHECK-NEXT: getelementptr inbounds i8* %{{.*}}, i64 4
271 // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000272 // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
273 // CHECK-NEXT: br label %[[SKIP_VBASES]]
274 //
275 // CHECK: [[SKIP_VBASES]]
276 // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0)
277 // CHECK: ret
278}
279
280struct E : virtual C {
281 E();
282};
283
284E::E() {
Stephen Lin9dc6eef2013-06-30 20:40:16 +0000285 // CHECK: define x86_thiscallcc %"struct.constructors::E"* @"\01??0E@constructors@@QAE@XZ"(%"struct.constructors::E"* returned %this, i32 %is_most_derived) unnamed_addr
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000286 // CHECK: store i32 %is_most_derived, i32* %[[IS_MOST_DERIVED_VAR:.*]], align 4
287 // CHECK: %[[IS_MOST_DERIVED_VAL:.*]] = load i32* %[[IS_MOST_DERIVED_VAR]]
288 // CHECK: %[[SHOULD_CALL_VBASE_CTORS:.*]] = icmp ne i32 %[[IS_MOST_DERIVED_VAL]], 0
289 // CHECK: br i1 %[[SHOULD_CALL_VBASE_CTORS]], label %[[INIT_VBASES:.*]], label %[[SKIP_VBASES:.*]]
290 //
291 // CHECK: [[INIT_VBASES]]
Reid Kleckner7810af02013-06-19 15:20:38 +0000292 // CHECK-NEXT: %[[this_i8:.*]] = bitcast %"struct.constructors::E"* %{{.*}} to i8*
293 // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 0
294 // CHECK-NEXT: %[[vbptr_E:.*]] = bitcast i8* %[[offs]] to [3 x i32]**
295 // CHECK-NEXT: store [3 x i32]* @"\01??_8E@constructors@@7B01@@", [3 x i32]** %[[vbptr_E]]
296 // CHECK-NEXT: %[[offs:.*]] = getelementptr inbounds i8* %[[this_i8]], i64 4
297 // CHECK-NEXT: %[[vbptr_C:.*]] = bitcast i8* %[[offs]] to [2 x i32]**
298 // CHECK-NEXT: store [2 x i32]* @"\01??_8E@constructors@@7BC@1@@", [2 x i32]** %[[vbptr_C]]
Warren Hunt8f8bad72013-10-11 20:19:00 +0000299 // CHECK-NEXT: bitcast %"struct.constructors::E"* %{{.*}} to i8*
300 // CHECK-NEXT: getelementptr inbounds i8* %{{.*}}, i64 4
301 // CHECK-NEXT: bitcast i8* %{{.*}} to %"struct.constructors::A"*
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000302 // CHECK-NEXT: call x86_thiscallcc %"struct.constructors::A"* @"\01??0A@constructors@@QAE@XZ"(%"struct.constructors::A"* %{{.*}})
303 // CHECK: call x86_thiscallcc %"struct.constructors::C"* @"\01??0C@constructors@@QAE@XZ"(%"struct.constructors::C"* %{{.*}}, i32 0)
304 // CHECK-NEXT: br label %[[SKIP_VBASES]]
305 //
306 // CHECK: [[SKIP_VBASES]]
307 // CHECK: ret
308}
309
Timur Iskhodzhanov40f2fa92013-08-04 17:30:04 +0000310// PR16735 - even abstract classes should have a constructor emitted.
311struct F {
312 F();
313 virtual void f() = 0;
314};
315
316F::F() {}
317// CHECK: define x86_thiscallcc %"struct.constructors::F"* @"\01??0F@constructors@@QAE@XZ"
318
Timur Iskhodzhanov57cbe5c2013-02-27 13:46:31 +0000319} // end namespace constructors
Reid Klecknere7de47e2013-07-22 13:51:44 +0000320
321namespace dtors {
322
323struct A {
324 ~A();
325};
326
327void call_nv_complete(A *a) {
328 a->~A();
329// CHECK: define void @"\01?call_nv_complete@dtors@@YAXPAUA@1@@Z"
330// CHECK: call x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ"
331// CHECK: ret
332}
333
334// CHECK: declare x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ"
335
336// Now try some virtual bases, where we need the complete dtor.
337
338struct B : virtual A { ~B(); };
339struct C : virtual A { ~C(); };
340struct D : B, C { ~D(); };
341
342void call_vbase_complete(D *d) {
343 d->~D();
344// CHECK: define void @"\01?call_vbase_complete@dtors@@YAXPAUD@1@@Z"
345// CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}})
346// CHECK: ret
347}
348
349// The complete dtor should call the base dtors for D and the vbase A (once).
350// CHECK: define linkonce_odr x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"
351// CHECK-NOT: call
352// CHECK: call x86_thiscallcc void @"\01??1D@dtors@@QAE@XZ"
353// CHECK-NOT: call
354// CHECK: call x86_thiscallcc void @"\01??1A@dtors@@QAE@XZ"
355// CHECK-NOT: call
356// CHECK: ret
357
358void destroy_d_complete() {
359 D d;
360// CHECK: define void @"\01?destroy_d_complete@dtors@@YAXXZ"
361// CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}})
362// CHECK: ret
363}
364
365// FIXME: Clang manually inlines the deletion, so we don't get a call to the
366// deleting dtor (_G). The only way to call deleting dtors currently is through
367// a vftable.
368void call_nv_deleting_dtor(D *d) {
369 delete d;
370// CHECK: define void @"\01?call_nv_deleting_dtor@dtors@@YAXPAUD@1@@Z"
371// CHECK: call x86_thiscallcc void @"\01??_DD@dtors@@QAE@XZ"(%"struct.dtors::D"* %{{[^,]+}})
372// CHECK: call void @"\01??3@YAXPAX@Z"
373// CHECK: ret
374}
375
376}
Reid Klecknera12cd282013-12-11 19:21:27 +0000377
Reid Kleckner89077a12013-12-17 19:46:40 +0000378namespace test1 {
379struct A { };
380struct B : virtual A {
381 B(int *a);
382 B(const char *a, ...);
383 __cdecl B(short *a);
384};
385B::B(int *a) {}
386B::B(const char *a, ...) {}
387B::B(short *a) {}
388// CHECK: define x86_thiscallcc %"struct.test1::B"* @"\01??0B@test1@@QAE@PAH@Z"
389// CHECK: (%"struct.test1::B"* returned %this, i32* %a, i32 %is_most_derived)
390// CHECK: define %"struct.test1::B"* @"\01??0B@test1@@QAA@PBDZZ"
391// CHECK: (%"struct.test1::B"* returned %this, i32 %is_most_derived, i8* %a, ...)
392
393// FIXME: This should be x86_thiscallcc. MSVC ignores explicit CCs on structors.
394// CHECK: define %"struct.test1::B"* @"\01??0B@test1@@QAA@PAF@Z"
395// CHECK: (%"struct.test1::B"* returned %this, i16* %a, i32 %is_most_derived)
396
397void construct_b() {
398 int a;
399 B b1(&a);
400 B b2("%d %d", 1, 2);
401}
402// CHECK-LABEL: define void @"\01?construct_b@test1@@YAXXZ"()
403// CHECK: call x86_thiscallcc %"struct.test1::B"* @"\01??0B@test1@@QAE@PAH@Z"
404// CHECK: (%"struct.test1::B"* {{.*}}, i32* {{.*}}, i32 1)
405// CHECK: call %"struct.test1::B"* (%"struct.test1::B"*, i32, i8*, ...)* @"\01??0B@test1@@QAA@PBDZZ"
406// CHECK: (%"struct.test1::B"* {{.*}}, i32 1, i8* {{.*}}, i32 1, i32 2)
407}
408
Reid Klecknera12cd282013-12-11 19:21:27 +0000409// Dtor thunks for classes in anonymous namespaces should be internal, not
410// linkonce_odr.
411namespace {
412struct A {
413 virtual ~A() { }
414};
415}
416void *getA() {
417 return (void*)new A();
418}
419// CHECK: define internal x86_thiscallcc void @"\01??_GA@?A@@UAEPAXI@Z"
David Blaikieabe1a392014-04-02 05:58:29 +0000420// CHECK: (%"struct.(anonymous namespace)::A"* %this, i32 %should_call_delete)
Reid Klecknera12cd282013-12-11 19:21:27 +0000421// CHECK: define internal x86_thiscallcc void @"\01??1A@?A@@UAE@XZ"
David Blaikieabe1a392014-04-02 05:58:29 +0000422// CHECK: (%"struct.(anonymous namespace)::A"* %this)