rust/tests/fail/function_calls/exported_symbol_abi_mismatch.rs

36 lines
880 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 {
2022-06-22 01:03:34 -05:00
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)]
unsafe {
2022-06-22 01:03:34 -05:00
foo();
}
2021-05-30 22:05:04 -05:00
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();
}
2022-06-22 01:03:34 -05:00
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
}
}