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