about summary refs log tree commit diff
path: root/tests/run-make/mte-ffi/foo_function.rs
blob: 2c8e0b2623851984e86385c0ace068e61d0f4edd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#![crate_type = "cdylib"]
#![crate_name = "foo"]

extern "C" fn ret32() -> i32 {
    32
}

#[no_mangle]
pub extern "C" fn foo(ptr: extern "C" fn(extern "C" fn() -> i32)) {
    assert_eq!((ptr as usize) >> 56, 0x1f);

    // Store an arbitrary tag in the tag bits, and convert back to the correct pointer type.
    let p = ((ret32 as usize) | (0x2f << 56)) as *const ();
    let p: extern "C" fn() -> i32 = unsafe { std::mem::transmute(p) };

    unsafe { ptr(p) }
}