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 --check-prefix WIN %s
3 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=thumb-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA --check-prefix WIN %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 --check-prefix WIN %s
5 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple=aarch64-windows-msvc -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WOA64 --check-prefix WIN %s
17 // This is a C++11 trivial and standard-layout struct but not a C++03 POD.
18 struct SmallCpp11NotCpp03Pod
: Empty
{
22 struct SmallWithCtor
{
37 struct SmallWithDtor
{
43 struct SmallWithVftable
{
52 struct MediumWithCopyCtor
{
54 MediumWithCopyCtor(const struct MediumWithCopyCtor
&);
68 struct BaseNoByval
: Small
{
72 struct SmallWithPrivate
{
77 struct SmallWithSmallWithPrivate
{
81 // WIN32: declare dso_local void @"{{.*take_bools_and_chars.*}}"
82 // WIN32: (ptr inalloca(<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor, i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>)
83 void take_bools_and_chars(char a
, char b
, SmallWithDtor c
, char d
, bool e
, int f
, bool g
);
84 void call_bools_and_chars() {
85 take_bools_and_chars('A', 'B', SmallWithDtor(), 'D', true, 13, false);
88 // Returning structs that fit into a register.
89 Small
small_return() { return Small(); }
90 // LINUX-LABEL: define{{.*}} void @_Z12small_returnv(ptr noalias sret(%struct.Small) align 4 %agg.result)
91 // WIN32: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
92 // WIN64: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
93 // WOA64: define dso_local i32 @"?small_return@@YA?AUSmall@@XZ"()
95 Medium
medium_return() { return Medium(); }
96 // LINUX-LABEL: define{{.*}} void @_Z13medium_returnv(ptr noalias sret(%struct.Medium) align 4 %agg.result)
97 // WIN32: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
98 // WIN64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
99 // WOA64: define dso_local i64 @"?medium_return@@YA?AUMedium@@XZ"()
101 // Returning structs that fit into a register but are not POD.
102 SmallCpp11NotCpp03Pod
small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
103 // LINUX-LABEL: define{{.*}} void @_Z20small_non_pod_returnv(ptr noalias sret(%struct.SmallCpp11NotCpp03Pod) align 4 %agg.result)
104 // WIN32: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(ptr noalias sret(%struct.SmallCpp11NotCpp03Pod) align 4 %agg.result)
105 // WIN64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(ptr noalias sret(%struct.SmallCpp11NotCpp03Pod) align 4 %agg.result)
106 // WOA64: define dso_local void @"?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(ptr inreg noalias sret(%struct.SmallCpp11NotCpp03Pod) align 4 %agg.result)
108 SmallWithCtor
small_with_ctor_return() { return SmallWithCtor(); }
109 // LINUX-LABEL: define{{.*}} void @_Z22small_with_ctor_returnv(ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
110 // WIN32: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
111 // WIN64: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
112 // FIXME: The 'sret' mark here doesn't seem to be enough to convince LLVM to
113 // preserve the hidden sret pointer in R0 across the function.
114 // WOA: define dso_local arm_aapcs_vfpcc void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
115 // WOA64: define dso_local void @"?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(ptr inreg noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
117 SmallWithDtor
small_with_dtor_return() { return SmallWithDtor(); }
118 // LINUX-LABEL: define{{.*}} void @_Z22small_with_dtor_returnv(ptr noalias sret(%struct.SmallWithDtor) align 4 %agg.result)
119 // WIN32: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(ptr noalias sret(%struct.SmallWithDtor) align 4 %agg.result)
120 // WIN64: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(ptr noalias sret(%struct.SmallWithDtor) align 4 %agg.result)
121 // WOA64: define dso_local void @"?small_with_dtor_return@@YA?AUSmallWithDtor@@XZ"(ptr inreg noalias sret(%struct.SmallWithDtor) align 4 %agg.result)
123 SmallWithVftable
small_with_vftable_return() { return SmallWithVftable(); }
124 // LINUX-LABEL: define{{.*}} void @_Z25small_with_vftable_returnv(ptr noalias sret(%struct.SmallWithVftable) align 4 %agg.result)
125 // WIN32: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(ptr noalias sret(%struct.SmallWithVftable) align 4 %agg.result)
126 // WIN64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(ptr noalias sret(%struct.SmallWithVftable) align 8 %agg.result)
127 // WOA64: define dso_local void @"?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(ptr inreg noalias sret(%struct.SmallWithVftable) align 8 %agg.result)
129 MediumWithCopyCtor
medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
130 // LINUX-LABEL: define{{.*}} void @_Z28medium_with_copy_ctor_returnv(ptr noalias sret(%struct.MediumWithCopyCtor) align 4 %agg.result)
131 // WIN32: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(ptr noalias sret(%struct.MediumWithCopyCtor) align 4 %agg.result)
132 // WIN64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(ptr noalias sret(%struct.MediumWithCopyCtor) align 4 %agg.result)
133 // WOA: define dso_local arm_aapcs_vfpcc void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(ptr noalias sret(%struct.MediumWithCopyCtor) align 4 %agg.result)
134 // WOA64: define dso_local void @"?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(ptr inreg noalias sret(%struct.MediumWithCopyCtor) align 4 %agg.result)
136 // Returning a large struct that doesn't fit into a register.
137 Big
big_return() { return Big(); }
138 // LINUX-LABEL: define{{.*}} void @_Z10big_returnv(ptr noalias sret(%struct.Big) align 4 %agg.result)
139 // WIN32: define dso_local void @"?big_return@@YA?AUBig@@XZ"(ptr noalias sret(%struct.Big) align 4 %agg.result)
140 // WIN64: define dso_local void @"?big_return@@YA?AUBig@@XZ"(ptr noalias sret(%struct.Big) align 4 %agg.result)
141 // WOA64: define dso_local void @"?big_return@@YA?AUBig@@XZ"(ptr noalias sret(%struct.Big) align 4 %agg.result)
144 void small_arg(Small s
) {}
145 // LINUX-LABEL: define{{.*}} void @_Z9small_arg5Small(i32 %s.0)
146 // WIN32: define dso_local void @"?small_arg@@YAXUSmall@@@Z"(i32 %s.0)
147 // WIN64: define dso_local void @"?small_arg@@YAXUSmall@@@Z"(i32 %s.coerce)
148 // WOA: define dso_local arm_aapcs_vfpcc void @"?small_arg@@YAXUSmall@@@Z"([1 x i32] %s.coerce)
150 void medium_arg(Medium s
) {}
151 // LINUX-LABEL: define{{.*}} void @_Z10medium_arg6Medium(i32 %s.0, i32 %s.1)
152 // WIN32: define dso_local void @"?medium_arg@@YAXUMedium@@@Z"(i32 %s.0, i32 %s.1)
153 // WIN64: define dso_local void @"?medium_arg@@YAXUMedium@@@Z"(i64 %s.coerce)
154 // WOA: define dso_local arm_aapcs_vfpcc void @"?medium_arg@@YAXUMedium@@@Z"([2 x i32] %s.coerce)
156 void base_no_byval_arg(BaseNoByval s
) {}
157 // LINUX-LABEL: define{{.*}} void @_Z17base_no_byval_arg11BaseNoByval(ptr noundef byval(%struct.BaseNoByval) align 4 %s)
158 // WIN32: define dso_local void @"?base_no_byval_arg@@YAXUBaseNoByval@@@Z"(i32 %s.0, i32 %s.1)
159 // WIN64: define dso_local void @"?base_no_byval_arg@@YAXUBaseNoByval@@@Z"(i64 %s.coerce)
160 // WOA: define dso_local arm_aapcs_vfpcc void @"?base_no_byval_arg@@YAXUBaseNoByval@@@Z"([2 x i32] %s.coerce)
162 void small_arg_with_ctor(SmallWithCtor s
) {}
163 // LINUX-LABEL: define{{.*}} void @_Z19small_arg_with_ctor13SmallWithCtor(ptr noundef byval(%struct.SmallWithCtor) align 4 %s)
164 // WIN32: define dso_local void @"?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.0)
165 // WIN64: define dso_local void @"?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.coerce)
166 // WOA: define dso_local arm_aapcs_vfpcc void @"?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"([1 x i32] %s.coerce)
168 // FIXME: We could coerce to a series of i32s here if we wanted to.
169 void multibyte_arg(Multibyte s
) {}
170 // LINUX-LABEL: define{{.*}} void @_Z13multibyte_arg9Multibyte(ptr noundef byval(%struct.Multibyte) align 4 %s)
171 // WIN32: define dso_local void @"?multibyte_arg@@YAXUMultibyte@@@Z"(ptr noundef byval(%struct.Multibyte) align 4 %s)
172 // WIN64: define dso_local void @"?multibyte_arg@@YAXUMultibyte@@@Z"(i32 %s.coerce)
173 // WOA: define dso_local arm_aapcs_vfpcc void @"?multibyte_arg@@YAXUMultibyte@@@Z"([1 x i32] %s.coerce)
175 void packed_arg(Packed s
) {}
176 // LINUX-LABEL: define{{.*}} void @_Z10packed_arg6Packed(ptr noundef byval(%struct.Packed) align 4 %s)
177 // WIN32: define dso_local void @"?packed_arg@@YAXUPacked@@@Z"(ptr noundef byval(%struct.Packed) align 4 %s)
178 // WIN64: define dso_local void @"?packed_arg@@YAXUPacked@@@Z"(ptr noundef %s)
180 // Test that dtors are invoked in the callee.
181 void small_arg_with_dtor(SmallWithDtor s
) {}
182 // WIN32: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(ptr inalloca(<{ %struct.SmallWithDtor }>) %0) {{.*}} {
183 // WIN32: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
185 // WIN64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
186 // WIN64: call void @"??1SmallWithDtor@@QEAA@XZ"
188 // WOA64: define dso_local void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i64 %s.coerce) {{.*}} {
189 // WOA64: call void @"??1SmallWithDtor@@QEAA@XZ"(ptr {{[^,]*}} %s)
192 // FIXME: MSVC incompatible!
193 // WOA: define dso_local arm_aapcs_vfpcc void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(ptr noundef %s) {{.*}} {
194 // WOA: call arm_aapcs_vfpcc void @"??1SmallWithDtor@@QAA@XZ"(ptr {{[^,]*}} %s)
198 // Test that the eligible non-aggregate is passed directly, but returned
199 // indirectly on ARM64 Windows.
200 // WOA64: define dso_local void @"?small_arg_with_private_member@@YA?AUSmallWithPrivate@@U1@@Z"(ptr inreg noalias sret(%struct.SmallWithPrivate) align 4 %agg.result, i64 %s.coerce) {{.*}} {
201 SmallWithPrivate
small_arg_with_private_member(SmallWithPrivate s
) { return s
; }
203 // WOA64: define dso_local i32 @"?small_arg_with_small_struct_with_private_member@@YA?AUSmallWithSmallWithPrivate@@U1@@Z"(i64 %s.coerce) {{.*}} {
204 // WIN64: define dso_local i32 @"?small_arg_with_small_struct_with_private_member@@YA?AUSmallWithSmallWithPrivate@@U1@@Z"(i32 %s.coerce) {{.*}} {
205 SmallWithSmallWithPrivate
small_arg_with_small_struct_with_private_member(SmallWithSmallWithPrivate s
) { return s
; }
207 void call_small_arg_with_dtor() {
208 small_arg_with_dtor(SmallWithDtor());
210 // WIN64-LABEL: define dso_local void @"?call_small_arg_with_dtor@@YAXXZ"()
211 // WIN64: call noundef ptr @"??0SmallWithDtor@@QEAA@XZ"
212 // WIN64: call void @"?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %{{.*}})
215 // Test that references aren't destroyed in the callee.
216 void ref_small_arg_with_dtor(const SmallWithDtor
&s
) { }
217 // WIN32: define dso_local void @"?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"(ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %s) {{.*}} {
218 // WIN32-NOT: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
220 // WIN64-LABEL: define dso_local void @"?ref_small_arg_with_dtor@@YAXAEBUSmallWithDtor@@@Z"(ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %s)
222 void big_arg_with_dtor(BigWithDtor s
) {}
223 // WIN64-LABEL: define dso_local void @"?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(ptr noundef %s)
224 // WIN64: call void @"??1BigWithDtor@@QEAA@XZ"
227 void call_big_arg_with_dtor() {
228 big_arg_with_dtor(BigWithDtor());
230 // We can elide the copy of the temporary in the caller, because this object is
231 // larger than 8 bytes and is passed indirectly.
232 // WIN64-LABEL: define dso_local void @"?call_big_arg_with_dtor@@YAXXZ"()
233 // WIN64: call noundef ptr @"??0BigWithDtor@@QEAA@XZ"
234 // WIN64: call void @"?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(ptr noundef %{{.*}})
235 // WIN64-NOT: call void @"??1BigWithDtor@@QEAA@XZ"
238 // Test that temporaries passed by reference are destroyed in the caller.
239 void temporary_ref_with_dtor() {
240 ref_small_arg_with_dtor(SmallWithDtor());
242 // WIN32: define dso_local void @"?temporary_ref_with_dtor@@YAXXZ"() {{.*}} {
243 // WIN32: call x86_thiscallcc noundef ptr @"??0SmallWithDtor@@QAE@XZ"
244 // WIN32: call void @"?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"
245 // WIN32: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
248 void takes_two_by_val_with_dtor(SmallWithDtor a
, SmallWithDtor b
);
249 void eh_cleanup_arg_with_dtor() {
250 takes_two_by_val_with_dtor(SmallWithDtor(), SmallWithDtor());
252 // When exceptions are off, we don't have any cleanups. See
253 // microsoft-abi-exceptions.cpp for these cleanups.
254 // WIN32: define dso_local void @"?eh_cleanup_arg_with_dtor@@YAXXZ"() {{.*}} {
255 // WIN32: call x86_thiscallcc noundef ptr @"??0SmallWithDtor@@QAE@XZ"
256 // WIN32: call x86_thiscallcc noundef ptr @"??0SmallWithDtor@@QAE@XZ"
257 // WIN32: call void @"?takes_two_by_val_with_dtor@@YAXUSmallWithDtor@@0@Z"
258 // WIN32-NOT: call x86_thiscallcc void @"??1SmallWithDtor@@QAE@XZ"
261 void small_arg_with_vftable(SmallWithVftable s
) {}
262 // LINUX-LABEL: define{{.*}} void @_Z22small_arg_with_vftable16SmallWithVftable(ptr noundef %s)
263 // WIN32: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(ptr inalloca(<{ %struct.SmallWithVftable }>) %0)
264 // WIN64: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(ptr noundef %s)
265 // WOA64: define dso_local void @"?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(ptr noundef %s)
267 void medium_arg_with_copy_ctor(MediumWithCopyCtor s
) {}
268 // LINUX-LABEL: define{{.*}} void @_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(ptr noundef %s)
269 // WIN32: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(ptr inalloca(<{ %struct.MediumWithCopyCtor }>) %0)
270 // WIN64: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(ptr noundef %s)
271 // WOA: define dso_local arm_aapcs_vfpcc void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(ptr noundef %s)
272 // WOA64: define dso_local void @"?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(ptr noundef %s)
274 void big_arg(Big s
) {}
275 // LINUX-LABEL: define{{.*}} void @_Z7big_arg3Big(ptr noundef byval(%struct.Big) align 4 %s)
276 // WIN32: define dso_local void @"?big_arg@@YAXUBig@@@Z"(ptr noundef byval(%struct.Big) align 4 %s)
277 // WIN64: define dso_local void @"?big_arg@@YAXUBig@@@Z"(ptr noundef %s)
279 // PR27607: We would attempt to load i32 value out of the reference instead of
280 // just loading the pointer from the struct during argument expansion.
285 void takes_ref_field(RefField s
) {}
286 // LINUX-LABEL: define{{.*}} void @_Z15takes_ref_field8RefField(ptr noundef byval(%struct.RefField) align 4 %s)
287 // WIN32: define dso_local void @"?takes_ref_field@@YAXURefField@@@Z"(ptr %s.0)
288 // WIN64: define dso_local void @"?takes_ref_field@@YAXURefField@@@Z"(i64 %s.coerce)
290 void pass_ref_field() {
292 takes_ref_field(RefField(x
));
294 // LINUX-LABEL: define{{.*}} void @_Z14pass_ref_fieldv()
295 // LINUX: call void @_Z15takes_ref_field8RefField(ptr noundef byval(%struct.RefField) align 4 %{{.*}})
296 // WIN32-LABEL: define dso_local void @"?pass_ref_field@@YAXXZ"()
297 // WIN32: call void @"?takes_ref_field@@YAXURefField@@@Z"(ptr %{{.*}})
298 // WIN64-LABEL: define dso_local void @"?pass_ref_field@@YAXXZ"()
299 // WIN64: call void @"?takes_ref_field@@YAXURefField@@@Z"(i64 %{{.*}})
303 Small
thiscall_method_small() { return Small(); }
304 // LINUX: define {{.*}} void @_ZN5Class21thiscall_method_smallEv(ptr noalias sret(%struct.Small) align 4 %agg.result, ptr {{[^,]*}} %this)
305 // WIN32: define {{.*}} x86_thiscallcc void @"?thiscall_method_small@Class@@QAE?AUSmall@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.Small) align 4 %agg.result)
306 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_small@Class@@QEAA?AUSmall@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.Small) align 4 %agg.result)
307 // WOA64: define linkonce_odr dso_local void @"?thiscall_method_small@Class@@QEAA?AUSmall@@XZ"(ptr {{[^,]*}} %this, ptr inreg noalias sret(%struct.Small) align 4 %agg.result)
309 SmallWithCtor
thiscall_method_small_with_ctor() { return SmallWithCtor(); }
310 // LINUX: define {{.*}} void @_ZN5Class31thiscall_method_small_with_ctorEv(ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result, ptr {{[^,]*}} %this)
311 // WIN32: define {{.*}} x86_thiscallcc void @"?thiscall_method_small_with_ctor@Class@@QAE?AUSmallWithCtor@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
312 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_small_with_ctor@Class@@QEAA?AUSmallWithCtor@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
313 // WOA64: define linkonce_odr dso_local void @"?thiscall_method_small_with_ctor@Class@@QEAA?AUSmallWithCtor@@XZ"(ptr {{[^,]*}} %this, ptr inreg noalias sret(%struct.SmallWithCtor) align 4 %agg.result)
315 Small __cdecl
cdecl_method_small() { return Small(); }
316 // LINUX: define {{.*}} void @_ZN5Class18cdecl_method_smallEv(ptr noalias sret(%struct.Small) align 4 %agg.result, ptr {{[^,]*}} %this)
317 // WIN32: define {{.*}} void @"?cdecl_method_small@Class@@QAA?AUSmall@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.Small) align 4 %agg.result)
318 // WIN64: define linkonce_odr dso_local void @"?cdecl_method_small@Class@@QEAA?AUSmall@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.Small) align 4 %agg.result)
320 Big __cdecl
cdecl_method_big() { return Big(); }
321 // LINUX: define {{.*}} void @_ZN5Class16cdecl_method_bigEv(ptr noalias sret(%struct.Big) align 4 %agg.result, ptr {{[^,]*}} %this)
322 // WIN32: define {{.*}} void @"?cdecl_method_big@Class@@QAA?AUBig@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.Big) align 4 %agg.result)
323 // WIN64: define linkonce_odr dso_local void @"?cdecl_method_big@Class@@QEAA?AUBig@@XZ"(ptr {{[^,]*}} %this, ptr noalias sret(%struct.Big) align 4 %agg.result)
324 // WOA64: define linkonce_odr dso_local void @"?cdecl_method_big@Class@@QEAA?AUBig@@XZ"(ptr {{[^,]*}} %this, ptr inreg noalias sret(%struct.Big) align 4 %agg.result)
326 void thiscall_method_arg(Empty s
) {}
327 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Empty(ptr {{[^,]*}} %this)
328 // WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUEmpty@@@Z"(ptr {{[^,]*}} %this, ptr noundef byval(%struct.Empty) align 4 %s)
329 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUEmpty@@@Z"(ptr {{[^,]*}} %this, i8 %s.coerce)
331 void thiscall_method_arg(EmptyWithCtor s
) {}
332 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13EmptyWithCtor(ptr {{[^,]*}} %this)
333 // WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUEmptyWithCtor@@@Z"(ptr {{[^,]*}} %this, ptr noundef byval(%struct.EmptyWithCtor) align 4 %s)
334 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUEmptyWithCtor@@@Z"(ptr {{[^,]*}} %this, i8 %s.coerce)
336 void thiscall_method_arg(Small s
) {}
337 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(ptr {{[^,]*}} %this, i32 %s.0)
338 // WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUSmall@@@Z"(ptr {{[^,]*}} %this, i32 %s.0)
339 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUSmall@@@Z"(ptr {{[^,]*}} %this, i32 %s.coerce)
341 void thiscall_method_arg(SmallWithCtor s
) {}
342 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13SmallWithCtor(ptr {{[^,]*}} %this, ptr noundef byval(%struct.SmallWithCtor) align 4 %s)
343 // WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUSmallWithCtor@@@Z"(ptr {{[^,]*}} %this, i32 %s.0)
344 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUSmallWithCtor@@@Z"(ptr {{[^,]*}} %this, i32 %s.coerce)
346 void thiscall_method_arg(Big s
) {}
347 // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE3Big(ptr {{[^,]*}} %this, ptr noundef byval(%struct.Big) align 4 %s)
348 // WIN32: define {{.*}} void @"?thiscall_method_arg@Class@@QAEXUBig@@@Z"(ptr {{[^,]*}} %this, ptr noundef byval(%struct.Big) align 4 %s)
349 // WIN64: define linkonce_odr dso_local void @"?thiscall_method_arg@Class@@QEAAXUBig@@@Z"(ptr {{[^,]*}} %this, ptr noundef %s)
354 c
.thiscall_method_small();
355 c
.thiscall_method_small_with_ctor();
357 c
.cdecl_method_small();
358 c
.cdecl_method_big();
360 c
.thiscall_method_arg(Empty());
361 c
.thiscall_method_arg(EmptyWithCtor());
362 c
.thiscall_method_arg(Small());
363 c
.thiscall_method_arg(SmallWithCtor());
364 c
.thiscall_method_arg(Big());
373 // WIN32: define dso_local void @"?g@@YAXUX@@@Z"(ptr inalloca(<{ %struct.X, [3 x i8] }>) %0) {{.*}} {
374 // WIN32: call x86_thiscallcc void @"??1X@@QAE@XZ"(ptr {{.*}})
379 // WIN32: define dso_local void @"?f@@YAXXZ"() {{.*}} {
380 // WIN32-NOT: call {{.*}} @"??1X@@QAE@XZ"
385 // We used to crash on this due to the mixture of POD byval and non-trivial
390 NonTrivial(const NonTrivial
&o
);
394 struct POD
{ int b
; };
396 int foo(NonTrivial a
, POD b
);
400 int c
= foo(NonTrivial(), b
);
402 // WIN32-LABEL: define dso_local void @"?bar@test2@@YAXXZ"() {{.*}} {
403 // WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ %"struct.test2::NonTrivial", %"struct.test2::POD" }>]]
404 // WIN32: getelementptr inbounds [[argmem_ty]], ptr %[[argmem]], i32 0, i32 1
405 // WIN32: call void @llvm.memcpy
406 // WIN32: getelementptr inbounds [[argmem_ty]], ptr %[[argmem]], i32 0, i32 0
407 // WIN32: call x86_thiscallcc noundef ptr @"??0NonTrivial@test2@@QAE@XZ"
408 // WIN32: call noundef i32 @"?foo@test2@@YAHUNonTrivial@1@UPOD@1@@Z"(ptr inalloca([[argmem_ty]]) %argmem)
416 // Check that we padded the inalloca struct to a multiple of 4.
419 NonTrivial(const NonTrivial
&o
);
423 void foo(NonTrivial a
, bool b
) { }
424 // WIN32-LABEL: define dso_local void @"?foo@test3@@YAXUNonTrivial@1@_N@Z"(ptr inalloca(<{ %"struct.test3::NonTrivial", i8, [3 x i8] }>) %0)
428 // We would crash here because the later definition of ForwardDeclare1 results
429 // in a different IR type for the value we want to store. However, the alloca's
430 // type will use the argument type selected by fn1.
431 struct ForwardDeclare1
;
433 typedef void (*FnPtr1
)(ForwardDeclare1
);
434 void fn1(FnPtr1 a
, SmallWithDtor b
) { }
436 struct ForwardDeclare1
{};
438 void fn2(FnPtr1 a
, SmallWithDtor b
) { fn1(a
, b
); };
439 // WIN32-LABEL: define dso_local void @"?fn2@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"
440 // WIN32: %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty:<{ ptr, %struct.SmallWithDtor }>]], ptr %{{.*}}, i32 0, i32 0
441 // WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ ptr, %struct.SmallWithDtor }>]]
442 // WIN32: %[[gep1:[^ ]*]] = getelementptr inbounds [[argmem_ty]], ptr %[[argmem]], i32 0, i32 1
443 // WIN32: call void @llvm.memcpy.p0.p0.i32(ptr align 4 %[[gep1]], ptr align 4 {{.*}}, i32 4, i1 false)
444 // WIN32: %[[a2:[^ ]*]] = load ptr, ptr %[[a]], align 4
445 // WIN32: %[[gep2:[^ ]*]] = getelementptr inbounds [[argmem_ty]], ptr %[[argmem]], i32 0, i32 0
446 // WIN32: store ptr %[[a2]], ptr %[[gep2]], align 4
447 // WIN32: call void @"?fn1@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"(ptr inalloca([[argmem_ty]]) %[[argmem]])
450 // Virtual methods living in a secondary vtable take ptr as their 'this'
451 // parameter because the 'this' parameter on entry points to the secondary
452 // vptr. We used to have a bug where we didn't apply this rule consistently,
453 // and it would cause assertion failures when used with inalloca.
458 virtual void __cdecl
h(SmallWithDtor
);
460 struct C final
: A
, B
{
462 void __cdecl
h(SmallWithDtor
);
465 void C::g() { return h(SmallWithDtor()); }
467 // WIN32-LABEL: define dso_local x86_thiscallcc void @"?g@C@pr30293@@QAEXXZ"(ptr {{[^,]*}} %this)
468 // WIN32: call x86_thiscallcc noundef ptr @"??0SmallWithDtor@@QAE@XZ"
469 // WIN32: call void @"?h@C@pr30293@@UAAXUSmallWithDtor@@@Z"(ptr inalloca(<{ ptr, %struct.SmallWithDtor }>) %{{[^,)]*}})
470 // WIN32: declare dso_local void @"?h@C@pr30293@@UAAXUSmallWithDtor@@@Z"(ptr inalloca(<{ ptr, %struct.SmallWithDtor }>))
472 // WIN64-LABEL: define dso_local void @"?g@C@pr30293@@QEAAXXZ"(ptr {{[^,]*}} %this)
473 // WIN64: declare dso_local void @"?h@C@pr30293@@UEAAXUSmallWithDtor@@@Z"(ptr noundef, i32)
476 namespace protected_member_of_member
{
477 struct field
{ protected: int i
; };
482 t1
f1() { return v1
; }
483 // WIN: define dso_local {{.*}}i32 @"?f1@protected_member_of_member@@YA?AUt1@1@XZ"()
486 namespace default_member_initializer
{
491 t1
f1() { return v1
; }
492 // WIN: define dso_local {{.*}}i32 @"?f1@default_member_initializer@@YA?AUt1@1@XZ"()
495 namespace defaulted_copy_ctor
{
498 t1(const t1
&) = default;
501 t1
f1() { return v1
; }
502 // WIN: define dso_local {{.*}}i32 @"?f1@defaulted_copy_ctor@@YA?AUt1@1@XZ"()