rust/tests/fail/validity/cast_fn_ptr1.rs

14 lines
442 B
Rust
Raw Normal View History

2022-07-08 11:08:32 -05:00
//@compile-flags: -Zmiri-permissive-provenance
fn main() {
// Cast a function pointer such that on a call, the argument gets transmuted
2019-02-15 19:43:56 -06:00
// from raw ptr to reference. This is ABI-compatible, so it's not the call that
// should fail, but validation should.
fn f(_x: &i32) {}
let g: fn(*const i32) = unsafe { std::mem::transmute(f as fn(&i32)) };
2019-02-15 19:43:56 -06:00
g(0usize as *const i32)
//~^ ERROR: encountered a null reference
}