]> git.lizzy.rs Git - rust.git/blob - src/test/ui/abi/foreign/foreign-fn-with-byval.rs
Rollup merge of #95353 - jyn514:invalid-filter-hard-error, r=Mark-Simulacrum
[rust.git] / src / test / ui / abi / foreign / foreign-fn-with-byval.rs
1 // run-pass
2 #![allow(improper_ctypes)]
3
4 // ignore-wasm32-bare no libc to test ffi with
5
6 #[derive(Copy, Clone)]
7 pub struct S {
8     x: u64,
9     y: u64,
10     z: u64,
11 }
12
13 #[link(name = "rust_test_helpers", kind = "static")]
14 extern "C" {
15     pub fn get_x(x: S) -> u64;
16     pub fn get_y(x: S) -> u64;
17     pub fn get_z(x: S) -> u64;
18 }
19
20 #[inline(never)]
21 fn indirect_call(func: unsafe extern "C" fn(s: S) -> u64, s: S) -> u64 {
22     unsafe { func(s) }
23 }
24
25 fn main() {
26     let s = S { x: 1, y: 2, z: 3 };
27     assert_eq!(s.x, indirect_call(get_x, s));
28     assert_eq!(s.y, indirect_call(get_y, s));
29     assert_eq!(s.z, indirect_call(get_z, s));
30 }