]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs
Rollup merge of #68918 - brson:unwrapdoc, r=Dylan-DPC
[rust.git] / src / test / codegen / riscv-abi / riscv64-lp64-lp64f-lp64d-abi.rs
1 // ignore-tidy-linelength
2 // compile-flags: -C no-prepopulate-passes
3 // only-riscv64
4 // only-linux
5 #![crate_type = "lib"]
6 #![allow(improper_ctypes)]
7
8 // CHECK: define void @f_void()
9 #[no_mangle]
10 pub extern "C" fn f_void() {}
11
12 // CHECK: define zeroext i1 @f_scalar_0(i1 zeroext %a)
13 #[no_mangle]
14 pub extern "C" fn f_scalar_0(a: bool) -> bool {
15     a
16 }
17
18 // CHECK: define signext i8 @f_scalar_1(i8 signext %x)
19 #[no_mangle]
20 pub extern "C" fn f_scalar_1(x: i8) -> i8 {
21     x
22 }
23
24 // CHECK: define zeroext i8 @f_scalar_2(i8 zeroext %x)
25 #[no_mangle]
26 pub extern "C" fn f_scalar_2(x: u8) -> u8 {
27     x
28 }
29
30 // CHECK: define signext i32 @f_scalar_3(i32 signext %x)
31 #[no_mangle]
32 pub extern "C" fn f_scalar_3(x: i32) -> u32 {
33     x as u32
34 }
35
36 // CHECK: define i64 @f_scalar_4(i64 %x)
37 #[no_mangle]
38 pub extern "C" fn f_scalar_4(x: i64) -> i64 {
39     x
40 }
41
42 // CHECK: define float @f_fp_scalar_1(float)
43 #[no_mangle]
44 pub extern "C" fn f_fp_scalar_1(x: f32) -> f32 {
45     x
46 }
47 // CHECK: define double @f_fp_scalar_2(double)
48 #[no_mangle]
49 pub extern "C" fn f_fp_scalar_2(x: f64) -> f64 {
50     x
51 }
52
53 #[repr(C)]
54 pub struct Empty {}
55
56 // CHECK: define void @f_agg_empty_struct()
57 #[no_mangle]
58 pub extern "C" fn f_agg_empty_struct(e: Empty) -> Empty {
59     e
60 }
61
62 #[repr(C)]
63 pub struct Tiny {
64     a: u16,
65     b: u16,
66     c: u16,
67     d: u16,
68 }
69
70 // CHECK: define void @f_agg_tiny(i64)
71 #[no_mangle]
72 pub extern "C" fn f_agg_tiny(mut e: Tiny) {
73     e.a += e.b;
74     e.c += e.d;
75 }
76
77 // CHECK: define i64 @f_agg_tiny_ret()
78 #[no_mangle]
79 pub extern "C" fn f_agg_tiny_ret() -> Tiny {
80     Tiny { a: 1, b: 2, c: 3, d: 4 }
81 }
82
83 #[repr(C)]
84 pub struct Small {
85     a: i64,
86     b: *mut i64,
87 }
88
89 // CHECK: define void @f_agg_small([2 x i64])
90 #[no_mangle]
91 pub extern "C" fn f_agg_small(mut x: Small) {
92     x.a += unsafe { *x.b };
93     x.b = &mut x.a;
94 }
95
96 // CHECK: define [2 x i64] @f_agg_small_ret()
97 #[no_mangle]
98 pub extern "C" fn f_agg_small_ret() -> Small {
99     Small { a: 1, b: core::ptr::null_mut() }
100 }
101
102 #[repr(C)]
103 pub struct SmallAligned {
104     a: i128,
105 }
106
107 // CHECK: define void @f_agg_small_aligned(i128)
108 #[no_mangle]
109 pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
110     x.a += x.a;
111 }
112
113 #[repr(C)]
114 pub struct Large {
115     a: i64,
116     b: i64,
117     c: i64,
118     d: i64,
119 }
120
121 // CHECK: define void @f_agg_large(%Large* {{.*}}%x)
122 #[no_mangle]
123 pub extern "C" fn f_agg_large(mut x: Large) {
124     x.a = x.b + x.c + x.d;
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, [2 x i64], i128, %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{{.*}}, i64 %a, i128, i128, 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: core::ptr::null_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 }