1 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
2 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
3 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA %s
4 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
5 
6 struct Empty {};
7 
8 struct EmptyWithCtor {
9   EmptyWithCtor() {}
10 };
11 
12 struct Small {
13   int x;
14 };
15 
16 // This is a C++11 trivial and standard-layout struct but not a C++03 POD.
17 struct SmallCpp11NotCpp03Pod : Empty {
18   int x;
19 };
20 
21 struct SmallWithCtor {
22   SmallWithCtor() {}
23   int x;
24 };
25 
26 struct Multibyte {
27   char a, b, c, d;
28 };
29 
30 struct Packed {
31   short a;
32   int b;
33   short c;
34 };
35 
36 struct SmallWithDtor {
37   SmallWithDtor();
38   ~SmallWithDtor();
39   int x;
40 };
41 
42 struct SmallWithVftable {
43   int x;
44   virtual void foo();
45 };
46 
47 struct Medium {
48   int x, y;
49 };
50 
51 struct MediumWithCopyCtor {
52   MediumWithCopyCtor();
53   MediumWithCopyCtor(const struct MediumWithCopyCtor &);
54   int x, y;
55 };
56 
57 struct Big {
58   int a, b, c, d, e, f;
59 };
60 
61 struct BigWithDtor {
62   BigWithDtor();
63   ~BigWithDtor();
64   int a, b, c, d, e, f;
65 };
66 
67 struct BaseNoByval : Small {
68   int bb;
69 };
70 
71 // WIN32: declare dso_local void @"{{.*take_bools_and_chars.*}}"
72 // WIN32:       (<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor,
73 // WIN32:           i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>* inalloca)
74 void take_bools_and_chars(char a, char b, SmallWithDtor c, char d, bool e, int f, bool g);
75 void call_bools_and_chars() {
76   take_bools_and_chars('A', 'B', SmallWithDtor(), 'D', true, 13, false);
77 }
78 
79 // Returning structs that fit into a register.
80 Small small_return() { return Small(); }
81 // LINUX-LABEL: define void @_Z12small_returnv(%struct.Small* noalias sret %agg.result)
82 // WIN32: define dso_local i32 @"\01?small_return@@YA?AUSmall@@XZ"()
83 // WIN64: define dso_local i32 @"\01?small_return@@YA?AUSmall@@XZ"()
84 
85 Medium medium_return() { return Medium(); }
86 // LINUX-LABEL: define void @_Z13medium_returnv(%struct.Medium* noalias sret %agg.result)
87 // WIN32: define dso_local i64 @"\01?medium_return@@YA?AUMedium@@XZ"()
88 // WIN64: define dso_local i64 @"\01?medium_return@@YA?AUMedium@@XZ"()
89 
90 // Returning structs that fit into a register but are not POD.
91 SmallCpp11NotCpp03Pod small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
92 // LINUX-LABEL: define void @_Z20small_non_pod_returnv(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
93 // WIN32: define dso_local void @"\01?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
94 // WIN64: define dso_local void @"\01?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
95 
96 SmallWithCtor small_with_ctor_return() { return SmallWithCtor(); }
97 // LINUX-LABEL: define void @_Z22small_with_ctor_returnv(%struct.SmallWithCtor* noalias sret %agg.result)
98 // WIN32: define dso_local void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
99 // WIN64: define dso_local void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
100 // FIXME: The 'sret' mark here doesn't seem to be enough to convince LLVM to
101 // preserve the hidden sret pointer in R0 across the function.
102 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
103 
104 SmallWithVftable small_with_vftable_return() { return SmallWithVftable(); }
105 // LINUX-LABEL: define void @_Z25small_with_vftable_returnv(%struct.SmallWithVftable* noalias sret %agg.result)
106 // WIN32: define dso_local void @"\01?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
107 // WIN64: define dso_local void @"\01?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
108 
109 MediumWithCopyCtor medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
110 // LINUX-LABEL: define void @_Z28medium_with_copy_ctor_returnv(%struct.MediumWithCopyCtor* noalias sret %agg.result)
111 // WIN32: define dso_local void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
112 // WIN64: define dso_local void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
113 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
114 
115 // Returning a large struct that doesn't fit into a register.
116 Big big_return() { return Big(); }
117 // LINUX-LABEL: define void @_Z10big_returnv(%struct.Big* noalias sret %agg.result)
118 // WIN32: define dso_local void @"\01?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
119 // WIN64: define dso_local void @"\01?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
120 
121 
122 void small_arg(Small s) {}
123 // LINUX-LABEL: define void @_Z9small_arg5Small(i32 %s.0)
124 // WIN32: define dso_local void @"\01?small_arg@@YAXUSmall@@@Z"(i32 %s.0)
125 // WIN64: define dso_local void @"\01?small_arg@@YAXUSmall@@@Z"(i32 %s.coerce)
126 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?small_arg@@YAXUSmall@@@Z"([1 x i32] %s.coerce)
127 
128 void medium_arg(Medium s) {}
129 // LINUX-LABEL: define void @_Z10medium_arg6Medium(i32 %s.0, i32 %s.1)
130 // WIN32: define dso_local void @"\01?medium_arg@@YAXUMedium@@@Z"(i32 %s.0, i32 %s.1)
131 // WIN64: define dso_local void @"\01?medium_arg@@YAXUMedium@@@Z"(i64 %s.coerce)
132 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?medium_arg@@YAXUMedium@@@Z"([2 x i32] %s.coerce)
133 
134 void base_no_byval_arg(BaseNoByval s) {}
135 // LINUX-LABEL: define void @_Z17base_no_byval_arg11BaseNoByval(%struct.BaseNoByval* byval align 4 %s)
136 // WIN32: define dso_local void @"\01?base_no_byval_arg@@YAXUBaseNoByval@@@Z"(i32 %s.0, i32 %s.1)
137 // WIN64: define dso_local void @"\01?base_no_byval_arg@@YAXUBaseNoByval@@@Z"(i64 %s.coerce)
138 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?base_no_byval_arg@@YAXUBaseNoByval@@@Z"([2 x i32] %s.coerce)
139 
140 void small_arg_with_ctor(SmallWithCtor s) {}
141 // LINUX-LABEL: define void @_Z19small_arg_with_ctor13SmallWithCtor(%struct.SmallWithCtor* byval align 4 %s)
142 // WIN32: define dso_local void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.0)
143 // WIN64: define dso_local void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.coerce)
144 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"([1 x i32] %s.coerce)
145 
146 // FIXME: We could coerce to a series of i32s here if we wanted to.
147 void multibyte_arg(Multibyte s) {}
148 // LINUX-LABEL: define void @_Z13multibyte_arg9Multibyte(%struct.Multibyte* byval align 4 %s)
149 // WIN32: define dso_local void @"\01?multibyte_arg@@YAXUMultibyte@@@Z"(%struct.Multibyte* byval align 4 %s)
150 // WIN64: define dso_local void @"\01?multibyte_arg@@YAXUMultibyte@@@Z"(i32 %s.coerce)
151 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?multibyte_arg@@YAXUMultibyte@@@Z"([1 x i32] %s.coerce)
152 
153 void packed_arg(Packed s) {}
154 // LINUX-LABEL: define void @_Z10packed_arg6Packed(%struct.Packed* byval align 4 %s)
155 // WIN32: define dso_local void @"\01?packed_arg@@YAXUPacked@@@Z"(%struct.Packed* byval align 4 %s)
156 // WIN64: define dso_local void @"\01?packed_arg@@YAXUPacked@@@Z"(%struct.Packed* %s)
157 
158 // Test that dtors are invoked in the callee.
159 void small_arg_with_dtor(SmallWithDtor s) {}
160 // WIN32: define dso_local void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(<{ %struct.SmallWithDtor }>* inalloca) {{.*}} {
161 // WIN32:   call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
162 // WIN32: }
163 // WIN64: define dso_local void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
164 // WIN64:   call void @"\01??1SmallWithDtor@@QEAA@XZ"
165 // WIN64: }
166 
167 // FIXME: MSVC incompatible!
168 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(%struct.SmallWithDtor* %s) {{.*}} {
169 // WOA:   call arm_aapcs_vfpcc void @"\01??1SmallWithDtor@@QAA@XZ"(%struct.SmallWithDtor* %s)
170 // WOA: }
171 
172 void call_small_arg_with_dtor() {
173   small_arg_with_dtor(SmallWithDtor());
174 }
175 // The temporary is copied, so it's destroyed in the caller as well as the
176 // callee.
177 // WIN64-LABEL: define dso_local void @"\01?call_small_arg_with_dtor@@YAXXZ"()
178 // WIN64:   call %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QEAA@XZ"
179 // WIN64:   call void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %{{.*}})
180 // WIN64:   call void @"\01??1SmallWithDtor@@QEAA@XZ"
181 // WIN64:   ret void
182 
183 // Test that references aren't destroyed in the callee.
184 void ref_small_arg_with_dtor(const SmallWithDtor &s) { }
185 // WIN32: define dso_local void @"\01?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s) {{.*}} {
186 // WIN32-NOT:   call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
187 // WIN32: }
188 // WIN64-LABEL: define dso_local void @"\01?ref_small_arg_with_dtor@@YAXAEBUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s)
189 
190 void big_arg_with_dtor(BigWithDtor s) {}
191 // WIN64-LABEL: define dso_local void @"\01?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %s)
192 // WIN64:   call void @"\01??1BigWithDtor@@QEAA@XZ"
193 // WIN64: }
194 
195 void call_big_arg_with_dtor() {
196   big_arg_with_dtor(BigWithDtor());
197 }
198 // We can elide the copy of the temporary in the caller, because this object is
199 // larger than 8 bytes and is passed indirectly.
200 // WIN64-LABEL: define dso_local void @"\01?call_big_arg_with_dtor@@YAXXZ"()
201 // WIN64:   call %struct.BigWithDtor* @"\01??0BigWithDtor@@QEAA@XZ"
202 // WIN64:   call void @"\01?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %{{.*}})
203 // WIN64-NOT: call void @"\01??1BigWithDtor@@QEAA@XZ"
204 // WIN64:   ret void
205 
206 // Test that temporaries passed by reference are destroyed in the caller.
207 void temporary_ref_with_dtor() {
208   ref_small_arg_with_dtor(SmallWithDtor());
209 }
210 // WIN32: define dso_local void @"\01?temporary_ref_with_dtor@@YAXXZ"() {{.*}} {
211 // WIN32:   call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
212 // WIN32:   call void @"\01?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"
213 // WIN32:   call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
214 // WIN32: }
215 
216 void takes_two_by_val_with_dtor(SmallWithDtor a, SmallWithDtor b);
217 void eh_cleanup_arg_with_dtor() {
218   takes_two_by_val_with_dtor(SmallWithDtor(), SmallWithDtor());
219 }
220 //   When exceptions are off, we don't have any cleanups.  See
221 //   microsoft-abi-exceptions.cpp for these cleanups.
222 // WIN32: define dso_local void @"\01?eh_cleanup_arg_with_dtor@@YAXXZ"() {{.*}} {
223 // WIN32:   call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
224 // WIN32:   call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
225 // WIN32:   call void @"\01?takes_two_by_val_with_dtor@@YAXUSmallWithDtor@@0@Z"
226 // WIN32-NOT: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
227 // WIN32: }
228 
229 void small_arg_with_vftable(SmallWithVftable s) {}
230 // LINUX-LABEL: define void @_Z22small_arg_with_vftable16SmallWithVftable(%struct.SmallWithVftable* %s)
231 // WIN32: define dso_local void @"\01?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(<{ %struct.SmallWithVftable }>* inalloca)
232 // WIN64: define dso_local void @"\01?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* %s)
233 
234 void medium_arg_with_copy_ctor(MediumWithCopyCtor s) {}
235 // LINUX-LABEL: define void @_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(%struct.MediumWithCopyCtor* %s)
236 // WIN32: define dso_local void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(<{ %struct.MediumWithCopyCtor }>* inalloca)
237 // WIN64: define dso_local void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
238 // WOA: define dso_local arm_aapcs_vfpcc void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
239 
240 void big_arg(Big s) {}
241 // LINUX-LABEL: define void @_Z7big_arg3Big(%struct.Big* byval align 4 %s)
242 // WIN32: define dso_local void @"\01?big_arg@@YAXUBig@@@Z"(%struct.Big* byval align 4 %s)
243 // WIN64: define dso_local void @"\01?big_arg@@YAXUBig@@@Z"(%struct.Big* %s)
244 
245 // PR27607: We would attempt to load i32 value out of the reference instead of
246 // just loading the pointer from the struct during argument expansion.
247 struct RefField {
248   RefField(int &x);
249   int &x;
250 };
251 void takes_ref_field(RefField s) {}
252 // LINUX-LABEL: define void @_Z15takes_ref_field8RefField(%struct.RefField* byval align 4 %s)
253 // WIN32: define dso_local void @"\01?takes_ref_field@@YAXURefField@@@Z"(i32* %s.0)
254 // WIN64: define dso_local void @"\01?takes_ref_field@@YAXURefField@@@Z"(i64 %s.coerce)
255 
256 void pass_ref_field() {
257   int x;
258   takes_ref_field(RefField(x));
259 }
260 // LINUX-LABEL: define void @_Z14pass_ref_fieldv()
261 // LINUX: call void @_Z15takes_ref_field8RefField(%struct.RefField* byval align 4 %{{.*}})
262 // WIN32-LABEL: define dso_local void @"\01?pass_ref_field@@YAXXZ"()
263 // WIN32: call void @"\01?takes_ref_field@@YAXURefField@@@Z"(i32* %{{.*}})
264 // WIN64-LABEL: define dso_local void @"\01?pass_ref_field@@YAXXZ"()
265 // WIN64: call void @"\01?takes_ref_field@@YAXURefField@@@Z"(i64 %{{.*}})
266 
267 class Class {
268  public:
269   Small thiscall_method_small() { return Small(); }
270   // LINUX: define {{.*}} void @_ZN5Class21thiscall_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
271   // WIN32: define {{.*}} x86_thiscallcc void @"\01?thiscall_method_small@Class@@QAE?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
272   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
273 
274   SmallWithCtor thiscall_method_small_with_ctor() { return SmallWithCtor(); }
275   // LINUX: define {{.*}} void @_ZN5Class31thiscall_method_small_with_ctorEv(%struct.SmallWithCtor* noalias sret %agg.result, %class.Class* %this)
276   // WIN32: define {{.*}} x86_thiscallcc void @"\01?thiscall_method_small_with_ctor@Class@@QAE?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
277   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_small_with_ctor@Class@@QEAA?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
278 
279   Small __cdecl cdecl_method_small() { return Small(); }
280   // LINUX: define {{.*}} void @_ZN5Class18cdecl_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
281   // WIN32: define {{.*}} void @"\01?cdecl_method_small@Class@@QAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
282   // WIN64: define linkonce_odr dso_local void @"\01?cdecl_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
283 
284   Big __cdecl cdecl_method_big() { return Big(); }
285   // LINUX: define {{.*}} void @_ZN5Class16cdecl_method_bigEv(%struct.Big* noalias sret %agg.result, %class.Class* %this)
286   // WIN32: define {{.*}} void @"\01?cdecl_method_big@Class@@QAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
287   // WIN64: define linkonce_odr dso_local void @"\01?cdecl_method_big@Class@@QEAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
288 
289   void thiscall_method_arg(Empty s) {}
290   // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Empty(%class.Class* %this)
291   // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUEmpty@@@Z"(%class.Class* %this, %struct.Empty* byval align 4 %s)
292   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_arg@Class@@QEAAXUEmpty@@@Z"(%class.Class* %this, i8 %s.coerce)
293 
294   void thiscall_method_arg(EmptyWithCtor s) {}
295   // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13EmptyWithCtor(%class.Class* %this)
296   // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUEmptyWithCtor@@@Z"(%class.Class* %this, %struct.EmptyWithCtor* byval align 4 %s)
297   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_arg@Class@@QEAAXUEmptyWithCtor@@@Z"(%class.Class* %this, i8 %s.coerce)
298 
299   void thiscall_method_arg(Small s) {}
300   // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(%class.Class* %this, i32 %s.0)
301   // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmall@@@Z"(%class.Class* %this, i32 %s.0)
302   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_arg@Class@@QEAAXUSmall@@@Z"(%class.Class* %this, i32 %s.coerce)
303 
304   void thiscall_method_arg(SmallWithCtor s) {}
305   // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13SmallWithCtor(%class.Class* %this, %struct.SmallWithCtor* byval align 4 %s)
306   // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmallWithCtor@@@Z"(%class.Class* %this, i32 %s.0)
307   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_arg@Class@@QEAAXUSmallWithCtor@@@Z"(%class.Class* %this, i32 %s.coerce)
308 
309   void thiscall_method_arg(Big s) {}
310   // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE3Big(%class.Class* %this, %struct.Big* byval align 4 %s)
311   // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUBig@@@Z"(%class.Class* %this, %struct.Big* byval align 4 %s)
312   // WIN64: define linkonce_odr dso_local void @"\01?thiscall_method_arg@Class@@QEAAXUBig@@@Z"(%class.Class* %this, %struct.Big* %s)
313 };
314 
315 void use_class() {
316   Class c;
317   c.thiscall_method_small();
318   c.thiscall_method_small_with_ctor();
319 
320   c.cdecl_method_small();
321   c.cdecl_method_big();
322 
323   c.thiscall_method_arg(Empty());
324   c.thiscall_method_arg(EmptyWithCtor());
325   c.thiscall_method_arg(Small());
326   c.thiscall_method_arg(SmallWithCtor());
327   c.thiscall_method_arg(Big());
328 }
329 
330 struct X {
331   X();
332   ~X();
333 };
334 void g(X) {
335 }
336 // WIN32: define dso_local void @"\01?g@@YAXUX@@@Z"(<{ %struct.X, [3 x i8] }>* inalloca) {{.*}} {
337 // WIN32:   call x86_thiscallcc void @"\01??1X@@QAE@XZ"(%struct.X* {{.*}})
338 // WIN32: }
339 void f() {
340   g(X());
341 }
342 // WIN32: define dso_local void @"\01?f@@YAXXZ"() {{.*}} {
343 // WIN32-NOT: call {{.*}} @"\01??1X@@QAE@XZ"
344 // WIN32: }
345 
346 
347 namespace test2 {
348 // We used to crash on this due to the mixture of POD byval and non-trivial
349 // byval.
350 
351 struct NonTrivial {
352   NonTrivial();
353   NonTrivial(const NonTrivial &o);
354   ~NonTrivial();
355   int a;
356 };
357 struct POD { int b; };
358 
359 int foo(NonTrivial a, POD b);
360 void bar() {
361   POD b;
362   b.b = 13;
363   int c = foo(NonTrivial(), b);
364 }
365 // WIN32-LABEL: define dso_local void @"\01?bar@test2@@YAXXZ"() {{.*}} {
366 // WIN32:   %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ %"struct.test2::NonTrivial", %"struct.test2::POD" }>]]
367 // WIN32:   getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
368 // WIN32:   call void @llvm.memcpy
369 // WIN32:   getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
370 // WIN32:   call x86_thiscallcc %"struct.test2::NonTrivial"* @"\01??0NonTrivial@test2@@QAE@XZ"
371 // WIN32:   call i32 @"\01?foo@test2@@YAHUNonTrivial@1@UPOD@1@@Z"([[argmem_ty]]* inalloca %argmem)
372 // WIN32:   ret void
373 // WIN32: }
374 
375 }
376 
377 namespace test3 {
378 
379 // Check that we padded the inalloca struct to a multiple of 4.
380 struct NonTrivial {
381   NonTrivial();
382   NonTrivial(const NonTrivial &o);
383   ~NonTrivial();
384   int a;
385 };
386 void foo(NonTrivial a, bool b) { }
387 // WIN32-LABEL: define dso_local void @"\01?foo@test3@@YAXUNonTrivial@1@_N@Z"(<{ %"struct.test3::NonTrivial", i8, [3 x i8] }>* inalloca)
388 
389 }
390 
391 // We would crash here because the later definition of ForwardDeclare1 results
392 // in a different IR type for the value we want to store.  However, the alloca's
393 // type will use the argument type selected by fn1.
394 struct ForwardDeclare1;
395 
396 typedef void (*FnPtr1)(ForwardDeclare1);
397 void fn1(FnPtr1 a, SmallWithDtor b) { }
398 
399 struct ForwardDeclare1 {};
400 
401 void fn2(FnPtr1 a, SmallWithDtor b) { fn1(a, b); };
402 // WIN32-LABEL: define dso_local void @"\01?fn2@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"
403 // WIN32:   %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]], [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]]* %{{.*}}, i32 0, i32 0
404 // WIN32:   %[[a1:[^ ]*]] = bitcast {}** %[[a]] to void [[dst_ty:\(%struct.ForwardDeclare1\*\)\*]]*
405 // WIN32:   %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty]]
406 // WIN32:   %[[gep1:[^ ]*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 1
407 // WIN32:   %[[bc1:[^ ]*]] = bitcast %struct.SmallWithDtor* %[[gep1]] to i8*
408 // WIN32:   call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %[[bc1]], i8* align 4 {{.*}}, i32 4, i1 false)
409 // WIN32:   %[[a2:[^ ]*]] = load void [[dst_ty]], void [[dst_ty]]* %[[a1]], align 4
410 // WIN32:   %[[gep2:[^ ]*]] = getelementptr inbounds [[argmem_ty]], [[argmem_ty]]* %[[argmem]], i32 0, i32 0
411 // WIN32:   %[[addr:[^ ]*]] = bitcast {}** %[[gep2]] to void [[dst_ty]]*
412 // WIN32:   store void [[dst_ty]] %[[a2]], void [[dst_ty]]* %[[addr]], align 4
413 // WIN32:   call void @"\01?fn1@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"([[argmem_ty]]* inalloca %[[argmem]])
414 
415 namespace pr30293 {
416 // Virtual methods living in a secondary vtable take i8* as their 'this'
417 // parameter because the 'this' parameter on entry points to the secondary
418 // vptr. We used to have a bug where we didn't apply this rule consistently,
419 // and it would cause assertion failures when used with inalloca.
420 struct A {
421   virtual void f();
422 };
423 struct B {
424   virtual void __cdecl h(SmallWithDtor);
425 };
426 struct C final : A, B {
427   void g();
428   void __cdecl h(SmallWithDtor);
429   void f();
430 };
431 void C::g() { return h(SmallWithDtor()); }
432 
433 // WIN32-LABEL: define dso_local x86_thiscallcc void @"\01?g@C@pr30293@@QAEXXZ"(%"struct.pr30293::C"* %this)
434 // WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
435 // WIN32: call void @"\01?h@C@pr30293@@UAAXUSmallWithDtor@@@Z"(<{ i8*, %struct.SmallWithDtor }>* inalloca %{{[^,)]*}})
436 // WIN32: declare dso_local void @"\01?h@C@pr30293@@UAAXUSmallWithDtor@@@Z"(<{ i8*, %struct.SmallWithDtor }>* inalloca)
437 
438 // WIN64-LABEL: define dso_local void @"\01?g@C@pr30293@@QEAAXXZ"(%"struct.pr30293::C"* %this)
439 // WIN64: declare dso_local void @"\01?h@C@pr30293@@UEAAXUSmallWithDtor@@@Z"(i8*, i32)
440 }
441