1 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC
2 // RUN: %clang_cc1 -mfloat-abi hard -triple armv7-unknown-linux-gnueabi -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM32
3 // RUN: %clang_cc1 -mfloat-abi hard -triple aarch64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
4 // RUN: %clang_cc1 -mfloat-abi hard -triple x86_64-unknown-windows-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=X64
5 // RUN: %clang_cc1 -mfloat-abi hard -triple aarch64-unknown-windows-msvc -emit-llvm -o - %s | FileCheck %s --check-prefix=WOA64
7 #if defined(__x86_64__)
8 #define CC __attribute__((vectorcall))
13 // Test that C++ classes are correctly classified as homogeneous aggregates.
24 struct D1
: Base1
{ // non-homogeneous aggregate
27 struct D2
: Base2
{ // homogeneous aggregate
30 struct D3
: Base1
, Base2
{ // non-homogeneous aggregate
33 struct D4
: Base2
, Base3
{ // homogeneous aggregate
40 struct D5
: I1
, I2
, I3
{}; // homogeneous aggregate
42 // PPC: define{{.*}} void @_Z7func_D12D1(ptr noalias sret(%struct.D1) align 8 %agg.result, [3 x i64] %x.coerce)
43 // ARM32: define{{.*}} arm_aapcs_vfpcc void @_Z7func_D12D1(ptr noalias sret(%struct.D1) align 8 %agg.result, [3 x i64] %x.coerce)
44 // ARM64: define{{.*}} void @_Z7func_D12D1(ptr noalias sret(%struct.D1) align 8 %agg.result, ptr noundef %x)
45 // X64: define dso_local x86_vectorcallcc void @"\01_Z7func_D12D1@@24"(ptr noalias sret(%struct.D1) align 8 %agg.result, ptr noundef %x)
46 D1 CC
func_D1(D1 x
) { return x
; }
48 // PPC: define{{.*}} [3 x double] @_Z7func_D22D2([3 x double] %x.coerce)
49 // ARM32: define{{.*}} arm_aapcs_vfpcc %struct.D2 @_Z7func_D22D2(%struct.D2 %x.coerce)
50 // ARM64: define{{.*}} %struct.D2 @_Z7func_D22D2([3 x double] alignstack(8) %x.coerce)
51 // X64: define dso_local x86_vectorcallcc %struct.D2 @"\01_Z7func_D22D2@@24"(%struct.D2 inreg %x.coerce)
52 D2 CC
func_D2(D2 x
) { return x
; }
54 // PPC: define{{.*}} void @_Z7func_D32D3(ptr noalias sret(%struct.D3) align 8 %agg.result, [4 x i64] %x.coerce)
55 // ARM32: define{{.*}} arm_aapcs_vfpcc void @_Z7func_D32D3(ptr noalias sret(%struct.D3) align 8 %agg.result, [4 x i64] %x.coerce)
56 // ARM64: define{{.*}} void @_Z7func_D32D3(ptr noalias sret(%struct.D3) align 8 %agg.result, ptr noundef %x)
57 D3 CC
func_D3(D3 x
) { return x
; }
59 // PPC: define{{.*}} [4 x double] @_Z7func_D42D4([4 x double] %x.coerce)
60 // ARM32: define{{.*}} arm_aapcs_vfpcc %struct.D4 @_Z7func_D42D4(%struct.D4 %x.coerce)
61 // ARM64: define{{.*}} %struct.D4 @_Z7func_D42D4([4 x double] alignstack(8) %x.coerce)
62 D4 CC
func_D4(D4 x
) { return x
; }
64 D5 CC
func_D5(D5 x
) { return x
; }
65 // PPC: define{{.*}} [3 x double] @_Z7func_D52D5([3 x double] %x.coerce)
66 // ARM32: define{{.*}} arm_aapcs_vfpcc %struct.D5 @_Z7func_D52D5(%struct.D5 %x.coerce)
68 // The C++ multiple inheritance expansion case is a little more complicated, so
69 // do some extra checking.
71 // ARM64-LABEL: define{{.*}} %struct.D5 @_Z7func_D52D5([3 x double] alignstack(8) %x.coerce)
72 // ARM64: store [3 x double] %x.coerce, ptr
78 // Check the call site.
80 // ARM64-LABEL: define{{.*}} void @_Z7call_D5P2D5(ptr noundef %p)
81 // ARM64: load [3 x double], ptr
82 // ARM64: call %struct.D5 @_Z7func_D52D5([3 x double] alignstack(8) %{{.*}})
85 struct Float1
{ float x
; };
86 struct Float2
{ float y
; };
87 struct HVAWithEmptyBase
: Float1
, Empty
, Float2
{ float z
; };
89 // PPC: define{{.*}} void @_Z15with_empty_base16HVAWithEmptyBase([3 x float] %a.coerce)
90 // ARM64: define{{.*}} void @_Z15with_empty_base16HVAWithEmptyBase([3 x float] alignstack(8) %a.coerce)
91 // ARM32: define{{.*}} arm_aapcs_vfpcc void @_Z15with_empty_base16HVAWithEmptyBase(%struct.HVAWithEmptyBase %a.coerce)
92 void CC
with_empty_base(HVAWithEmptyBase a
) {}
94 // WOA64: define dso_local void @"?with_empty_base@@YAXUHVAWithEmptyBase@@@Z"([2 x i64] %{{.*}})
95 // X64: define dso_local x86_vectorcallcc void @"\01_Z15with_empty_base16HVAWithEmptyBase@@16"(%struct.HVAWithEmptyBase inreg %a.coerce)
97 struct HVAWithEmptyBitField
: Float1
, Float2
{
98 int : 0; // Takes no space.
102 // PPC: define{{.*}} void @_Z19with_empty_bitfield20HVAWithEmptyBitField([3 x float] %a.coerce)
103 // ARM64: define{{.*}} void @_Z19with_empty_bitfield20HVAWithEmptyBitField([3 x float] alignstack(8) %a.coerce)
104 // ARM32: define{{.*}} arm_aapcs_vfpcc void @_Z19with_empty_bitfield20HVAWithEmptyBitField(%struct.HVAWithEmptyBitField %a.coerce)
105 // X64: define dso_local x86_vectorcallcc void @"\01_Z19with_empty_bitfield20HVAWithEmptyBitField@@16"(%struct.HVAWithEmptyBitField inreg %a.coerce)
106 void CC
with_empty_bitfield(HVAWithEmptyBitField a
) {}
109 // MSVC on Arm includes "isCXX14Aggregate" as part of its definition of
110 // Homogeneous Floating-point Aggregate (HFA). Additionally, it has a different
111 // handling of C++14 aggregates, which can lead to confusion.
113 // Pod is a trivial HFA.
117 // Not an aggregate according to C++14 spec => not HFA according to MSVC.
118 struct NotCXX14Aggregate
{
122 // NotPod is a C++14 aggregate. But not HFA, because it contains
123 // NotCXX14Aggregate (which itself is not HFA because it's not a C++14
129 // A class with a base is returned using the sret calling convetion by MSVC.
130 struct HasEmptyBase
: public Empty
{
133 struct HasPodBase
: public Pod
{};
134 // WOA64-LABEL: define dso_local %"struct.pr47611::Pod" @"?copy@pr47611@@YA?AUPod@1@PEAU21@@Z"(ptr noundef %x)
135 Pod
copy(Pod
*x
) { return *x
; } // MSVC: ldp d0,d1,[x0], Clang: ldp d0,d1,[x0]
136 // WOA64-LABEL: define dso_local void @"?copy@pr47611@@YA?AUNotCXX14Aggregate@1@PEAU21@@Z"(ptr inreg noalias sret(%"struct.pr47611::NotCXX14Aggregate") align 8 %agg.result, ptr noundef %x)
137 NotCXX14Aggregate
copy(NotCXX14Aggregate
*x
) { return *x
; } // MSVC: stp x8,x9,[x0], Clang: str q0,[x0]
138 // WOA64-LABEL: define dso_local [2 x i64] @"?copy@pr47611@@YA?AUNotPod@1@PEAU21@@Z"(ptr noundef %x)
139 NotPod
copy(NotPod
*x
) { return *x
; }
140 // WOA64-LABEL: define dso_local void @"?copy@pr47611@@YA?AUHasEmptyBase@1@PEAU21@@Z"(ptr inreg noalias sret(%"struct.pr47611::HasEmptyBase") align 8 %agg.result, ptr noundef %x)
141 HasEmptyBase
copy(HasEmptyBase
*x
) { return *x
; }
142 // WOA64-LABEL: define dso_local void @"?copy@pr47611@@YA?AUHasPodBase@1@PEAU21@@Z"(ptr inreg noalias sret(%"struct.pr47611::HasPodBase") align 8 %agg.result, ptr noundef %x)
143 HasPodBase
copy(HasPodBase
*x
) { return *x
; }
145 void call_copy_pod(Pod
*pod
) {
147 // WOA64-LABEL: define dso_local void @"?call_copy_pod@pr47611@@YAXPEAUPod@1@@Z"
148 // WOA64: %{{.*}} = call %"struct.pr47611::Pod" @"?copy@pr47611@@YA?AUPod@1@PEAU21@@Z"(ptr noundef %{{.*}})
151 void call_copy_notcxx14aggregate(NotCXX14Aggregate
*notcxx14aggregate
) {
152 *notcxx14aggregate
= copy(notcxx14aggregate
);
153 // WOA64-LABEL: define dso_local void @"?call_copy_notcxx14aggregate@pr47611@@YAXPEAUNotCXX14Aggregate@1@@Z"
154 // WOA64: call void @"?copy@pr47611@@YA?AUNotCXX14Aggregate@1@PEAU21@@Z"(ptr inreg sret(%"struct.pr47611::NotCXX14Aggregate") align 8 %{{.*}}, ptr noundef %{{.*}})
157 void call_copy_notpod(NotPod
*notPod
) {
158 *notPod
= copy(notPod
);
159 // WOA64-LABEL: define dso_local void @"?call_copy_notpod@pr47611@@YAXPEAUNotPod@1@@Z"
160 // WOA64: %{{.*}} = call [2 x i64] @"?copy@pr47611@@YA?AUNotPod@1@PEAU21@@Z"(ptr noundef %{{.*}})
163 void call_copy_hasemptybase(HasEmptyBase
*hasEmptyBase
) {
164 *hasEmptyBase
= copy(hasEmptyBase
);
165 // WOA64-LABEL: define dso_local void @"?call_copy_hasemptybase@pr47611@@YAXPEAUHasEmptyBase@1@@Z"
166 // WOA64: call void @"?copy@pr47611@@YA?AUHasEmptyBase@1@PEAU21@@Z"(ptr inreg sret(%"struct.pr47611::HasEmptyBase") align 8 %{{.*}}, ptr noundef %{{.*}})
169 void call_copy_haspodbase(HasPodBase
*hasPodBase
) {
170 *hasPodBase
= copy(hasPodBase
);
171 // WOA64-LABEL: define dso_local void @"?call_copy_haspodbase@pr47611@@YAXPEAUHasPodBase@1@@Z"
172 // WOA64: call void @"?copy@pr47611@@YA?AUHasPodBase@1@PEAU21@@Z"(ptr inreg sret(%"struct.pr47611::HasPodBase") align 8 %{{.*}}, ptr noundef %{{.*}})
174 } // namespace pr47611
176 namespace protected_member
{
183 double foo(HFA v
) { return v
.x
+ v
.y
; }
184 // WOA64: define dso_local noundef double @"?foo@protected_member@@YANUHFA@1@@Z"([3 x double] %{{.*}})
186 namespace private_member
{
193 double foo(HFA v
) { return v
.x
+ v
.y
; }
194 // WOA64: define dso_local noundef double @"?foo@private_member@@YANUHFA@1@@Z"([3 x double] %{{.*}})
196 namespace polymorphic
{
203 double foo(NonHFA v
) { return v
.x
+ v
.y
; }
204 // WOA64: define dso_local noundef double @"?foo@polymorphic@@YANUNonHFA@1@@Z"(ptr noundef %{{.*}})
206 namespace trivial_copy_assignment
{
211 HFA
&operator=(const HFA
&) = default;
213 double foo(HFA v
) { return v
.x
+ v
.y
; }
214 // WOA64: define dso_local noundef double @"?foo@trivial_copy_assignment@@YANUHFA@1@@Z"([3 x double] %{{.*}})
216 namespace non_trivial_copy_assignment
{
221 NonHFA
&operator=(const NonHFA
&);
223 double foo(NonHFA v
) { return v
.x
+ v
.y
; }
224 // WOA64: define dso_local noundef double @"?foo@non_trivial_copy_assignment@@YANUNonHFA@1@@Z"(ptr noundef %{{.*}})
226 namespace user_provided_ctor
{
233 double foo(HFA v
) { return v
.x
+ v
.y
; }
234 // WOA64: define dso_local noundef double @"?foo@user_provided_ctor@@YANUHFA@1@@Z"([3 x double] %{{.*}})
236 namespace trivial_dtor
{
243 double foo(HFA v
) { return v
.x
+ v
.y
; }
244 // WOA64: define dso_local noundef double @"?foo@trivial_dtor@@YANUHFA@1@@Z"([3 x double] %{{.*}})
246 namespace non_trivial_dtor
{
253 double foo(NonHFA v
) { return v
.x
+ v
.y
; }
254 // WOA64: define dso_local noundef double @"?foo@non_trivial_dtor@@YANUNonHFA@1@@Z"(ptr noundef %{{.*}})
256 namespace non_empty_base
{
257 struct non_empty_base
{ double d
; };
258 struct HFA
: non_empty_base
{
263 double foo(HFA v
) { return v
.x
+ v
.y
; }
264 // WOA64: define dso_local noundef double @"?foo@non_empty_base@@YANUHFA@1@@Z"([4 x double] %{{.*}})
266 namespace empty_field
{
274 double foo(NonHFA v
) { return v
.x
+ v
.y
; }
275 // WOA64: define dso_local noundef double @"?foo@empty_field@@YANUNonHFA@1@@Z"(ptr noundef %{{.*}})
277 namespace non_empty_field
{
278 struct non_empty
{ double d
; };
285 double foo(HFA v
) { return v
.x
+ v
.y
; }
286 // WOA64: define dso_local noundef double @"?foo@non_empty_field@@YANUHFA@1@@Z"([4 x double] %{{.*}})
290 // HVAs don't follow the normal rules for return values. That means they can
291 // have base classes, user-defined ctors, and protected/private members.
292 // (The same restrictions that apply to HVA arguments still apply.)
293 typedef double V
__attribute((ext_vector_type(2)));
294 struct base
{ V v
; };
295 struct test
: base
{ test(double); protected: V v2
;};
296 test
f(test
*x
) { return *x
; }
297 // WOA64: define dso_local %"struct.pr62223::test" @"?f@pr62223@@YA?AUtest@1@PEAU21@@Z"(ptr noundef %{{.*}})
299 // The above rule only apples to HVAs, not HFAs.
300 struct base2
{ double v
; };
301 struct test2
: base2
{ test2(double); protected: double v2
;};
302 test2
f(test2
*x
) { return *x
; }
303 // WOA64: define dso_local void @"?f@pr62223@@YA?AUtest2@1@PEAU21@@Z"(ptr inreg noalias sret(%"struct.pr62223::test2") align 8 %{{.*}}, ptr noundef %{{.*}})