Files
rust/tests/ui/abi/foreign/foreign-fn-with-byval.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
613 B
Rust
Raw Normal View History

//@ run-pass
#![allow(improper_ctypes, improper_ctypes_definitions)]
2015-03-30 09:38:27 -04:00
#[derive(Copy, Clone)]
pub struct S {
x: u64,
y: u64,
z: u64,
}
2016-11-23 16:09:51 -08:00
#[link(name = "rust_test_helpers", kind = "static")]
2020-09-01 17:12:52 -04:00
extern "C" {
pub fn get_x(x: S) -> u64;
pub fn get_y(x: S) -> u64;
pub fn get_z(x: S) -> u64;
}
#[inline(never)]
2020-09-01 17:12:52 -04:00
fn indirect_call(func: unsafe extern "C" fn(s: S) -> u64, s: S) -> u64 {
unsafe { func(s) }
}
fn main() {
let s = S { x: 1, y: 2, z: 3 };
assert_eq!(s.x, indirect_call(get_x, s));
assert_eq!(s.y, indirect_call(get_y, s));
assert_eq!(s.z, indirect_call(get_z, s));
}