1 // RUN: %clang_cc1 -triple riscv32 -emit-llvm %s -o - \
2 // RUN: | FileCheck -check-prefixes=ILP32,ILP32-ILP32F,ILP32-ILP32F-ILP32D %s
3 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-abi ilp32f -emit-llvm %s -o - \
4 // RUN: | FileCheck -check-prefixes=ILP32F,ILP32-ILP32F,ILP32F-ILP32D,ILP32-ILP32F-ILP32D %s
5 // RUN: %clang_cc1 -triple riscv32 -target-feature +f -target-feature +d -target-abi ilp32d -emit-llvm %s -o - \
6 // RUN: | FileCheck -check-prefixes=ILP32D,ILP32F-ILP32D,ILP32-ILP32F-ILP32D %s
7
8 // RUN: %clang_cc1 -triple riscv64 -emit-llvm %s -o - \
9 // RUN: | FileCheck -check-prefixes=LP64,LP64-LP64F,LP64-LP64F-LP64D %s
10 // RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-abi lp64f -emit-llvm %s -o - \
11 // RUN: | FileCheck -check-prefixes=LP64F,LP64-LP64F,LP64F-LP64D,LP64-LP64F-LP64D %s
12 // RUN: %clang_cc1 -triple riscv64 -target-feature +f -target-feature +d -target-abi lp64d -emit-llvm %s -o - \
13 // RUN: | FileCheck -check-prefixes=LP64D,LP64F-LP64D,LP64-LP64F-LP64D %s
14
15 #include <stdint.h>
16
17 // Ensure that fields inherited from a parent struct are treated in the same
18 // way as fields directly in the child for the purposes of RISC-V ABI rules.
19
20 struct parent1_int32_s {
21 int32_t i1;
22 };
23
24 struct child1_int32_s : parent1_int32_s {
25 int32_t i2;
26 };
27
28 // ILP32-ILP32F-ILP32D-LABEL: define{{.*}} [2 x i32] @_Z30int32_int32_struct_inheritance14child1_int32_s([2 x i32] %a.coerce)
29 // LP64-LP64F-LP64D-LABEL: define{{.*}} i64 @_Z30int32_int32_struct_inheritance14child1_int32_s(i64 %a.coerce)
int32_int32_struct_inheritance(struct child1_int32_s a)30 struct child1_int32_s int32_int32_struct_inheritance(struct child1_int32_s a) {
31 return a;
32 }
33
34 struct parent2_int32_s {
35 int32_t i1;
36 };
37
38 struct child2_float_s : parent2_int32_s {
39 float f1;
40 };
41
42 // ILP32: define{{.*}} [2 x i32] @_Z30int32_float_struct_inheritance14child2_float_s([2 x i32] %a.coerce)
43 // ILP32F-ILP32D: define{{.*}} { i32, float } @_Z30int32_float_struct_inheritance14child2_float_s(i32 %0, float %1)
44 // LP64: define{{.*}} i64 @_Z30int32_float_struct_inheritance14child2_float_s(i64 %a.coerce)
45 // LP64F-LP64D: define{{.*}} { i32, float } @_Z30int32_float_struct_inheritance14child2_float_s(i32 %0, float %1)
int32_float_struct_inheritance(struct child2_float_s a)46 struct child2_float_s int32_float_struct_inheritance(struct child2_float_s a) {
47 return a;
48 }
49
50 struct parent3_float_s {
51 float f1;
52 };
53
54 struct child3_int64_s : parent3_float_s {
55 int64_t i1;
56 };
57
58 // ILP32-ILP32F-ILP32D-LABEL: define{{.*}} void @_Z30float_int64_struct_inheritance14child3_int64_s(ptr noalias sret(%struct.child3_int64_s)
59 // LP64-LABEL: define{{.*}} [2 x i64] @_Z30float_int64_struct_inheritance14child3_int64_s([2 x i64] %a.coerce)
60 // LP64F-LP64D-LABEL: define{{.*}} { float, i64 } @_Z30float_int64_struct_inheritance14child3_int64_s(float %0, i64 %1)
float_int64_struct_inheritance(struct child3_int64_s a)61 struct child3_int64_s float_int64_struct_inheritance(struct child3_int64_s a) {
62 return a;
63 }
64
65 struct parent4_double_s {
66 double d1;
67 };
68
69 struct child4_double_s : parent4_double_s {
70 double d1;
71 };
72
73 // ILP32-ILP32F-LABEL: define{{.*}} void @_Z32double_double_struct_inheritance15child4_double_s(ptr noalias sret(%struct.child4_double_s)
74 // ILP32D-LABEL: define{{.*}} { double, double } @_Z32double_double_struct_inheritance15child4_double_s(double %0, double %1)
75 // LP64-LP64F-LABEL: define{{.*}} [2 x i64] @_Z32double_double_struct_inheritance15child4_double_s([2 x i64] %a.coerce)
76 // LP64D-LABEL: define{{.*}} { double, double } @_Z32double_double_struct_inheritance15child4_double_s(double %0, double %1)
double_double_struct_inheritance(struct child4_double_s a)77 struct child4_double_s double_double_struct_inheritance(struct child4_double_s a) {
78 return a;
79 }
80
81 // When virtual inheritance is used, the resulting struct isn't eligible for
82 // passing in registers.
83
84 struct parent5_virtual_s {
85 int32_t i1;
86 };
87
88 struct child5_virtual_s : virtual parent5_virtual_s {
89 float f1;
90 };
91
92 // ILP32-ILP32F-ILP32D-LABEL: define{{.*}} void @_ZN16child5_virtual_sC1EOS_(ptr noundef nonnull align 4 dereferenceable(8) %this, ptr noundef nonnull align 4 dereferenceable(8) %0)
93 // LP64-LP64F-LP64D-LABEL: define{{.*}} void @_ZN16child5_virtual_sC1EOS_(ptr noundef nonnull align 8 dereferenceable(12) %this, ptr noundef nonnull align 8 dereferenceable(12) %0)
int32_float_virtual_struct_inheritance(struct child5_virtual_s a)94 struct child5_virtual_s int32_float_virtual_struct_inheritance(struct child5_virtual_s a) {
95 return a;
96 }
97
98 // Check for correct lowering in the presence of diamond inheritance.
99
100 struct parent6_float_s {
101 float f1;
102 };
103
104 struct child6a_s : parent6_float_s {
105 };
106
107 struct child6b_s : parent6_float_s {
108 };
109
110 struct grandchild_6_s : child6a_s, child6b_s {
111 };
112
113 // ILP32: define{{.*}} [2 x i32] @_Z38float_float_diamond_struct_inheritance14grandchild_6_s([2 x i32] %a.coerce)
114 // ILP32F-ILP64D: define{{.*}} { float, float } @_Z38float_float_diamond_struct_inheritance14grandchild_6_s(float %0, float %1)
115 // LP64: define{{.*}} i64 @_Z38float_float_diamond_struct_inheritance14grandchild_6_s(i64 %a.coerce)
116 // LP64F-LP64D: define{{.*}} { float, float } @_Z38float_float_diamond_struct_inheritance14grandchild_6_s(float %0, float %1)
float_float_diamond_struct_inheritance(struct grandchild_6_s a)117 struct grandchild_6_s float_float_diamond_struct_inheritance(struct grandchild_6_s a) {
118 return a;
119 }
120
121 // NOTE: These prefixes are unused. Do not add tests below this line:
122 // ILP32F: {{.*}}
123 // LP64F: {{.*}}
124