2022-07-08 11:08:32 -05:00
|
|
|
//@compile-flags: -Zmiri-permissive-provenance
|
2022-06-26 20:26:14 -05:00
|
|
|
|
2018-10-12 03:54:37 -05:00
|
|
|
fn main() {
|
|
|
|
// Cast a function pointer such that when returning, the return value 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
|
2018-10-12 03:54:37 -05:00
|
|
|
// should fail, but validation should.
|
2022-06-21 13:27:44 -05:00
|
|
|
fn f() -> *const i32 {
|
|
|
|
0usize as *const i32
|
|
|
|
}
|
2018-10-12 03:54:37 -05:00
|
|
|
|
|
|
|
let g: fn() -> &'static i32 = unsafe { std::mem::transmute(f as fn() -> *const i32) };
|
|
|
|
|
2019-02-15 19:43:56 -06:00
|
|
|
let _x = g();
|
2022-07-11 06:44:55 -05:00
|
|
|
//~^ ERROR: encountered a null reference
|
2018-10-12 03:54:37 -05:00
|
|
|
}
|