@@ -23,6 +23,10 @@ fn h(i: i32, j: i32) -> i32 {
23
23
j * i * 7
24
24
}
25
25
26
+ fn i ( ) -> i32 {
27
+ 73
28
+ }
29
+
26
30
fn return_fn_ptr ( f : fn ( ) -> i32 ) -> fn ( ) -> i32 {
27
31
f
28
32
}
@@ -72,9 +76,18 @@ fn main() {
72
76
assert_eq ! ( indirect3( h) , 210 ) ;
73
77
assert_eq ! ( indirect_mut3( h) , 210 ) ;
74
78
assert_eq ! ( indirect_once3( h) , 210 ) ;
75
- let g = f as fn ( ) -> i32 ;
76
- assert ! ( return_fn_ptr( g) == g) ;
77
- assert ! ( return_fn_ptr( g) as unsafe fn ( ) -> i32 == g as fn ( ) -> i32 as unsafe fn ( ) -> i32 ) ;
79
+ // Check that `i` always has the same address. This is not guaranteed
80
+ // but Miri currently uses a fixed address for monomorphic functions.
81
+ assert ! ( return_fn_ptr( i) == i) ;
82
+ assert ! ( return_fn_ptr( i) as unsafe fn ( ) -> i32 == i as fn ( ) -> i32 as unsafe fn ( ) -> i32 ) ;
83
+ // We don't check anything for `f`. Miri gives it many different addresses
84
+ // but mir-opts can turn them into the same address.
85
+ let _val = return_fn_ptr ( f) != f;
86
+ // However, if we only turn `f` into a function pointer and use that pointer,
87
+ // it is equal to itself.
88
+ let f2 = f as fn ( ) -> i32 ;
89
+ assert ! ( return_fn_ptr( f2) == f2) ;
90
+ assert ! ( return_fn_ptr( f2) as unsafe fn ( ) -> i32 == f2 as fn ( ) -> i32 as unsafe fn ( ) -> i32 ) ;
78
91
79
92
// Any non-null value is okay for function pointers.
80
93
unsafe {
0 commit comments