1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-linux | FileCheck -check-prefix LINUX %s
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN32 %s
3*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-win32 -mconstructor-aliases -fno-rtti | FileCheck -check-prefix WIN64 %s
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc struct Empty {};
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc struct EmptyWithCtor {
EmptyWithCtorEmptyWithCtor8f4a2713aSLionel Sambuc EmptyWithCtor() {}
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambuc struct Small {
12f4a2713aSLionel Sambuc int x;
13f4a2713aSLionel Sambuc };
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambuc // This is a C++11 trivial and standard-layout struct but not a C++03 POD.
16f4a2713aSLionel Sambuc struct SmallCpp11NotCpp03Pod : Empty {
17f4a2713aSLionel Sambuc int x;
18f4a2713aSLionel Sambuc };
19f4a2713aSLionel Sambuc
20f4a2713aSLionel Sambuc struct SmallWithCtor {
SmallWithCtorSmallWithCtor21f4a2713aSLionel Sambuc SmallWithCtor() {}
22f4a2713aSLionel Sambuc int x;
23f4a2713aSLionel Sambuc };
24f4a2713aSLionel Sambuc
25f4a2713aSLionel Sambuc struct SmallWithDtor {
26f4a2713aSLionel Sambuc SmallWithDtor();
27f4a2713aSLionel Sambuc ~SmallWithDtor();
28f4a2713aSLionel Sambuc int x;
29f4a2713aSLionel Sambuc };
30f4a2713aSLionel Sambuc
31f4a2713aSLionel Sambuc struct SmallWithVftable {
32f4a2713aSLionel Sambuc int x;
33f4a2713aSLionel Sambuc virtual void foo();
34f4a2713aSLionel Sambuc };
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc struct Medium {
37f4a2713aSLionel Sambuc int x, y;
38f4a2713aSLionel Sambuc };
39f4a2713aSLionel Sambuc
40f4a2713aSLionel Sambuc struct MediumWithCopyCtor {
41f4a2713aSLionel Sambuc MediumWithCopyCtor();
42f4a2713aSLionel Sambuc MediumWithCopyCtor(const struct MediumWithCopyCtor &);
43f4a2713aSLionel Sambuc int x, y;
44f4a2713aSLionel Sambuc };
45f4a2713aSLionel Sambuc
46f4a2713aSLionel Sambuc struct Big {
47f4a2713aSLionel Sambuc int a, b, c, d, e, f;
48f4a2713aSLionel Sambuc };
49f4a2713aSLionel Sambuc
50*0a6a1f1dSLionel Sambuc struct BigWithDtor {
51*0a6a1f1dSLionel Sambuc BigWithDtor();
52*0a6a1f1dSLionel Sambuc ~BigWithDtor();
53*0a6a1f1dSLionel Sambuc int a, b, c, d, e, f;
54*0a6a1f1dSLionel Sambuc };
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambuc // WIN32: declare void @"{{.*take_bools_and_chars.*}}"
57*0a6a1f1dSLionel Sambuc // WIN32: (<{ i8, [3 x i8], i8, [3 x i8], %struct.SmallWithDtor,
58*0a6a1f1dSLionel Sambuc // WIN32: i8, [3 x i8], i8, [3 x i8], i32, i8, [3 x i8] }>* inalloca)
59*0a6a1f1dSLionel Sambuc void take_bools_and_chars(char a, char b, SmallWithDtor c, char d, bool e, int f, bool g);
call_bools_and_chars()60*0a6a1f1dSLionel Sambuc void call_bools_and_chars() {
61*0a6a1f1dSLionel Sambuc take_bools_and_chars('A', 'B', SmallWithDtor(), 'D', true, 13, false);
62*0a6a1f1dSLionel Sambuc }
63*0a6a1f1dSLionel Sambuc
64f4a2713aSLionel Sambuc // Returning structs that fit into a register.
small_return()65f4a2713aSLionel Sambuc Small small_return() { return Small(); }
66f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z12small_returnv(%struct.Small* noalias sret %agg.result)
67f4a2713aSLionel Sambuc // WIN32: define i32 @"\01?small_return@@YA?AUSmall@@XZ"()
68f4a2713aSLionel Sambuc // WIN64: define i32 @"\01?small_return@@YA?AUSmall@@XZ"()
69f4a2713aSLionel Sambuc
medium_return()70f4a2713aSLionel Sambuc Medium medium_return() { return Medium(); }
71f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z13medium_returnv(%struct.Medium* noalias sret %agg.result)
72f4a2713aSLionel Sambuc // WIN32: define i64 @"\01?medium_return@@YA?AUMedium@@XZ"()
73f4a2713aSLionel Sambuc // WIN64: define i64 @"\01?medium_return@@YA?AUMedium@@XZ"()
74f4a2713aSLionel Sambuc
75f4a2713aSLionel Sambuc // Returning structs that fit into a register but are not POD.
small_non_pod_return()76f4a2713aSLionel Sambuc SmallCpp11NotCpp03Pod small_non_pod_return() { return SmallCpp11NotCpp03Pod(); }
77f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z20small_non_pod_returnv(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
78f4a2713aSLionel Sambuc // WIN32: define void @"\01?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
79f4a2713aSLionel Sambuc // WIN64: define void @"\01?small_non_pod_return@@YA?AUSmallCpp11NotCpp03Pod@@XZ"(%struct.SmallCpp11NotCpp03Pod* noalias sret %agg.result)
80f4a2713aSLionel Sambuc
small_with_ctor_return()81f4a2713aSLionel Sambuc SmallWithCtor small_with_ctor_return() { return SmallWithCtor(); }
82f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z22small_with_ctor_returnv(%struct.SmallWithCtor* noalias sret %agg.result)
83f4a2713aSLionel Sambuc // WIN32: define void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
84f4a2713aSLionel Sambuc // WIN64: define void @"\01?small_with_ctor_return@@YA?AUSmallWithCtor@@XZ"(%struct.SmallWithCtor* noalias sret %agg.result)
85f4a2713aSLionel Sambuc
small_with_vftable_return()86f4a2713aSLionel Sambuc SmallWithVftable small_with_vftable_return() { return SmallWithVftable(); }
87f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z25small_with_vftable_returnv(%struct.SmallWithVftable* noalias sret %agg.result)
88f4a2713aSLionel Sambuc // WIN32: define void @"\01?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
89f4a2713aSLionel Sambuc // WIN64: define void @"\01?small_with_vftable_return@@YA?AUSmallWithVftable@@XZ"(%struct.SmallWithVftable* noalias sret %agg.result)
90f4a2713aSLionel Sambuc
medium_with_copy_ctor_return()91f4a2713aSLionel Sambuc MediumWithCopyCtor medium_with_copy_ctor_return() { return MediumWithCopyCtor(); }
92f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z28medium_with_copy_ctor_returnv(%struct.MediumWithCopyCtor* noalias sret %agg.result)
93f4a2713aSLionel Sambuc // WIN32: define void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
94f4a2713aSLionel Sambuc // WIN64: define void @"\01?medium_with_copy_ctor_return@@YA?AUMediumWithCopyCtor@@XZ"(%struct.MediumWithCopyCtor* noalias sret %agg.result)
95f4a2713aSLionel Sambuc
96f4a2713aSLionel Sambuc // Returning a large struct that doesn't fit into a register.
big_return()97f4a2713aSLionel Sambuc Big big_return() { return Big(); }
98f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z10big_returnv(%struct.Big* noalias sret %agg.result)
99f4a2713aSLionel Sambuc // WIN32: define void @"\01?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
100f4a2713aSLionel Sambuc // WIN64: define void @"\01?big_return@@YA?AUBig@@XZ"(%struct.Big* noalias sret %agg.result)
101f4a2713aSLionel Sambuc
102f4a2713aSLionel Sambuc
small_arg(Small s)103f4a2713aSLionel Sambuc void small_arg(Small s) {}
104f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z9small_arg5Small(%struct.Small* byval align 4 %s)
105f4a2713aSLionel Sambuc // WIN32: define void @"\01?small_arg@@YAXUSmall@@@Z"(%struct.Small* byval align 4 %s)
106f4a2713aSLionel Sambuc // WIN64: define void @"\01?small_arg@@YAXUSmall@@@Z"(i32 %s.coerce)
107f4a2713aSLionel Sambuc
medium_arg(Medium s)108f4a2713aSLionel Sambuc void medium_arg(Medium s) {}
109f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z10medium_arg6Medium(%struct.Medium* byval align 4 %s)
110f4a2713aSLionel Sambuc // WIN32: define void @"\01?medium_arg@@YAXUMedium@@@Z"(%struct.Medium* byval align 4 %s)
111f4a2713aSLionel Sambuc // WIN64: define void @"\01?medium_arg@@YAXUMedium@@@Z"(i64 %s.coerce)
112f4a2713aSLionel Sambuc
small_arg_with_ctor(SmallWithCtor s)113f4a2713aSLionel Sambuc void small_arg_with_ctor(SmallWithCtor s) {}
114f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z19small_arg_with_ctor13SmallWithCtor(%struct.SmallWithCtor* byval align 4 %s)
115f4a2713aSLionel Sambuc // WIN32: define void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(%struct.SmallWithCtor* byval align 4 %s)
116f4a2713aSLionel Sambuc // WIN64: define void @"\01?small_arg_with_ctor@@YAXUSmallWithCtor@@@Z"(i32 %s.coerce)
117f4a2713aSLionel Sambuc
118f4a2713aSLionel Sambuc // Test that dtors are invoked in the callee.
small_arg_with_dtor(SmallWithDtor s)119f4a2713aSLionel Sambuc void small_arg_with_dtor(SmallWithDtor s) {}
120*0a6a1f1dSLionel Sambuc // WIN32: define void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(<{ %struct.SmallWithDtor }>* inalloca) {{.*}} {
121*0a6a1f1dSLionel Sambuc // WIN32: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
122f4a2713aSLionel Sambuc // WIN32: }
123*0a6a1f1dSLionel Sambuc // WIN64: define void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %s.coerce) {{.*}} {
124*0a6a1f1dSLionel Sambuc // WIN64: call void @"\01??1SmallWithDtor@@QEAA@XZ"
125f4a2713aSLionel Sambuc // WIN64: }
126f4a2713aSLionel Sambuc
call_small_arg_with_dtor()127*0a6a1f1dSLionel Sambuc void call_small_arg_with_dtor() {
128*0a6a1f1dSLionel Sambuc small_arg_with_dtor(SmallWithDtor());
129*0a6a1f1dSLionel Sambuc }
130*0a6a1f1dSLionel Sambuc // The temporary is copied, so it's destroyed in the caller as well as the
131*0a6a1f1dSLionel Sambuc // callee.
132*0a6a1f1dSLionel Sambuc // WIN64-LABEL: define void @"\01?call_small_arg_with_dtor@@YAXXZ"()
133*0a6a1f1dSLionel Sambuc // WIN64: call %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QEAA@XZ"
134*0a6a1f1dSLionel Sambuc // WIN64: call void @"\01?small_arg_with_dtor@@YAXUSmallWithDtor@@@Z"(i32 %{{.*}})
135*0a6a1f1dSLionel Sambuc // WIN64: call void @"\01??1SmallWithDtor@@QEAA@XZ"
136*0a6a1f1dSLionel Sambuc // WIN64: ret void
137*0a6a1f1dSLionel Sambuc
138f4a2713aSLionel Sambuc // Test that references aren't destroyed in the callee.
ref_small_arg_with_dtor(const SmallWithDtor & s)139f4a2713aSLionel Sambuc void ref_small_arg_with_dtor(const SmallWithDtor &s) { }
140*0a6a1f1dSLionel Sambuc // WIN32: define void @"\01?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s) {{.*}} {
141f4a2713aSLionel Sambuc // WIN32-NOT: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
142f4a2713aSLionel Sambuc // WIN32: }
143*0a6a1f1dSLionel Sambuc // WIN64-LABEL: define void @"\01?ref_small_arg_with_dtor@@YAXAEBUSmallWithDtor@@@Z"(%struct.SmallWithDtor* dereferenceable({{[0-9]+}}) %s)
144*0a6a1f1dSLionel Sambuc
big_arg_with_dtor(BigWithDtor s)145*0a6a1f1dSLionel Sambuc void big_arg_with_dtor(BigWithDtor s) {}
146*0a6a1f1dSLionel Sambuc // WIN64-LABEL: define void @"\01?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %s)
147*0a6a1f1dSLionel Sambuc // WIN64: call void @"\01??1BigWithDtor@@QEAA@XZ"
148*0a6a1f1dSLionel Sambuc // WIN64: }
149*0a6a1f1dSLionel Sambuc
call_big_arg_with_dtor()150*0a6a1f1dSLionel Sambuc void call_big_arg_with_dtor() {
151*0a6a1f1dSLionel Sambuc big_arg_with_dtor(BigWithDtor());
152*0a6a1f1dSLionel Sambuc }
153*0a6a1f1dSLionel Sambuc // We can elide the copy of the temporary in the caller, because this object is
154*0a6a1f1dSLionel Sambuc // larger than 8 bytes and is passed indirectly.
155*0a6a1f1dSLionel Sambuc // WIN64-LABEL: define void @"\01?call_big_arg_with_dtor@@YAXXZ"()
156*0a6a1f1dSLionel Sambuc // WIN64: call %struct.BigWithDtor* @"\01??0BigWithDtor@@QEAA@XZ"
157*0a6a1f1dSLionel Sambuc // WIN64: call void @"\01?big_arg_with_dtor@@YAXUBigWithDtor@@@Z"(%struct.BigWithDtor* %{{.*}})
158*0a6a1f1dSLionel Sambuc // WIN64-NOT: call void @"\01??1BigWithDtor@@QEAA@XZ"
159*0a6a1f1dSLionel Sambuc // WIN64: ret void
160f4a2713aSLionel Sambuc
161f4a2713aSLionel Sambuc // Test that temporaries passed by reference are destroyed in the caller.
temporary_ref_with_dtor()162f4a2713aSLionel Sambuc void temporary_ref_with_dtor() {
163f4a2713aSLionel Sambuc ref_small_arg_with_dtor(SmallWithDtor());
164f4a2713aSLionel Sambuc }
165f4a2713aSLionel Sambuc // WIN32: define void @"\01?temporary_ref_with_dtor@@YAXXZ"() {{.*}} {
166f4a2713aSLionel Sambuc // WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
167f4a2713aSLionel Sambuc // WIN32: call void @"\01?ref_small_arg_with_dtor@@YAXABUSmallWithDtor@@@Z"
168f4a2713aSLionel Sambuc // WIN32: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
169f4a2713aSLionel Sambuc // WIN32: }
170f4a2713aSLionel Sambuc
171f4a2713aSLionel Sambuc void takes_two_by_val_with_dtor(SmallWithDtor a, SmallWithDtor b);
eh_cleanup_arg_with_dtor()172f4a2713aSLionel Sambuc void eh_cleanup_arg_with_dtor() {
173f4a2713aSLionel Sambuc takes_two_by_val_with_dtor(SmallWithDtor(), SmallWithDtor());
174f4a2713aSLionel Sambuc }
175f4a2713aSLionel Sambuc // When exceptions are off, we don't have any cleanups. See
176f4a2713aSLionel Sambuc // microsoft-abi-exceptions.cpp for these cleanups.
177f4a2713aSLionel Sambuc // WIN32: define void @"\01?eh_cleanup_arg_with_dtor@@YAXXZ"() {{.*}} {
178f4a2713aSLionel Sambuc // WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
179f4a2713aSLionel Sambuc // WIN32: call x86_thiscallcc %struct.SmallWithDtor* @"\01??0SmallWithDtor@@QAE@XZ"
180f4a2713aSLionel Sambuc // WIN32: call void @"\01?takes_two_by_val_with_dtor@@YAXUSmallWithDtor@@0@Z"
181f4a2713aSLionel Sambuc // WIN32-NOT: call x86_thiscallcc void @"\01??1SmallWithDtor@@QAE@XZ"
182f4a2713aSLionel Sambuc // WIN32: }
183f4a2713aSLionel Sambuc
small_arg_with_vftable(SmallWithVftable s)184f4a2713aSLionel Sambuc void small_arg_with_vftable(SmallWithVftable s) {}
185f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z22small_arg_with_vftable16SmallWithVftable(%struct.SmallWithVftable* %s)
186*0a6a1f1dSLionel Sambuc // WIN32: define void @"\01?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(<{ %struct.SmallWithVftable }>* inalloca)
187*0a6a1f1dSLionel Sambuc // WIN64: define void @"\01?small_arg_with_vftable@@YAXUSmallWithVftable@@@Z"(%struct.SmallWithVftable* %s)
188f4a2713aSLionel Sambuc
medium_arg_with_copy_ctor(MediumWithCopyCtor s)189f4a2713aSLionel Sambuc void medium_arg_with_copy_ctor(MediumWithCopyCtor s) {}
190f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z25medium_arg_with_copy_ctor18MediumWithCopyCtor(%struct.MediumWithCopyCtor* %s)
191*0a6a1f1dSLionel Sambuc // WIN32: define void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(<{ %struct.MediumWithCopyCtor }>* inalloca)
192*0a6a1f1dSLionel Sambuc // WIN64: define void @"\01?medium_arg_with_copy_ctor@@YAXUMediumWithCopyCtor@@@Z"(%struct.MediumWithCopyCtor* %s)
193f4a2713aSLionel Sambuc
big_arg(Big s)194f4a2713aSLionel Sambuc void big_arg(Big s) {}
195f4a2713aSLionel Sambuc // LINUX-LABEL: define void @_Z7big_arg3Big(%struct.Big* byval align 4 %s)
196f4a2713aSLionel Sambuc // WIN32: define void @"\01?big_arg@@YAXUBig@@@Z"(%struct.Big* byval align 4 %s)
197f4a2713aSLionel Sambuc // WIN64: define void @"\01?big_arg@@YAXUBig@@@Z"(%struct.Big* %s)
198f4a2713aSLionel Sambuc
199f4a2713aSLionel Sambuc class Class {
200f4a2713aSLionel Sambuc public:
thiscall_method_small()201f4a2713aSLionel Sambuc Small thiscall_method_small() { return Small(); }
202f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class21thiscall_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
203*0a6a1f1dSLionel Sambuc // WIN32: define {{.*}} x86_thiscallcc void @"\01?thiscall_method_small@Class@@QAE?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
204*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
205f4a2713aSLionel Sambuc
thiscall_method_small_with_ctor()206f4a2713aSLionel Sambuc SmallWithCtor thiscall_method_small_with_ctor() { return SmallWithCtor(); }
207f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class31thiscall_method_small_with_ctorEv(%struct.SmallWithCtor* noalias sret %agg.result, %class.Class* %this)
208*0a6a1f1dSLionel Sambuc // 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*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_small_with_ctor@Class@@QEAA?AUSmallWithCtor@@XZ"(%class.Class* %this, %struct.SmallWithCtor* noalias sret %agg.result)
210f4a2713aSLionel Sambuc
cdecl_method_small()211f4a2713aSLionel Sambuc Small __cdecl cdecl_method_small() { return Small(); }
212f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class18cdecl_method_smallEv(%struct.Small* noalias sret %agg.result, %class.Class* %this)
213*0a6a1f1dSLionel Sambuc // WIN32: define {{.*}} void @"\01?cdecl_method_small@Class@@QAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
214*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?cdecl_method_small@Class@@QEAA?AUSmall@@XZ"(%class.Class* %this, %struct.Small* noalias sret %agg.result)
215f4a2713aSLionel Sambuc
cdecl_method_big()216f4a2713aSLionel Sambuc Big __cdecl cdecl_method_big() { return Big(); }
217f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class16cdecl_method_bigEv(%struct.Big* noalias sret %agg.result, %class.Class* %this)
218*0a6a1f1dSLionel Sambuc // WIN32: define {{.*}} void @"\01?cdecl_method_big@Class@@QAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
219*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?cdecl_method_big@Class@@QEAA?AUBig@@XZ"(%class.Class* %this, %struct.Big* noalias sret %agg.result)
220f4a2713aSLionel Sambuc
thiscall_method_arg(Empty s)221f4a2713aSLionel Sambuc void thiscall_method_arg(Empty s) {}
222f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Empty(%class.Class* %this)
223f4a2713aSLionel Sambuc // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUEmpty@@@Z"(%class.Class* %this, %struct.Empty* byval align 4 %s)
224*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUEmpty@@@Z"(%class.Class* %this, i8 %s.coerce)
225f4a2713aSLionel Sambuc
thiscall_method_arg(EmptyWithCtor s)226f4a2713aSLionel Sambuc void thiscall_method_arg(EmptyWithCtor s) {}
227f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13EmptyWithCtor(%class.Class* %this)
228f4a2713aSLionel Sambuc // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUEmptyWithCtor@@@Z"(%class.Class* %this, %struct.EmptyWithCtor* byval align 4 %s)
229*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUEmptyWithCtor@@@Z"(%class.Class* %this, i8 %s.coerce)
230f4a2713aSLionel Sambuc
thiscall_method_arg(Small s)231f4a2713aSLionel Sambuc void thiscall_method_arg(Small s) {}
232f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE5Small(%class.Class* %this, %struct.Small* byval align 4 %s)
233f4a2713aSLionel Sambuc // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmall@@@Z"(%class.Class* %this, %struct.Small* byval align 4 %s)
234*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUSmall@@@Z"(%class.Class* %this, i32 %s.coerce)
235f4a2713aSLionel Sambuc
thiscall_method_arg(SmallWithCtor s)236f4a2713aSLionel Sambuc void thiscall_method_arg(SmallWithCtor s) {}
237f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE13SmallWithCtor(%class.Class* %this, %struct.SmallWithCtor* byval align 4 %s)
238f4a2713aSLionel Sambuc // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUSmallWithCtor@@@Z"(%class.Class* %this, %struct.SmallWithCtor* byval align 4 %s)
239*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUSmallWithCtor@@@Z"(%class.Class* %this, i32 %s.coerce)
240f4a2713aSLionel Sambuc
thiscall_method_arg(Big s)241f4a2713aSLionel Sambuc void thiscall_method_arg(Big s) {}
242f4a2713aSLionel Sambuc // LINUX: define {{.*}} void @_ZN5Class19thiscall_method_argE3Big(%class.Class* %this, %struct.Big* byval align 4 %s)
243f4a2713aSLionel Sambuc // WIN32: define {{.*}} void @"\01?thiscall_method_arg@Class@@QAEXUBig@@@Z"(%class.Class* %this, %struct.Big* byval align 4 %s)
244*0a6a1f1dSLionel Sambuc // WIN64: define linkonce_odr void @"\01?thiscall_method_arg@Class@@QEAAXUBig@@@Z"(%class.Class* %this, %struct.Big* %s)
245f4a2713aSLionel Sambuc };
246f4a2713aSLionel Sambuc
use_class()247f4a2713aSLionel Sambuc void use_class() {
248f4a2713aSLionel Sambuc Class c;
249f4a2713aSLionel Sambuc c.thiscall_method_small();
250f4a2713aSLionel Sambuc c.thiscall_method_small_with_ctor();
251f4a2713aSLionel Sambuc
252f4a2713aSLionel Sambuc c.cdecl_method_small();
253f4a2713aSLionel Sambuc c.cdecl_method_big();
254f4a2713aSLionel Sambuc
255f4a2713aSLionel Sambuc c.thiscall_method_arg(Empty());
256f4a2713aSLionel Sambuc c.thiscall_method_arg(EmptyWithCtor());
257f4a2713aSLionel Sambuc c.thiscall_method_arg(Small());
258f4a2713aSLionel Sambuc c.thiscall_method_arg(SmallWithCtor());
259f4a2713aSLionel Sambuc c.thiscall_method_arg(Big());
260f4a2713aSLionel Sambuc }
261f4a2713aSLionel Sambuc
262f4a2713aSLionel Sambuc struct X {
263f4a2713aSLionel Sambuc X();
264f4a2713aSLionel Sambuc ~X();
265f4a2713aSLionel Sambuc };
g(X)266f4a2713aSLionel Sambuc void g(X) {
267f4a2713aSLionel Sambuc }
268*0a6a1f1dSLionel Sambuc // WIN32: define void @"\01?g@@YAXUX@@@Z"(<{ %struct.X, [3 x i8] }>* inalloca) {{.*}} {
269*0a6a1f1dSLionel Sambuc // WIN32: call x86_thiscallcc void @"\01??1X@@QAE@XZ"(%struct.X* {{.*}})
270f4a2713aSLionel Sambuc // WIN32: }
f()271f4a2713aSLionel Sambuc void f() {
272f4a2713aSLionel Sambuc g(X());
273f4a2713aSLionel Sambuc }
274f4a2713aSLionel Sambuc // WIN32: define void @"\01?f@@YAXXZ"() {{.*}} {
275f4a2713aSLionel Sambuc // WIN32-NOT: call {{.*}} @"\01??1X@@QAE@XZ"
276f4a2713aSLionel Sambuc // WIN32: }
277*0a6a1f1dSLionel Sambuc
278*0a6a1f1dSLionel Sambuc
279*0a6a1f1dSLionel Sambuc namespace test2 {
280*0a6a1f1dSLionel Sambuc // We used to crash on this due to the mixture of POD byval and non-trivial
281*0a6a1f1dSLionel Sambuc // byval.
282*0a6a1f1dSLionel Sambuc
283*0a6a1f1dSLionel Sambuc struct NonTrivial {
284*0a6a1f1dSLionel Sambuc NonTrivial();
285*0a6a1f1dSLionel Sambuc NonTrivial(const NonTrivial &o);
286*0a6a1f1dSLionel Sambuc ~NonTrivial();
287*0a6a1f1dSLionel Sambuc int a;
288*0a6a1f1dSLionel Sambuc };
289*0a6a1f1dSLionel Sambuc struct POD { int b; };
290*0a6a1f1dSLionel Sambuc
291*0a6a1f1dSLionel Sambuc int foo(NonTrivial a, POD b);
bar()292*0a6a1f1dSLionel Sambuc void bar() {
293*0a6a1f1dSLionel Sambuc POD b;
294*0a6a1f1dSLionel Sambuc b.b = 13;
295*0a6a1f1dSLionel Sambuc int c = foo(NonTrivial(), b);
296*0a6a1f1dSLionel Sambuc }
297*0a6a1f1dSLionel Sambuc // WIN32-LABEL: define void @"\01?bar@test2@@YAXXZ"() {{.*}} {
298*0a6a1f1dSLionel Sambuc // WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty:<{ %"struct.test2::NonTrivial", %"struct.test2::POD" }>]]
299*0a6a1f1dSLionel Sambuc // WIN32: getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 1
300*0a6a1f1dSLionel Sambuc // WIN32: call void @llvm.memcpy
301*0a6a1f1dSLionel Sambuc // WIN32: getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 0
302*0a6a1f1dSLionel Sambuc // WIN32: call x86_thiscallcc %"struct.test2::NonTrivial"* @"\01??0NonTrivial@test2@@QAE@XZ"
303*0a6a1f1dSLionel Sambuc // WIN32: call i32 @"\01?foo@test2@@YAHUNonTrivial@1@UPOD@1@@Z"([[argmem_ty]]* inalloca %argmem)
304*0a6a1f1dSLionel Sambuc // WIN32: ret void
305*0a6a1f1dSLionel Sambuc // WIN32: }
306*0a6a1f1dSLionel Sambuc
307*0a6a1f1dSLionel Sambuc }
308*0a6a1f1dSLionel Sambuc
309*0a6a1f1dSLionel Sambuc namespace test3 {
310*0a6a1f1dSLionel Sambuc
311*0a6a1f1dSLionel Sambuc // Check that we padded the inalloca struct to a multiple of 4.
312*0a6a1f1dSLionel Sambuc struct NonTrivial {
313*0a6a1f1dSLionel Sambuc NonTrivial();
314*0a6a1f1dSLionel Sambuc NonTrivial(const NonTrivial &o);
315*0a6a1f1dSLionel Sambuc ~NonTrivial();
316*0a6a1f1dSLionel Sambuc int a;
317*0a6a1f1dSLionel Sambuc };
foo(NonTrivial a,bool b)318*0a6a1f1dSLionel Sambuc void foo(NonTrivial a, bool b) { }
319*0a6a1f1dSLionel Sambuc // WIN32-LABEL: define void @"\01?foo@test3@@YAXUNonTrivial@1@_N@Z"(<{ %"struct.test3::NonTrivial", i8, [3 x i8] }>* inalloca)
320*0a6a1f1dSLionel Sambuc
321*0a6a1f1dSLionel Sambuc }
322*0a6a1f1dSLionel Sambuc
323*0a6a1f1dSLionel Sambuc // We would crash here because the later definition of ForwardDeclare1 results
324*0a6a1f1dSLionel Sambuc // in a different IR type for the value we want to store. However, the alloca's
325*0a6a1f1dSLionel Sambuc // type will use the argument type selected by fn1.
326*0a6a1f1dSLionel Sambuc struct ForwardDeclare1;
327*0a6a1f1dSLionel Sambuc
328*0a6a1f1dSLionel Sambuc typedef void (*FnPtr1)(ForwardDeclare1);
fn1(FnPtr1 a,SmallWithDtor b)329*0a6a1f1dSLionel Sambuc void fn1(FnPtr1 a, SmallWithDtor b) { }
330*0a6a1f1dSLionel Sambuc
331*0a6a1f1dSLionel Sambuc struct ForwardDeclare1 {};
332*0a6a1f1dSLionel Sambuc
fn2(FnPtr1 a,SmallWithDtor b)333*0a6a1f1dSLionel Sambuc void fn2(FnPtr1 a, SmallWithDtor b) { fn1(a, b); };
334*0a6a1f1dSLionel Sambuc // WIN32-LABEL: define void @"\01?fn2@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"
335*0a6a1f1dSLionel Sambuc // WIN32: %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty:<{ {}\*, %struct.SmallWithDtor }>]]* %{{.*}}, i32 0, i32 0
336*0a6a1f1dSLionel Sambuc // WIN32: %[[a1:[^ ]*]] = bitcast {}** %[[a]] to void [[dst_ty:\(%struct.ForwardDeclare1\*\)\*]]*
337*0a6a1f1dSLionel Sambuc // WIN32: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty]]
338*0a6a1f1dSLionel Sambuc // WIN32: %[[gep1:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 1
339*0a6a1f1dSLionel Sambuc // WIN32: %[[bc1:[^ ]*]] = bitcast %struct.SmallWithDtor* %[[gep1]] to i8*
340*0a6a1f1dSLionel Sambuc // WIN32: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[bc1]], i8* {{.*}}, i32 4, i32 4, i1 false)
341*0a6a1f1dSLionel Sambuc // WIN32: %[[a2:[^ ]*]] = load void [[dst_ty]]* %[[a1]], align 4
342*0a6a1f1dSLionel Sambuc // WIN32: %[[gep2:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 0
343*0a6a1f1dSLionel Sambuc // WIN32: %[[addr:[^ ]*]] = bitcast {}** %[[gep2]] to void [[dst_ty]]*
344*0a6a1f1dSLionel Sambuc // WIN32: store void [[dst_ty]] %[[a2]], void [[dst_ty]]* %[[addr]], align 4
345*0a6a1f1dSLionel Sambuc // WIN32: call void @"\01?fn1@@YAXP6AXUForwardDeclare1@@@ZUSmallWithDtor@@@Z"([[argmem_ty]]* inalloca %[[argmem]])
346