blob: 4c2d8506af7089cec60da8b0ba2b9e3ca5caa0b8 [file] [log] [blame]
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +00001// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
Stephen Hines651f13c2014-04-23 16:59:28 -07002// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
3// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +00004
5struct Empty {};
6
7struct EmptyWithCtor {
8 EmptyWithCtor() {}
9};
10
11struct Small {
12 int x;
13};
14
15// This is a C++11 trivial and standard-layout struct but not a C++03 POD.
16struct SmallCpp11NotCpp03Pod : Empty {
17 int x;
18};
19
20struct SmallWithCtor {
21 SmallWithCtor() {}
22 int x;
23};
24
Reid Kleckner9b601952013-06-21 12:45:15 +000025struct SmallWithDtor {
26 SmallWithDtor();
27 ~SmallWithDtor();
28 int x;
29};
30
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000031struct SmallWithVftable {
32 int x;
33 virtual void foo();
34};
35
36struct Medium {
37 int x, y;
38};
39
40struct MediumWithCopyCtor {
41 MediumWithCopyCtor();
42 MediumWithCopyCtor(const struct MediumWithCopyCtor &);
43 int x, y;
44};
45
46struct Big {
47 int a, b, c, d, e, f;
48};
49
Stephen Hines6bcf27b2014-05-29 04:14:42 -070050struct BigWithDtor {
51 BigWithDtor();
52 ~BigWithDtor();
53 int a, b, c, d, e, f;
54};
55
Stephen Hines651f13c2014-04-23 16:59:28 -070056// WIN32: declare void @"{{.*take_bools_and_chars.*}}"
57// WIN32: (<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor,
Stephen Hines6bcf27b2014-05-29 04:14:42 -070058// WIN32: i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>* inalloca)
Stephen Hines651f13c2014-04-23 16:59:28 -070059void take_bools_and_chars(char a, char b, SmallWithDtor c, char d, bool e, int f, bool g);
60void call_bools_and_chars() {
61 take_bools_and_chars('A', 'B', SmallWithDtor(), 'D', true, 13, false);
62}
63
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000064// Returning structs that fit into a register.
65Small small_return() { return Small(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000066// LINUX-LABEL: define void @_Z12small_returnv(%struct.Small* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000067// WIN32: define i32 @"\01?small_return@@YA?AUSmall@@XZ"()
68// WIN64: define i32 @"\01?small_return@@YA?AUSmall@@XZ"()
69
70Medium medium_return() { return Medium(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000071// LINUX-LABEL: define void @_Z13medium_returnv(%struct.Medium* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000072// WIN32: define i64 @"\01?medium_return@@YA?AUMedium@@XZ"()
73// WIN64: define i64 @"\01?medium_return@@YA?AUMedium@@XZ"()
74
75// Returning structs that fit into a register but are not POD.
76SmallCpp11NotCpp03Pod small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000077// LINUX-LABEL: define void @_Z20small_non_pod_returnv(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000078// WIN32: define void @"\01?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
79// WIN64: define void @"\01?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
80
81SmallWithCtor small_with_ctor_return() { return SmallWithCtor(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000082// LINUX-LABEL: define void @_Z22small_with_ctor_returnv(%struct.SmallWithCtor* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000083// WIN32: define void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
84// WIN64: define void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
85
86SmallWithVftable small_with_vftable_return() { return SmallWithVftable(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000087// LINUX-LABEL: define void @_Z25small_with_vftable_returnv(%struct.SmallWithVftable* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000088// WIN32: define void @"\01?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
89// WIN64: define void @"\01?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
90
91MediumWithCopyCtor medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000092// LINUX-LABEL: define void @_Z28medium_with_copy_ctor_returnv(%struct.MediumWithCopyCtor* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000093// WIN32: define void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
94// WIN64: define void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
95
96// Returning a large struct that doesn't fit into a register.
97Big big_return() { return Big(); }
Stephen Lin93ab6bf2013-08-15 06:47:53 +000098// LINUX-LABEL: define void @_Z10big_returnv(%struct.Big* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +000099// WIN32: define void @"\01?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
100// WIN64: define void @"\01?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
101
102
103void small_arg(Small s) {}
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700104// LINUX-LABEL: define void @_Z9small_arg5Small(i32 %s.0)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000105// WIN32: define void @"\01?small_arg@@YAXUSmall@@@Z"(%struct.Small* byval align 4 %s)
106// WIN64: define void @"\01?small_arg@@YAXUSmall@@@Z"(i32 %s.coerce)
107
108void medium_arg(Medium s) {}
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700109// LINUX-LABEL: define void @_Z10medium_arg6Medium(i32 %s.0, i32 %s.1)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000110// WIN32: define void @"\01?medium_arg@@YAXUMedium@@@Z"(%struct.Medium* byval align 4 %s)
111// WIN64: define void @"\01?medium_arg@@YAXUMedium@@@Z"(i64 %s.coerce)
112
113void small_arg_with_ctor(SmallWithCtor s) {}
Stephen Lin93ab6bf2013-08-15 06:47:53 +0000114// LINUX-LABEL: define void @_Z19small_arg_with_ctor13SmallWithCtor(%struct.SmallWithCtor* byval align 4 %s)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000115// WIN32: define void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(%struct.SmallWithCtor* byval align 4 %s)
116// WIN64: define void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.coerce)
117
Reid Kleckner9b601952013-06-21 12:45:15 +0000118// Test that dtors are invoked in the callee.
119void small_arg_with_dtor(SmallWithDtor s) {}
Stephen Hines651f13c2014-04-23 16:59:28 -0700120// WIN32: define void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(<{ %struct.SmallWithDtor }>* inalloca) {{.*}} {
121// WIN32: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
Reid Kleckner9b601952013-06-21 12:45:15 +0000122// WIN32: }
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700123// WIN64: define void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
Stephen Hines651f13c2014-04-23 16:59:28 -0700124// WIN64: call void @"\01??1SmallWithDtor@@QEAA@XZ"
Reid Kleckner9b601952013-06-21 12:45:15 +0000125// WIN64: }
126
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700127void call_small_arg_with_dtor() {
128 small_arg_with_dtor(SmallWithDtor());
129}
130// The temporary is copied, so it's destroyed in the caller as well as the
131// callee.
132// WIN64-LABEL: define void @"\01?call_small_arg_with_dtor@@YAXXZ"()
133// WIN64: call %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QEAA@XZ"
134// WIN64: call void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %{{.*}})
135// WIN64: call void @"\01??1SmallWithDtor@@QEAA@XZ"
136// WIN64: ret void
137
Reid Kleckner9b601952013-06-21 12:45:15 +0000138// Test that references aren't destroyed in the callee.
139void ref_small_arg_with_dtor(const SmallWithDtor &s) { }
Stephen Hines176edba2014-12-01 14:53:08 -0800140// WIN32: define void @"\01?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s) {{.*}} {
Reid Kleckner9b601952013-06-21 12:45:15 +0000141// WIN32-NOT: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
142// WIN32: }
Stephen Hines176edba2014-12-01 14:53:08 -0800143// WIN64-LABEL: define void @"\01?ref_small_arg_with_dtor@@YAXAEBUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700144
145void big_arg_with_dtor(BigWithDtor s) {}
146// WIN64-LABEL: define void @"\01?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %s)
147// WIN64: call void @"\01??1BigWithDtor@@QEAA@XZ"
148// WIN64: }
149
150void call_big_arg_with_dtor() {
151 big_arg_with_dtor(BigWithDtor());
152}
153// We can elide the copy of the temporary in the caller, because this object is
154// larger than 8 bytes and is passed indirectly.
155// WIN64-LABEL: define void @"\01?call_big_arg_with_dtor@@YAXXZ"()
156// WIN64: call %struct.BigWithDtor* @"\01??0BigWithDtor@@QEAA@XZ"
157// WIN64: call void @"\01?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %{{.*}})
158// WIN64-NOT: call void @"\01??1BigWithDtor@@QEAA@XZ"
159// WIN64: ret void
Reid Kleckner9b601952013-06-21 12:45:15 +0000160
161// Test that temporaries passed by reference are destroyed in the caller.
162void temporary_ref_with_dtor() {
163 ref_small_arg_with_dtor(SmallWithDtor());
164}
165// WIN32: define void @"\01?temporary_ref_with_dtor@@YAXXZ"() {{.*}} {
166// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
167// WIN32: call void @"\01?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"
168// WIN32: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
169// WIN32: }
170
171void takes_two_by_val_with_dtor(SmallWithDtor a, SmallWithDtor b);
172void eh_cleanup_arg_with_dtor() {
173 takes_two_by_val_with_dtor(SmallWithDtor(), SmallWithDtor());
174}
175// When exceptions are off, we don't have any cleanups. See
176// microsoft-abi-exceptions.cpp for these cleanups.
177// WIN32: define void @"\01?eh_cleanup_arg_with_dtor@@YAXXZ"() {{.*}} {
178// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
179// WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
180// WIN32: call void @"\01?takes_two_by_val_with_dtor@@YAXUSmallWithDtor@@0@Z"
181// WIN32-NOT: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
182// WIN32: }
183
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000184void small_arg_with_vftable(SmallWithVftable s) {}
Stephen Lin93ab6bf2013-08-15 06:47:53 +0000185// LINUX-LABEL: define void @_Z22small_arg_with_vftable16SmallWithVftable(%struct.SmallWithVftable* %s)
Stephen Hines651f13c2014-04-23 16:59:28 -0700186// WIN32: define void @"\01?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(<{ %struct.SmallWithVftable }>* inalloca)
187// WIN64: define void @"\01?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* %s)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000188
189void medium_arg_with_copy_ctor(MediumWithCopyCtor s) {}
Stephen Lin93ab6bf2013-08-15 06:47:53 +0000190// LINUX-LABEL: define void @_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(%struct.MediumWithCopyCtor* %s)
Stephen Hines651f13c2014-04-23 16:59:28 -0700191// WIN32: define void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(<{ %struct.MediumWithCopyCtor }>* inalloca)
192// WIN64: define void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000193
194void big_arg(Big s) {}
Stephen Lin93ab6bf2013-08-15 06:47:53 +0000195// LINUX-LABEL: define void @_Z7big_arg3Big(%struct.Big* byval align 4 %s)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000196// WIN32: define void @"\01?big_arg@@YAXUBig@@@Z"(%struct.Big* byval align 4 %s)
197// WIN64: define void @"\01?big_arg@@YAXUBig@@@Z"(%struct.Big* %s)
198
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000199class Class {
200 public:
201 Small thiscall_method_small() { return Small(); }
202 // LINUX: define {{.*}} void @_ZN5Class21thiscall_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700203 // WIN32: define {{.*}} x86_thiscallcc void @"\01?thiscall_method_small@Class@@QAE?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
204 // WIN64: define linkonce_odr void @"\01?thiscall_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000205
206 SmallWithCtor thiscall_method_small_with_ctor() { return SmallWithCtor(); }
207 // LINUX: define {{.*}} void @_ZN5Class31thiscall_method_small_with_ctorEv(%struct.SmallWithCtor* noalias sret %agg.result, %class.Class* %this)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700208 // WIN32: define {{.*}} x86_thiscallcc void @"\01?thiscall_method_small_with_ctor@Class@@QAE?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
209 // WIN64: define linkonce_odr void @"\01?thiscall_method_small_with_ctor@Class@@QEAA?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000210
211 Small __cdecl cdecl_method_small() { return Small(); }
212 // LINUX: define {{.*}} void @_ZN5Class18cdecl_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700213 // WIN32: define {{.*}} void @"\01?cdecl_method_small@Class@@QAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
214 // WIN64: define linkonce_odr void @"\01?cdecl_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000215
216 Big __cdecl cdecl_method_big() { return Big(); }
217 // LINUX: define {{.*}} void @_ZN5Class16cdecl_method_bigEv(%struct.Big* noalias sret %agg.result, %class.Class* %this)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700218 // WIN32: define {{.*}} void @"\01?cdecl_method_big@Class@@QAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
219 // WIN64: define linkonce_odr void @"\01?cdecl_method_big@Class@@QEAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000220
221 void thiscall_method_arg(Empty s) {}
222 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Empty(%class.Class* %this)
223 // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUEmpty@@@Z"(%class.Class* %this, %struct.Empty* byval align 4 %s)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700224 // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUEmpty@@@Z"(%class.Class* %this, i8 %s.coerce)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000225
226 void thiscall_method_arg(EmptyWithCtor s) {}
227 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13EmptyWithCtor(%class.Class* %this)
228 // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUEmptyWithCtor@@@Z"(%class.Class* %this, %struct.EmptyWithCtor* byval align 4 %s)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700229 // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUEmptyWithCtor@@@Z"(%class.Class* %this, i8 %s.coerce)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000230
231 void thiscall_method_arg(Small s) {}
Pirama Arumuga Nainar33337ca2015-05-06 11:48:57 -0700232 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(%class.Class* %this, i32 %s.0)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000233 // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmall@@@Z"(%class.Class* %this, %struct.Small* byval align 4 %s)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700234 // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUSmall@@@Z"(%class.Class* %this, i32 %s.coerce)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000235
236 void thiscall_method_arg(SmallWithCtor s) {}
237 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13SmallWithCtor(%class.Class* %this, %struct.SmallWithCtor* byval align 4 %s)
238 // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmallWithCtor@@@Z"(%class.Class* %this, %struct.SmallWithCtor* byval align 4 %s)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700239 // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUSmallWithCtor@@@Z"(%class.Class* %this, i32 %s.coerce)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000240
241 void thiscall_method_arg(Big s) {}
242 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE3Big(%class.Class* %this, %struct.Big* byval align 4 %s)
243 // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUBig@@@Z"(%class.Class* %this, %struct.Big* byval align 4 %s)
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700244 // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUBig@@@Z"(%class.Class* %this, %struct.Big* %s)
Timur Iskhodzhanoved23bdf2013-04-17 12:54:10 +0000245};
246
247void use_class() {
248 Class c;
249 c.thiscall_method_small();
250 c.thiscall_method_small_with_ctor();
251
252 c.cdecl_method_small();
253 c.cdecl_method_big();
254
255 c.thiscall_method_arg(Empty());
256 c.thiscall_method_arg(EmptyWithCtor());
257 c.thiscall_method_arg(Small());
258 c.thiscall_method_arg(SmallWithCtor());
259 c.thiscall_method_arg(Big());
260}
Reid Kleckner9b601952013-06-21 12:45:15 +0000261
262struct X {
263 X();
264 ~X();
265};
266void g(X) {
267}
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700268// WIN32: define void @"\01?g@@YAXUX@@@Z"(<{ %struct.X, [3 x i8] }>* inalloca) {{.*}} {
Stephen Hines651f13c2014-04-23 16:59:28 -0700269// WIN32: call x86_thiscallcc void @"\01??1X@@QAE@XZ"(%struct.X* {{.*}})
Reid Kleckner9b601952013-06-21 12:45:15 +0000270// WIN32: }
271void f() {
272 g(X());
273}
274// WIN32: define void @"\01?f@@YAXXZ"() {{.*}} {
275// WIN32-NOT: call {{.*}} @"\01??1X@@QAE@XZ"
276// WIN32: }
Stephen Hines651f13c2014-04-23 16:59:28 -0700277
278
279namespace test2 {
280// We used to crash on this due to the mixture of POD byval and non-trivial
281// byval.
282
283struct NonTrivial {
284 NonTrivial();
285 NonTrivial(const NonTrivial &o);
286 ~NonTrivial();
287 int a;
288};
289struct POD { int b; };
290
291int foo(NonTrivial a, POD b);
292void bar() {
293 POD b;
294 b.b = 13;
295 int c = foo(NonTrivial(), b);
296}
297// WIN32-LABEL: define void @"\01?bar@test2@@YAXXZ"() {{.*}} {
298// WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ %"struct.test2::NonTrivial", %"struct.test2::POD" }>]]
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700299// WIN32: getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
Stephen Hines651f13c2014-04-23 16:59:28 -0700300// WIN32: call void @llvm.memcpy
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700301// WIN32: getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
Stephen Hines651f13c2014-04-23 16:59:28 -0700302// WIN32: call x86_thiscallcc %"struct.test2::NonTrivial"* @"\01??0NonTrivial@test2@@QAE@XZ"
303// WIN32: call i32 @"\01?foo@test2@@YAHUNonTrivial@1@UPOD@1@@Z"([[argmem_ty]]* inalloca %argmem)
304// WIN32: ret void
305// WIN32: }
306
307}
308
Stephen Hines6bcf27b2014-05-29 04:14:42 -0700309namespace test3 {
310
311// Check that we padded the inalloca struct to a multiple of 4.
312struct NonTrivial {
313 NonTrivial();
314 NonTrivial(const NonTrivial &o);
315 ~NonTrivial();
316 int a;
317};
318void foo(NonTrivial a, bool b) { }
319// WIN32-LABEL: define void @"\01?foo@test3@@YAXUNonTrivial@1@_N@Z"(<{ %"struct.test3::NonTrivial", i8, [3 x i8] }>* inalloca)
320
321}
322
Stephen Hines651f13c2014-04-23 16:59:28 -0700323// We would crash here because the later definition of ForwardDeclare1 results
324// in a different IR type for the value we want to store. However, the alloca's
325// type will use the argument type selected by fn1.
326struct ForwardDeclare1;
327
328typedef void (*FnPtr1)(ForwardDeclare1);
329void fn1(FnPtr1 a, SmallWithDtor b) { }
330
331struct ForwardDeclare1 {};
332
333void fn2(FnPtr1 a, SmallWithDtor b) { fn1(a, b); };
334// WIN32-LABEL: define void @"\01?fn2@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700335// WIN32: %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]], [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]]* %{{.*}}, i32 0, i32 0
Stephen Hines651f13c2014-04-23 16:59:28 -0700336// WIN32: %[[a1:[^ ]*]] = bitcast {}** %[[a]] to void [[dst_ty:\(%struct.ForwardDeclare1\*\)\*]]*
337// WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty]]
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700338// WIN32: %[[gep1:[^ ]*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
Stephen Hines651f13c2014-04-23 16:59:28 -0700339// WIN32: %[[bc1:[^ ]*]] = bitcast %struct.SmallWithDtor* %[[gep1]] to i8*
340// WIN32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[bc1]], i8* {{.*}}, i32 4, i32 4, i1 false)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700341// WIN32: %[[a2:[^ ]*]] = load void [[dst_ty]], void [[dst_ty]]* %[[a1]], align 4
342// WIN32: %[[gep2:[^ ]*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
Stephen Hines651f13c2014-04-23 16:59:28 -0700343// WIN32: %[[addr:[^ ]*]] = bitcast {}** %[[gep2]] to void [[dst_ty]]*
344// WIN32: store void [[dst_ty]] %[[a2]], void [[dst_ty]]* %[[addr]], align 4
345// WIN32: call void @"\01?fn1@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"([[argmem_ty]]* inalloca %[[argmem]])