]> git.proxmox.com Git - rustc.git/blame - src/test/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs
New upstream version 1.61.0+dfsg1
[rustc.git] / src / test / codegen / riscv-abi / riscv64-lp64-lp64f-lp64d-abi.rs
CommitLineData
ee023bcb 1// compile-flags: --target riscv64gc-unknown-linux-gnu -O -C no-prepopulate-passes
5099ac24
FG
2// needs-llvm-components: riscv
3
74b04a01 4#![crate_type = "lib"]
5099ac24
FG
5#![no_core]
6#![feature(no_core, lang_items)]
74b04a01
XL
7#![allow(improper_ctypes)]
8
5099ac24
FG
9#[lang = "sized"]
10trait Sized {}
11#[lang = "copy"]
12trait Copy {}
ee023bcb
FG
13impl Copy for bool {}
14impl Copy for i8 {}
15impl Copy for u8 {}
16impl Copy for i32 {}
17impl Copy for i64 {}
18impl Copy for u64 {}
19impl Copy for f32 {}
20impl Copy for f64 {}
5099ac24 21
74b04a01
XL
22// CHECK: define void @f_void()
23#[no_mangle]
24pub extern "C" fn f_void() {}
25
5099ac24 26// CHECK: define noundef zeroext i1 @f_scalar_0(i1 noundef zeroext %a)
74b04a01
XL
27#[no_mangle]
28pub 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]
34pub 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]
40pub 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]
46pub 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]
52pub extern "C" fn f_scalar_4(x: i64) -> i64 {
53 x
54}
55
f035d41b 56// CHECK: define float @f_fp_scalar_1(float %0)
74b04a01
XL
57#[no_mangle]
58pub extern "C" fn f_fp_scalar_1(x: f32) -> f32 {
59 x
60}
f035d41b 61// CHECK: define double @f_fp_scalar_2(double %0)
74b04a01
XL
62#[no_mangle]
63pub extern "C" fn f_fp_scalar_2(x: f64) -> f64 {
64 x
65}
66
67#[repr(C)]
68pub struct Empty {}
69
70// CHECK: define void @f_agg_empty_struct()
71#[no_mangle]
72pub extern "C" fn f_agg_empty_struct(e: Empty) -> Empty {
73 e
74}
75
76#[repr(C)]
77pub struct Tiny {
78 a: u16,
79 b: u16,
80 c: u16,
81 d: u16,
82}
83
f035d41b 84// CHECK: define void @f_agg_tiny(i64 %0)
74b04a01
XL
85#[no_mangle]
86pub extern "C" fn f_agg_tiny(mut e: Tiny) {
74b04a01
XL
87}
88
89// CHECK: define i64 @f_agg_tiny_ret()
90#[no_mangle]
91pub extern "C" fn f_agg_tiny_ret() -> Tiny {
92 Tiny { a: 1, b: 2, c: 3, d: 4 }
93}
94
95#[repr(C)]
96pub struct Small {
97 a: i64,
98 b: *mut i64,
99}
100
f035d41b 101// CHECK: define void @f_agg_small([2 x i64] %0)
74b04a01
XL
102#[no_mangle]
103pub extern "C" fn f_agg_small(mut x: Small) {
74b04a01
XL
104}
105
106// CHECK: define [2 x i64] @f_agg_small_ret()
107#[no_mangle]
108pub extern "C" fn f_agg_small_ret() -> Small {
5099ac24 109 Small { a: 1, b: 0 as *mut _ }
74b04a01
XL
110}
111
112#[repr(C)]
113pub struct SmallAligned {
114 a: i128,
115}
116
f035d41b 117// CHECK: define void @f_agg_small_aligned(i128 %0)
74b04a01
XL
118#[no_mangle]
119pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
74b04a01
XL
120}
121
122#[repr(C)]
123pub struct Large {
124 a: i64,
125 b: i64,
126 c: i64,
127 d: i64,
128}
129
130// CHECK: define void @f_agg_large(%Large* {{.*}}%x)
131#[no_mangle]
132pub extern "C" fn f_agg_large(mut x: Large) {
74b04a01
XL
133}
134
135// CHECK: define void @f_agg_large_ret(%Large* {{.*}}sret{{.*}}, i32 signext %i, i8 signext %j)
136#[no_mangle]
137pub extern "C" fn f_agg_large_ret(i: i32, j: i8) -> Large {
138 Large { a: 1, b: 2, c: 3, d: 4 }
139}
140
f035d41b 141// 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)
74b04a01
XL
142#[no_mangle]
143pub 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
f035d41b 155// 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)
74b04a01
XL
156#[no_mangle]
157pub 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
169extern "C" {
170 fn f_va_callee(_: i32, ...) -> i32;
171}
172
173#[no_mangle]
174pub 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* {{.*}})
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 },
5099ac24 183 Small { a: 10, b: 0 as *mut _ },
74b04a01
XL
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}