Reid Kleckner | e9f6a71 | 2014-10-31 17:10:41 +0000 | [diff] [blame^] | 1 | // RUNxX: %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-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 |
| 4 | |
| 5 | // Test that C++ classes are correctly classified as homogeneous aggregates. |
| 6 | |
| 7 | struct Base1 { |
| 8 | int x; |
| 9 | }; |
| 10 | struct Base2 { |
| 11 | double x; |
| 12 | }; |
| 13 | struct Base3 { |
| 14 | double x; |
| 15 | }; |
| 16 | struct D1 : Base1 { // non-homogeneous aggregate |
| 17 | double y, z; |
| 18 | }; |
| 19 | struct D2 : Base2 { // homogeneous aggregate |
| 20 | double y, z; |
| 21 | }; |
| 22 | struct D3 : Base1, Base2 { // non-homogeneous aggregate |
| 23 | double y, z; |
| 24 | }; |
| 25 | struct D4 : Base2, Base3 { // homogeneous aggregate |
| 26 | double y, z; |
| 27 | }; |
| 28 | |
| 29 | struct I1 : Base2 {}; |
| 30 | struct I2 : Base2 {}; |
| 31 | struct I3 : Base2 {}; |
| 32 | struct D5 : I1, I2, I3 {}; // homogeneous aggregate |
| 33 | |
| 34 | // PPC: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, [3 x i64] %x.coerce) |
| 35 | // ARM32: define arm_aapcs_vfpcc void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, { [3 x i64] } %x.coerce) |
| 36 | // ARM64: define void @_Z7func_D12D1(%struct.D1* noalias sret %agg.result, %struct.D1* %x) |
| 37 | D1 func_D1(D1 x) { return x; } |
| 38 | |
| 39 | // PPC: define [3 x double] @_Z7func_D22D2([3 x double] %x.coerce) |
| 40 | // ARM32: define arm_aapcs_vfpcc %struct.D2 @_Z7func_D22D2(%struct.D2 %x.coerce) |
| 41 | // ARM64: define %struct.D2 @_Z7func_D22D2(double %x.0, double %x.1, double %x.2) |
| 42 | D2 func_D2(D2 x) { return x; } |
| 43 | |
| 44 | // PPC: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, [4 x i64] %x.coerce) |
| 45 | // ARM32: define arm_aapcs_vfpcc void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, { [4 x i64] } %x.coerce) |
| 46 | // ARM64: define void @_Z7func_D32D3(%struct.D3* noalias sret %agg.result, %struct.D3* %x) |
| 47 | D3 func_D3(D3 x) { return x; } |
| 48 | |
| 49 | // PPC: define [4 x double] @_Z7func_D42D4([4 x double] %x.coerce) |
| 50 | // ARM32: define arm_aapcs_vfpcc %struct.D4 @_Z7func_D42D4(%struct.D4 %x.coerce) |
| 51 | // ARM64: define %struct.D4 @_Z7func_D42D4(double %x.0, double %x.1, double %x.2, double %x.3) |
| 52 | D4 func_D4(D4 x) { return x; } |
| 53 | |
| 54 | D5 func_D5(D5 x) { return x; } |
| 55 | // PPC: define [3 x double] @_Z7func_D52D5([3 x double] %x.coerce) |
| 56 | // ARM32: define arm_aapcs_vfpcc %struct.D5 @_Z7func_D52D5(%struct.D5 %x.coerce) |
| 57 | |
| 58 | // The C++ multiple inheritance expansion case is a little more complicated, so |
| 59 | // do some extra checking. |
| 60 | // |
| 61 | // ARM64-LABEL: define %struct.D5 @_Z7func_D52D5(double %x.0, double %x.1, double %x.2) |
| 62 | // ARM64: bitcast %struct.D5* %{{.*}} to %struct.I1* |
| 63 | // ARM64: bitcast %struct.I1* %{{.*}} to %struct.Base2* |
| 64 | // ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0 |
| 65 | // ARM64: store double %x.0, double* |
| 66 | // ARM64: getelementptr inbounds i8* %{{.*}}, i64 8 |
| 67 | // ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0 |
| 68 | // ARM64: store double %x.1, double* |
| 69 | // ARM64: getelementptr inbounds i8* %{{.*}}, i64 16 |
| 70 | // ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0 |
| 71 | // ARM64: store double %x.2, double* |
| 72 | |
| 73 | void call_D5(D5 *p) { |
| 74 | func_D5(*p); |
| 75 | } |
| 76 | |
| 77 | // Check the call site. |
| 78 | // |
| 79 | // ARM64-LABEL: define void @_Z7call_D5P2D5(%struct.D5* %p) |
| 80 | // ARM64: bitcast %struct.D5* %{{.*}} to %struct.I1* |
| 81 | // ARM64: bitcast %struct.I1* %{{.*}} to %struct.Base2* |
| 82 | // ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0 |
| 83 | // ARM64: load double* |
| 84 | // ARM64: getelementptr inbounds i8* %{{.*}}, i64 8 |
| 85 | // ARM64: bitcast i8* %{{.*}} to %struct.I2* |
| 86 | // ARM64: bitcast %struct.I2* %{{.*}} to %struct.Base2* |
| 87 | // ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0 |
| 88 | // ARM64: load double* |
| 89 | // ARM64: getelementptr inbounds i8* %{{.*}}, i64 16 |
| 90 | // ARM64: bitcast i8* %{{.*}} to %struct.I3* |
| 91 | // ARM64: bitcast %struct.I3* %{{.*}} to %struct.Base2* |
| 92 | // ARM64: getelementptr inbounds %struct.Base2* %{{.*}}, i32 0, i32 0 |
| 93 | // ARM64: load double* |
| 94 | // ARM64: call %struct.D5 @_Z7func_D52D5(double %{{.*}}, double %{{.*}}, double %{{.*}}) |