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