about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-28 05:42:54 +0000
committerbors <bors@rust-lang.org>2023-09-28 05:42:54 +0000
commit024279a2e931c0bc68b235fd683ebcefc3fc718b (patch)
treea32699a88769d84881ac8a01de578a66f10f52d3 /src/tools
parent1a3dd7ea7d929db798b7095d3c25f50b49a52fb4 (diff)
parentf2623ac49b3dbcee5a0828c035157ca92bd0db2c (diff)
downloadrust-024279a2e931c0bc68b235fd683ebcefc3fc718b.tar.gz
rust-024279a2e931c0bc68b235fd683ebcefc3fc718b.zip
Auto merge of #3089 - rust-lang:rustup-2023-09-28, r=RalfJung
Automatic sync from rustc
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/miri/rust-version2
-rw-r--r--src/tools/miri/tests/pass/function_pointers.rs20
2 files changed, 17 insertions, 5 deletions
diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version
index 3f1babf5323..07dd52ce941 100644
--- a/src/tools/miri/rust-version
+++ b/src/tools/miri/rust-version
@@ -1 +1 @@
-d206f2c0857eb879877f27508139dd62a40294c3
+2ba4eb2d49e774b5fbc2a06258ac7b0f60b92b7e
diff --git a/src/tools/miri/tests/pass/function_pointers.rs b/src/tools/miri/tests/pass/function_pointers.rs
index b66826e3fcd..1c99a96feda 100644
--- a/src/tools/miri/tests/pass/function_pointers.rs
+++ b/src/tools/miri/tests/pass/function_pointers.rs
@@ -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,10 +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);
-    assert!(return_fn_ptr(f) != f);
+    // 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 {