2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-08-31 08:51:35 -05:00
|
|
|
#![allow(improper_ctypes)]
|
|
|
|
|
2017-10-22 22:01:00 -05:00
|
|
|
// ignore-wasm32-bare no libc to test ffi with
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2015-03-30 08:38:27 -05:00
|
|
|
#[derive(Copy, Clone)]
|
2014-06-17 14:51:24 -05:00
|
|
|
pub struct S {
|
|
|
|
x: u64,
|
|
|
|
y: u64,
|
|
|
|
z: u64,
|
|
|
|
}
|
|
|
|
|
2016-11-23 18:09:51 -06:00
|
|
|
#[link(name = "rust_test_helpers", kind = "static")]
|
2020-09-01 16:12:52 -05:00
|
|
|
extern "C" {
|
2014-06-17 14:51:24 -05:00
|
|
|
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 16:12:52 -05:00
|
|
|
fn indirect_call(func: unsafe extern "C" fn(s: S) -> u64, s: S) -> u64 {
|
|
|
|
unsafe { func(s) }
|
2014-06-17 14:51:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|