rust/tests/compile-fail/function_calls/exported_symbol_abi_mismatch.rs

30 lines
822 B
Rust
Raw Normal View History

2021-05-30 22:05:04 -05:00
// revisions: no_cache cache fn_ptr
2021-04-15 16:19:23 -05:00
#[no_mangle]
fn foo() {}
fn main() {
2021-05-30 22:05:04 -05:00
#[cfg(any(cache, fn_ptr))]
extern "Rust" {
fn foo();
}
#[cfg(fn_ptr)]
unsafe { std::mem::transmute::<unsafe fn(), unsafe extern "C" fn()>(foo)() }
//[fn_ptr]~^ ERROR calling a function with calling convention Rust using calling convention C
2021-05-30 22:05:04 -05:00
// `Instance` caching should not suppress ABI check.
2021-04-15 16:19:23 -05:00
#[cfg(cache)]
2021-05-30 22:05:04 -05:00
unsafe { foo() }
2021-04-15 16:19:23 -05:00
{
2021-05-30 22:05:04 -05:00
#[cfg_attr(any(cache, fn_ptr), allow(clashing_extern_declarations))]
extern "C" {
2021-04-15 16:19:23 -05:00
fn foo();
}
unsafe { foo() }
//[no_cache]~^ ERROR calling a function with calling convention Rust using calling convention C
//[cache]~^^ ERROR calling a function with calling convention Rust using calling convention C
2021-04-15 16:19:23 -05:00
}
}