1*67e74705SXin Li // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC
2*67e74705SXin Li // RUN: %clang_cc1 -mfloat-abi hard -triple armv7-unknown-linux-gnueabi -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM32
3*67e74705SXin Li // RUN: %clang_cc1 -mfloat-abi hard -triple aarch64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
4*67e74705SXin Li // RUN: %clang_cc1 -mfloat-abi hard -triple x86_64-unknown-windows-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=X64
5*67e74705SXin Li
6*67e74705SXin Li #if defined(__x86_64__)
7*67e74705SXin Li #define CC __attribute__((vectorcall))
8*67e74705SXin Li #else
9*67e74705SXin Li #define CC
10*67e74705SXin Li #endif
11*67e74705SXin Li
12*67e74705SXin Li // Test that C++ classes are correctly classified as homogeneous aggregates.
13*67e74705SXin Li
14*67e74705SXin Li struct Base1 {
15*67e74705SXin Li int x;
16*67e74705SXin Li };
17*67e74705SXin Li struct Base2 {
18*67e74705SXin Li double x;
19*67e74705SXin Li };
20*67e74705SXin Li struct Base3 {
21*67e74705SXin Li double x;
22*67e74705SXin Li };
23*67e74705SXin Li struct D1 : Base1 { // non-homogeneous aggregate
24*67e74705SXin Li double y, z;
25*67e74705SXin Li };
26*67e74705SXin Li struct D2 : Base2 { // homogeneous aggregate
27*67e74705SXin Li double y, z;
28*67e74705SXin Li };
29*67e74705SXin Li struct D3 : Base1, Base2 { // non-homogeneous aggregate
30*67e74705SXin Li double y, z;
31*67e74705SXin Li };
32*67e74705SXin Li struct D4 : Base2, Base3 { // homogeneous aggregate
33*67e74705SXin Li double y, z;
34*67e74705SXin Li };
35*67e74705SXin Li
36*67e74705SXin Li struct I1 : Base2 {};
37*67e74705SXin Li struct I2 : Base2 {};
38*67e74705SXin Li struct I3 : Base2 {};
39*67e74705SXin Li struct D5 : I1, I2, I3 {}; // homogeneous aggregate
40*67e74705SXin Li
41*67e74705SXin Li // PPC: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, [3 x i64] %x.coerce)
42*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, [3 x i64] %x.coerce)
43*67e74705SXin Li // ARM64: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, %struct.D1* %x)
44*67e74705SXin Li // X64: define x86_vectorcallcc void @"\01_Z7func_D12D1@@24"(%struct.D1* noalias sret %agg.result, %struct.D1* %x)
func_D1(D1 x)45*67e74705SXin Li D1 CC func_D1(D1 x) { return x; }
46*67e74705SXin Li
47*67e74705SXin Li // PPC: define [3 x double] @_Z7func_D22D2([3 x double] %x.coerce)
48*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc %struct.D2 @_Z7func_D22D2(%struct.D2 %x.coerce)
49*67e74705SXin Li // ARM64: define %struct.D2 @_Z7func_D22D2([3 x double] %x.coerce)
50*67e74705SXin Li // X64: define x86_vectorcallcc %struct.D2 @"\01_Z7func_D22D2@@24"(double %x.0, double %x.1, double %x.2)
func_D2(D2 x)51*67e74705SXin Li D2 CC func_D2(D2 x) { return x; }
52*67e74705SXin Li
53*67e74705SXin Li // PPC: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce)
54*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce)
55*67e74705SXin Li // ARM64: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, %struct.D3* %x)
func_D3(D3 x)56*67e74705SXin Li D3 CC func_D3(D3 x) { return x; }
57*67e74705SXin Li
58*67e74705SXin Li // PPC: define [4 x double] @_Z7func_D42D4([4 x double] %x.coerce)
59*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc %struct.D4 @_Z7func_D42D4(%struct.D4 %x.coerce)
60*67e74705SXin Li // ARM64: define %struct.D4 @_Z7func_D42D4([4 x double] %x.coerce)
func_D4(D4 x)61*67e74705SXin Li D4 CC func_D4(D4 x) { return x; }
62*67e74705SXin Li
func_D5(D5 x)63*67e74705SXin Li D5 CC func_D5(D5 x) { return x; }
64*67e74705SXin Li // PPC: define [3 x double] @_Z7func_D52D5([3 x double] %x.coerce)
65*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc %struct.D5 @_Z7func_D52D5(%struct.D5 %x.coerce)
66*67e74705SXin Li
67*67e74705SXin Li // The C++ multiple inheritance expansion case is a little more complicated, so
68*67e74705SXin Li // do some extra checking.
69*67e74705SXin Li //
70*67e74705SXin Li // ARM64-LABEL: define %struct.D5 @_Z7func_D52D5([3 x double] %x.coerce)
71*67e74705SXin Li // ARM64: bitcast %struct.D5* %{{.*}} to [3 x double]*
72*67e74705SXin Li // ARM64: store [3 x double] %x.coerce, [3 x double]*
73*67e74705SXin Li
call_D5(D5 * p)74*67e74705SXin Li void call_D5(D5 *p) {
75*67e74705SXin Li func_D5(*p);
76*67e74705SXin Li }
77*67e74705SXin Li
78*67e74705SXin Li // Check the call site.
79*67e74705SXin Li //
80*67e74705SXin Li // ARM64-LABEL: define void @_Z7call_D5P2D5(%struct.D5* %p)
81*67e74705SXin Li // ARM64: load [3 x double], [3 x double]*
82*67e74705SXin Li // ARM64: call %struct.D5 @_Z7func_D52D5([3 x double] %{{.*}})
83*67e74705SXin Li
84*67e74705SXin Li struct Empty { };
85*67e74705SXin Li struct Float1 { float x; };
86*67e74705SXin Li struct Float2 { float y; };
87*67e74705SXin Li struct HVAWithEmptyBase : Float1, Empty, Float2 { float z; };
88*67e74705SXin Li
89*67e74705SXin Li // PPC: define void @_Z15with_empty_base16HVAWithEmptyBase([3 x float] %a.coerce)
90*67e74705SXin Li // ARM64: define void @_Z15with_empty_base16HVAWithEmptyBase([3 x float] %a.coerce)
91*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc void @_Z15with_empty_base16HVAWithEmptyBase(%struct.HVAWithEmptyBase %a.coerce)
with_empty_base(HVAWithEmptyBase a)92*67e74705SXin Li void CC with_empty_base(HVAWithEmptyBase a) {}
93*67e74705SXin Li
94*67e74705SXin Li // FIXME: MSVC doesn't consider this an HVA because of the empty base.
95*67e74705SXin Li // X64: define x86_vectorcallcc void @"\01_Z15with_empty_base16HVAWithEmptyBase@@16"(float %a.0, float %a.1, float %a.2)
96*67e74705SXin Li
97*67e74705SXin Li struct HVAWithEmptyBitField : Float1, Float2 {
98*67e74705SXin Li int : 0; // Takes no space.
99*67e74705SXin Li float z;
100*67e74705SXin Li };
101*67e74705SXin Li
102*67e74705SXin Li // PPC: define void @_Z19with_empty_bitfield20HVAWithEmptyBitField([3 x float] %a.coerce)
103*67e74705SXin Li // ARM64: define void @_Z19with_empty_bitfield20HVAWithEmptyBitField([3 x float] %a.coerce)
104*67e74705SXin Li // ARM32: define arm_aapcs_vfpcc void @_Z19with_empty_bitfield20HVAWithEmptyBitField(%struct.HVAWithEmptyBitField %a.coerce)
105*67e74705SXin Li // X64: define x86_vectorcallcc void @"\01_Z19with_empty_bitfield20HVAWithEmptyBitField@@16"(float %a.0, float %a.1, float %a.2)
with_empty_bitfield(HVAWithEmptyBitField a)106*67e74705SXin Li void CC with_empty_bitfield(HVAWithEmptyBitField a) {}
107