blob: 4800aacbfe5e7ae6219d504cedbbe7cbc289c880 [file] [log] [blame]
Reid Kleckner80944df2014-10-31 22:00:51 +00001// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC
Reid Klecknere9f6a712014-10-31 17:10:41 +00002// RUN: %clang_cc1 -mfloat-abi hard -triple armv7-unknown-linux-gnu -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
Reid Kleckner80944df2014-10-31 22:00:51 +00004// RUN: %clang_cc1 -mfloat-abi hard -triple x86_64-unknown-windows-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=X64
5
6#if defined(__x86_64__)
7#define CC __attribute__((vectorcall))
8#else
9#define CC
10#endif
Reid Klecknere9f6a712014-10-31 17:10:41 +000011
12// Test that C++ classes are correctly classified as homogeneous aggregates.
13
14struct Base1 {
15 int x;
16};
17struct Base2 {
18 double x;
19};
20struct Base3 {
21 double x;
22};
23struct D1 : Base1 { // non-homogeneous aggregate
24 double y, z;
25};
26struct D2 : Base2 { // homogeneous aggregate
27 double y, z;
28};
29struct D3 : Base1, Base2 { // non-homogeneous aggregate
30 double y, z;
31};
32struct D4 : Base2, Base3 { // homogeneous aggregate
33 double y, z;
34};
35
36struct I1 : Base2 {};
37struct I2 : Base2 {};
38struct I3 : Base2 {};
39struct D5 : I1, I2, I3 {}; // homogeneous aggregate
40
41// PPC: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, [3 x i64] %x.coerce)
Tim Northover5a1558e2014-11-07 22:30:50 +000042// ARM32: define arm_aapcs_vfpcc void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, [3 x i64] %x.coerce)
Reid Klecknere9f6a712014-10-31 17:10:41 +000043// ARM64: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, %struct.D1* %x)
Reid Kleckner80944df2014-10-31 22:00:51 +000044// X64: define x86_vectorcallcc void @"\01_Z7func_D12D1@@24"(%struct.D1* noalias sret %agg.result, %struct.D1* %x)
45D1 CC func_D1(D1 x) { return x; }
Reid Klecknere9f6a712014-10-31 17:10:41 +000046
47// PPC: define [3 x double] @_Z7func_D22D2([3 x double] %x.coerce)
48// ARM32: define arm_aapcs_vfpcc %struct.D2 @_Z7func_D22D2(%struct.D2 %x.coerce)
49// ARM64: define %struct.D2 @_Z7func_D22D2(double %x.0, double %x.1, double %x.2)
Reid Kleckner80944df2014-10-31 22:00:51 +000050// X64: define x86_vectorcallcc %struct.D2 @"\01_Z7func_D22D2@@24"(double %x.0, double %x.1, double %x.2)
51D2 CC func_D2(D2 x) { return x; }
Reid Klecknere9f6a712014-10-31 17:10:41 +000052
53// PPC: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce)
Tim Northover5a1558e2014-11-07 22:30:50 +000054// ARM32: define arm_aapcs_vfpcc void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce)
Reid Klecknere9f6a712014-10-31 17:10:41 +000055// ARM64: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, %struct.D3* %x)
Reid Kleckner80944df2014-10-31 22:00:51 +000056D3 CC func_D3(D3 x) { return x; }
Reid Klecknere9f6a712014-10-31 17:10:41 +000057
58// PPC: define [4 x double] @_Z7func_D42D4([4 x double] %x.coerce)
59// ARM32: define arm_aapcs_vfpcc %struct.D4 @_Z7func_D42D4(%struct.D4 %x.coerce)
60// ARM64: define %struct.D4 @_Z7func_D42D4(double %x.0, double %x.1, double %x.2, double %x.3)
Reid Kleckner80944df2014-10-31 22:00:51 +000061D4 CC func_D4(D4 x) { return x; }
Reid Klecknere9f6a712014-10-31 17:10:41 +000062
Reid Kleckner80944df2014-10-31 22:00:51 +000063D5 CC func_D5(D5 x) { return x; }
Reid Klecknere9f6a712014-10-31 17:10:41 +000064// PPC: define [3 x double] @_Z7func_D52D5([3 x double] %x.coerce)
65// ARM32: define arm_aapcs_vfpcc %struct.D5 @_Z7func_D52D5(%struct.D5 %x.coerce)
66
67// The C++ multiple inheritance expansion case is a little more complicated, so
68// do some extra checking.
69//
70// ARM64-LABEL: define %struct.D5 @_Z7func_D52D5(double %x.0, double %x.1, double %x.2)
71// ARM64: bitcast %struct.D5* %{{.*}} to %struct.I1*
72// ARM64: bitcast %struct.I1* %{{.*}} to %struct.Base2*
73// ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0
74// ARM64: store double %x.0, double*
75// ARM64: getelementptr inbounds i8* %{{.*}}, i64 8
76// ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0
77// ARM64: store double %x.1, double*
78// ARM64: getelementptr inbounds i8* %{{.*}}, i64 16
79// ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0
80// ARM64: store double %x.2, double*
81
82void call_D5(D5 *p) {
83 func_D5(*p);
84}
85
86// Check the call site.
87//
88// ARM64-LABEL: define void @_Z7call_D5P2D5(%struct.D5* %p)
89// ARM64: bitcast %struct.D5* %{{.*}} to %struct.I1*
90// ARM64: bitcast %struct.I1* %{{.*}} to %struct.Base2*
91// ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0
92// ARM64: load double*
93// ARM64: getelementptr inbounds i8* %{{.*}}, i64 8
94// ARM64: bitcast i8* %{{.*}} to %struct.I2*
95// ARM64: bitcast %struct.I2* %{{.*}} to %struct.Base2*
96// ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0
97// ARM64: load double*
98// ARM64: getelementptr inbounds i8* %{{.*}}, i64 16
99// ARM64: bitcast i8* %{{.*}} to %struct.I3*
100// ARM64: bitcast %struct.I3* %{{.*}} to %struct.Base2*
101// ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0
102// ARM64: load double*
103// ARM64: call %struct.D5 @_Z7func_D52D5(double %{{.*}}, double %{{.*}}, double %{{.*}})
Reid Kleckner80944df2014-10-31 22:00:51 +0000104
105struct Empty { };
106struct Float1 { float x; };
107struct Float2 { float y; };
108struct HVAWithEmptyBase : Float1, Empty, Float2 { float z; };
109
110// PPC: define void @_Z15with_empty_base16HVAWithEmptyBase([3 x float] %a.coerce)
111// ARM64: define void @_Z15with_empty_base16HVAWithEmptyBase(float %a.0, float %a.1, float %a.2)
112// ARM32: define arm_aapcs_vfpcc void @_Z15with_empty_base16HVAWithEmptyBase(%struct.HVAWithEmptyBase %a.coerce)
113void CC with_empty_base(HVAWithEmptyBase a) {}
114
115// FIXME: MSVC doesn't consider this an HVA becuase of the empty base.
116// X64: define x86_vectorcallcc void @"\01_Z15with_empty_base16HVAWithEmptyBase@@16"(float %a.0, float %a.1, float %a.2)
117
118struct HVAWithEmptyBitField : Float1, Float2 {
119 int : 0; // Takes no space.
120 float z;
121};
122
123// PPC: define void @_Z19with_empty_bitfield20HVAWithEmptyBitField([3 x float] %a.coerce)
124// ARM64: define void @_Z19with_empty_bitfield20HVAWithEmptyBitField(float %a.0, float %a.1, float %a.2)
125// ARM32: define arm_aapcs_vfpcc void @_Z19with_empty_bitfield20HVAWithEmptyBitField(%struct.HVAWithEmptyBitField %a.coerce)
126// X64: define x86_vectorcallcc void @"\01_Z19with_empty_bitfield20HVAWithEmptyBitField@@16"(float %a.0, float %a.1, float %a.2)
127void CC with_empty_bitfield(HVAWithEmptyBitField a) {}