]> git.proxmox.com Git - rustc.git/blob - src/test/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / codegen / riscv-abi / riscv64-lp64-lp64f-lp64d-abi.rs
1 // compile-flags: --target riscv64gc-unknown-linux-gnu -O -C no-prepopulate-passes
2 // needs-llvm-components: riscv
3
4 #![crate_type = "lib"]
5 #![no_core]
6 #![feature(no_core, lang_items)]
7 #![allow(improper_ctypes)]
8
9 #[lang = "sized"]
10 trait Sized {}
11 #[lang = "copy"]
12 trait Copy {}
13 impl Copy for bool {}
14 impl Copy for i8 {}
15 impl Copy for u8 {}
16 impl Copy for i32 {}
17 impl Copy for i64 {}
18 impl Copy for u64 {}
19 impl Copy for f32 {}
20 impl Copy for f64 {}
21
22 // CHECK: define void @f_void()
23 #[no_mangle]
24 pub extern "C" fn f_void() {}
25
26 // CHECK: define noundef zeroext i1 @f_scalar_0(i1 noundef zeroext %a)
27 #[no_mangle]
28 pub extern "C" fn f_scalar_0(a: bool) -> bool {
29 a
30 }
31
32 // CHECK: define signext i8 @f_scalar_1(i8 signext %x)
33 #[no_mangle]
34 pub extern "C" fn f_scalar_1(x: i8) -> i8 {
35 x
36 }
37
38 // CHECK: define zeroext i8 @f_scalar_2(i8 zeroext %x)
39 #[no_mangle]
40 pub extern "C" fn f_scalar_2(x: u8) -> u8 {
41 x
42 }
43
44 // CHECK: define signext i32 @f_scalar_3(i32 signext %x)
45 #[no_mangle]
46 pub extern "C" fn f_scalar_3(x: i32) -> u32 {
47 x as u32
48 }
49
50 // CHECK: define i64 @f_scalar_4(i64 %x)
51 #[no_mangle]
52 pub extern "C" fn f_scalar_4(x: i64) -> i64 {
53 x
54 }
55
56 // CHECK: define float @f_fp_scalar_1(float %0)
57 #[no_mangle]
58 pub extern "C" fn f_fp_scalar_1(x: f32) -> f32 {
59 x
60 }
61 // CHECK: define double @f_fp_scalar_2(double %0)
62 #[no_mangle]
63 pub extern "C" fn f_fp_scalar_2(x: f64) -> f64 {
64 x
65 }
66
67 #[repr(C)]
68 pub struct Empty {}
69
70 // CHECK: define void @f_agg_empty_struct()
71 #[no_mangle]
72 pub extern "C" fn f_agg_empty_struct(e: Empty) -> Empty {
73 e
74 }
75
76 #[repr(C)]
77 pub struct Tiny {
78 a: u16,
79 b: u16,
80 c: u16,
81 d: u16,
82 }
83
84 // CHECK: define void @f_agg_tiny(i64 %0)
85 #[no_mangle]
86 pub extern "C" fn f_agg_tiny(mut e: Tiny) {
87 }
88
89 // CHECK: define i64 @f_agg_tiny_ret()
90 #[no_mangle]
91 pub extern "C" fn f_agg_tiny_ret() -> Tiny {
92 Tiny { a: 1, b: 2, c: 3, d: 4 }
93 }
94
95 #[repr(C)]
96 pub struct Small {
97 a: i64,
98 b: *mut i64,
99 }
100
101 // CHECK: define void @f_agg_small([2 x i64] %0)
102 #[no_mangle]
103 pub extern "C" fn f_agg_small(mut x: Small) {
104 }
105
106 // CHECK: define [2 x i64] @f_agg_small_ret()
107 #[no_mangle]
108 pub extern "C" fn f_agg_small_ret() -> Small {
109 Small { a: 1, b: 0 as *mut _ }
110 }
111
112 #[repr(C)]
113 pub struct SmallAligned {
114 a: i128,
115 }
116
117 // CHECK: define void @f_agg_small_aligned(i128 %0)
118 #[no_mangle]
119 pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
120 }
121
122 #[repr(C)]
123 pub struct Large {
124 a: i64,
125 b: i64,
126 c: i64,
127 d: i64,
128 }
129
130 // CHECK: define void @f_agg_large({{%Large\*|ptr}} {{.*}}%x)
131 #[no_mangle]
132 pub extern "C" fn f_agg_large(mut x: Large) {
133 }
134
135 // CHECK: define void @f_agg_large_ret({{%Large\*|ptr}} {{.*}}sret{{.*}}, i32 signext %i, i8 signext %j)
136 #[no_mangle]
137 pub extern "C" fn f_agg_large_ret(i: i32, j: i8) -> Large {
138 Large { a: 1, b: 2, c: 3, d: 4 }
139 }
140
141 // CHECK: define void @f_scalar_stack_1(i64 %0, [2 x i64] %1, i128 %2, {{%Large\*|ptr}} {{.*}}%d, i8 zeroext %e, i8 signext %f, i8 %g, i8 %h)
142 #[no_mangle]
143 pub extern "C" fn f_scalar_stack_1(
144 a: Tiny,
145 b: Small,
146 c: SmallAligned,
147 d: Large,
148 e: u8,
149 f: i8,
150 g: u8,
151 h: i8,
152 ) {
153 }
154
155 // CHECK: define void @f_scalar_stack_2({{%Large\*|ptr}} {{.*}}sret{{.*}} %0, i64 %a, i128 %1, i128 %2, i64 %d, i8 zeroext %e, i8 %f, i8 %g)
156 #[no_mangle]
157 pub extern "C" fn f_scalar_stack_2(
158 a: u64,
159 b: SmallAligned,
160 c: SmallAligned,
161 d: u64,
162 e: u8,
163 f: i8,
164 g: u8,
165 ) -> Large {
166 Large { a: a as i64, b: e as i64, c: f as i64, d: g as i64 }
167 }
168
169 extern "C" {
170 fn f_va_callee(_: i32, ...) -> i32;
171 }
172
173 #[no_mangle]
174 pub unsafe extern "C" fn f_va_caller() {
175 // CHECK: call signext i32 (i32, ...) @f_va_callee(i32 signext 1, i32 signext 2, i64 3, double {{.*}}, double {{.*}}, i64 {{.*}}, [2 x i64] {{.*}}, i128 {{.*}}, {{%Large\*|ptr}} {{.*}})
176 f_va_callee(
177 1,
178 2i32,
179 3i64,
180 4.0f64,
181 5.0f64,
182 Tiny { a: 1, b: 2, c: 3, d: 4 },
183 Small { a: 10, b: 0 as *mut _ },
184 SmallAligned { a: 11 },
185 Large { a: 12, b: 13, c: 14, d: 15 },
186 );
187 // CHECK: call signext i32 (i32, ...) @f_va_callee(i32 signext 1, i32 signext 2, i32 signext 3, i32 signext 4, i128 {{.*}}, i32 signext 6, i32 signext 7, i32 8, i32 9)
188 f_va_callee(1, 2i32, 3i32, 4i32, SmallAligned { a: 5 }, 6i32, 7i32, 8i32, 9i32);
189 }