Complete miri test.

This commit is contained in:
Camille GILLOT 2023-05-14 20:31:02 +00:00
parent 644e40f536
commit 6dfa053697

View File

@ -23,6 +23,10 @@ fn h(i: i32, j: i32) -> i32 {
j * i * 7
}
fn i() -> i32 {
73
}
fn return_fn_ptr(f: fn() -> i32) -> fn() -> i32 {
f
}
@ -72,9 +76,18 @@ fn main() {
assert_eq!(indirect3(h), 210);
assert_eq!(indirect_mut3(h), 210);
assert_eq!(indirect_once3(h), 210);
let g = f as fn() -> i32;
assert!(return_fn_ptr(g) == g);
assert!(return_fn_ptr(g) as unsafe fn() -> i32 == g as fn() -> i32 as unsafe fn() -> i32);
// Check that `i` always has the same address. This is not guaranteed
// but Miri currently uses a fixed address for monomorphic functions.
assert!(return_fn_ptr(i) == i);
assert!(return_fn_ptr(i) as unsafe fn() -> i32 == i as fn() -> i32 as unsafe fn() -> i32);
// We don't check anything for `f`. Miri gives it many different addresses
// but mir-opts can turn them into the same address.
let _val = return_fn_ptr(f) != f;
// However, if we only turn `f` into a function pointer and use that pointer,
// it is equal to itself.
let f2 = f as fn() -> i32;
assert!(return_fn_ptr(f2) == f2);
assert!(return_fn_ptr(f2) as unsafe fn() -> i32 == f2 as fn() -> i32 as unsafe fn() -> i32);
// Any non-null value is okay for function pointers.
unsafe {