Reid Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s --check-prefix=PPC |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 2 | // 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 Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 4 | // 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 Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 11 | |
| 12 | // Test that C++ classes are correctly classified as homogeneous aggregates. |
| 13 | |
| 14 | struct Base1 { |
| 15 | int x; |
| 16 | }; |
| 17 | struct Base2 { |
| 18 | double x; |
| 19 | }; |
| 20 | struct Base3 { |
| 21 | double x; |
| 22 | }; |
| 23 | struct D1 : Base1 { // non-homogeneous aggregate |
| 24 | double y, z; |
| 25 | }; |
| 26 | struct D2 : Base2 { // homogeneous aggregate |
| 27 | double y, z; |
| 28 | }; |
| 29 | struct D3 : Base1, Base2 { // non-homogeneous aggregate |
| 30 | double y, z; |
| 31 | }; |
| 32 | struct D4 : Base2, Base3 { // homogeneous aggregate |
| 33 | double y, z; |
| 34 | }; |
| 35 | |
| 36 | struct I1 : Base2 {}; |
| 37 | struct I2 : Base2 {}; |
| 38 | struct I3 : Base2 {}; |
| 39 | struct 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 Northover | 5a1558e | 2014-11-07 22:30:50 +0000 | [diff] [blame^] | 42 | // ARM32: define arm_aapcs_vfpcc void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, [3 x i64] %x.coerce) |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 43 | // ARM64: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, %struct.D1* %x) |
Reid Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 44 | // X64: define x86_vectorcallcc void @"\01_Z7func_D12D1@@24"(%struct.D1* noalias sret %agg.result, %struct.D1* %x) |
| 45 | D1 CC func_D1(D1 x) { return x; } |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 46 | |
| 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 Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 50 | // X64: define x86_vectorcallcc %struct.D2 @"\01_Z7func_D22D2@@24"(double %x.0, double %x.1, double %x.2) |
| 51 | D2 CC func_D2(D2 x) { return x; } |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 52 | |
| 53 | // PPC: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce) |
Tim Northover | 5a1558e | 2014-11-07 22:30:50 +0000 | [diff] [blame^] | 54 | // ARM32: define arm_aapcs_vfpcc void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce) |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 55 | // ARM64: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, %struct.D3* %x) |
Reid Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 56 | D3 CC func_D3(D3 x) { return x; } |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 57 | |
| 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 Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 61 | D4 CC func_D4(D4 x) { return x; } |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 62 | |
Reid Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 63 | D5 CC func_D5(D5 x) { return x; } |
Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame] | 64 | // 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 | |
| 82 | void 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 Kleckner | 80944df | 2014-10-31 22:00:51 +0000 | [diff] [blame] | 104 | |
| 105 | struct Empty { }; |
| 106 | struct Float1 { float x; }; |
| 107 | struct Float2 { float y; }; |
| 108 | struct 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) |
| 113 | void 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 | |
| 118 | struct 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) |
| 127 | void CC with_empty_bitfield(HVAWithEmptyBitField a) {} |