From faaabf48cc6cb849fd5800ef22f96fae63b619d2 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 1 Dec 2024 20:14:04 -0800 Subject: [PATCH 1/6] Bounds-check with PtrMetadata instead of Len in MIR --- tests/fail/both_borrows/buggy_as_mut_slice.rs | 2 +- tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/fail/both_borrows/buggy_as_mut_slice.rs b/tests/fail/both_borrows/buggy_as_mut_slice.rs index 6d535a14c0..6027b5c0f5 100644 --- a/tests/fail/both_borrows/buggy_as_mut_slice.rs +++ b/tests/fail/both_borrows/buggy_as_mut_slice.rs @@ -13,7 +13,7 @@ fn main() { let v1 = safe::as_mut_slice(&v); let v2 = safe::as_mut_slice(&v); v1[1] = 5; - //~[stack]^ ERROR: /write access .* tag does not exist in the borrow stack/ + //~[stack]^ ERROR: /trying to retag .+ for SharedReadOnly permission .+ tag does not exist in the borrow stack for this location/ v2[1] = 7; //~[tree]^ ERROR: /write access through .* is forbidden/ } diff --git a/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr b/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr index 4e5355f565..c5488a537a 100644 --- a/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr +++ b/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr @@ -1,11 +1,11 @@ -error: Undefined Behavior: attempting a write access using at ALLOC[0x4], but that tag does not exist in the borrow stack for this location +error: Undefined Behavior: trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location --> tests/fail/both_borrows/buggy_as_mut_slice.rs:LL:CC | LL | v1[1] = 5; - | ^^^^^^^^^ + | ^^^^^ | | - | attempting a write access using at ALLOC[0x4], but that tag does not exist in the borrow stack for this location - | this error occurs as part of an access at ALLOC[0x4..0x8] + | trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location + | this error occurs as part of retag at ALLOC[0x0..0xc] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information From bc7269d5f50a6807ca9465669d138496b4c72a61 Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Thu, 12 Dec 2024 12:34:43 -0800 Subject: [PATCH 2/6] Make BorrowSet/BorrowData fields accessible via public getters --- src/machine.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/machine.rs b/src/machine.rs index 7cc22f83a2..ac26feb345 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1571,8 +1571,12 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> { res } - fn after_local_read(ecx: &InterpCx<'tcx, Self>, local: mir::Local) -> InterpResult<'tcx> { - if let Some(data_race) = &ecx.frame().extra.data_race { + fn after_local_read( + ecx: &InterpCx<'tcx, Self>, + frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>, + local: mir::Local, + ) -> InterpResult<'tcx> { + if let Some(data_race) = &frame.extra.data_race { data_race.local_read(local, &ecx.machine); } interp_ok(()) From 55f8534b541d232f61978f30af8fdfb6f015bcc1 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Fri, 13 Dec 2024 02:00:20 -0800 Subject: [PATCH 3/6] Don't retag the `PtrMetadata(&raw const *_n)` in slice indexing --- tests/fail/both_borrows/buggy_as_mut_slice.rs | 2 +- tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/fail/both_borrows/buggy_as_mut_slice.rs b/tests/fail/both_borrows/buggy_as_mut_slice.rs index 6027b5c0f5..6d535a14c0 100644 --- a/tests/fail/both_borrows/buggy_as_mut_slice.rs +++ b/tests/fail/both_borrows/buggy_as_mut_slice.rs @@ -13,7 +13,7 @@ fn main() { let v1 = safe::as_mut_slice(&v); let v2 = safe::as_mut_slice(&v); v1[1] = 5; - //~[stack]^ ERROR: /trying to retag .+ for SharedReadOnly permission .+ tag does not exist in the borrow stack for this location/ + //~[stack]^ ERROR: /write access .* tag does not exist in the borrow stack/ v2[1] = 7; //~[tree]^ ERROR: /write access through .* is forbidden/ } diff --git a/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr b/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr index c5488a537a..4e5355f565 100644 --- a/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr +++ b/tests/fail/both_borrows/buggy_as_mut_slice.stack.stderr @@ -1,11 +1,11 @@ -error: Undefined Behavior: trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location +error: Undefined Behavior: attempting a write access using at ALLOC[0x4], but that tag does not exist in the borrow stack for this location --> tests/fail/both_borrows/buggy_as_mut_slice.rs:LL:CC | LL | v1[1] = 5; - | ^^^^^ + | ^^^^^^^^^ | | - | trying to retag from for SharedReadOnly permission at ALLOC[0x0], but that tag does not exist in the borrow stack for this location - | this error occurs as part of retag at ALLOC[0x0..0xc] + | attempting a write access using at ALLOC[0x4], but that tag does not exist in the borrow stack for this location + | this error occurs as part of an access at ALLOC[0x4..0x8] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information From a67498d7980716854bd49e9c0366603191187272 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:44:18 +0000 Subject: [PATCH 4/6] Make dependency_formats an FxIndexMap rather than a list of tuples It is treated as a map already. This is using FxIndexMap rather than UnordMap because the latter doesn't provide an api to pick a single value iff all values are equal, which each_linked_rlib depends on. --- src/helpers.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index b57ce4e070..1f7c60ad1b 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -149,10 +149,9 @@ pub fn iter_exported_symbols<'tcx>( let dependency_formats = tcx.dependency_formats(()); // Find the dependencies of the executable we are running. let dependency_format = dependency_formats - .iter() - .find(|(crate_type, _)| *crate_type == CrateType::Executable) + .get(&CrateType::Executable) .expect("interpreting a non-executable crate"); - for cnum in dependency_format.1.iter().enumerate().filter_map(|(num, &linkage)| { + for cnum in dependency_format.iter().enumerate().filter_map(|(num, &linkage)| { // We add 1 to the number because that's what rustc also does everywhere it // calls `CrateNum::new`... #[expect(clippy::arithmetic_side_effects)] From 65201b036b52da850b1341eb56e225988d877a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 12 Dec 2024 23:56:39 +0000 Subject: [PATCH 5/6] Fix miri tests --- tests/fail-dep/concurrency/windows_join_main.stderr | 3 +-- tests/fail/function_calls/arg_inplace_mutate.stack.stderr | 1 - tests/fail/function_calls/arg_inplace_mutate.tree.stderr | 1 - .../function_calls/arg_inplace_observe_during.stack.stderr | 1 - .../fail/function_calls/arg_inplace_observe_during.tree.stderr | 1 - .../function_calls/return_pointer_aliasing_read.stack.stderr | 1 - .../function_calls/return_pointer_aliasing_read.tree.stderr | 1 - .../function_calls/return_pointer_aliasing_write.stack.stderr | 1 - .../function_calls/return_pointer_aliasing_write.tree.stderr | 1 - .../return_pointer_aliasing_write_tail_call.stack.stderr | 1 - .../return_pointer_aliasing_write_tail_call.tree.stderr | 1 - 11 files changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/fail-dep/concurrency/windows_join_main.stderr b/tests/fail-dep/concurrency/windows_join_main.stderr index 23a9f8f9c2..6540543d8d 100644 --- a/tests/fail-dep/concurrency/windows_join_main.stderr +++ b/tests/fail-dep/concurrency/windows_join_main.stderr @@ -24,8 +24,7 @@ note: inside `main` LL | / thread::spawn(|| { LL | | unsafe { LL | | assert_eq!(WaitForSingleObject(MAIN_THREAD, INFINITE), WAIT_OBJECT_0); -LL | | } -LL | | }) +... | LL | | .join() | |___________^ diff --git a/tests/fail/function_calls/arg_inplace_mutate.stack.stderr b/tests/fail/function_calls/arg_inplace_mutate.stack.stderr index d9ab782986..2875a5be28 100644 --- a/tests/fail/function_calls/arg_inplace_mutate.stack.stderr +++ b/tests/fail/function_calls/arg_inplace_mutate.stack.stderr @@ -14,7 +14,6 @@ LL | | let _unit: (); LL | | { LL | | let non_copy = S(42); ... | -LL | | } LL | | } | |_____^ help: is this argument diff --git a/tests/fail/function_calls/arg_inplace_mutate.tree.stderr b/tests/fail/function_calls/arg_inplace_mutate.tree.stderr index 677952b39d..c699987b79 100644 --- a/tests/fail/function_calls/arg_inplace_mutate.tree.stderr +++ b/tests/fail/function_calls/arg_inplace_mutate.tree.stderr @@ -16,7 +16,6 @@ LL | | let _unit: (); LL | | { LL | | let non_copy = S(42); ... | -LL | | } LL | | } | |_____^ help: the protected tag was created here, in the initial state Reserved diff --git a/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr b/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr index efdd6129d7..f20ec00f97 100644 --- a/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr +++ b/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr @@ -14,7 +14,6 @@ LL | | let _unit: (); LL | | { LL | | let non_copy = S(42); ... | -LL | | LL | | } | |_____^ help: is this argument diff --git a/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr b/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr index 5746ad1e13..8996c3643d 100644 --- a/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr +++ b/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr @@ -16,7 +16,6 @@ LL | | let _unit: (); LL | | { LL | | let non_copy = S(42); ... | -LL | | LL | | } | |_____^ help: the protected tag was created here, in the initial state Reserved diff --git a/tests/fail/function_calls/return_pointer_aliasing_read.stack.stderr b/tests/fail/function_calls/return_pointer_aliasing_read.stack.stderr index b009b0901c..47e5ee4829 100644 --- a/tests/fail/function_calls/return_pointer_aliasing_read.stack.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing_read.stack.stderr @@ -14,7 +14,6 @@ LL | | { LL | | let x = 0; LL | | let ptr = &raw mut x; ... | -LL | | } LL | | } | |_____^ help: is this argument diff --git a/tests/fail/function_calls/return_pointer_aliasing_read.tree.stderr b/tests/fail/function_calls/return_pointer_aliasing_read.tree.stderr index 6d2cbe9b7c..7eb237ca1a 100644 --- a/tests/fail/function_calls/return_pointer_aliasing_read.tree.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing_read.tree.stderr @@ -16,7 +16,6 @@ LL | | { LL | | let x = 0; LL | | let ptr = &raw mut x; ... | -LL | | } LL | | } | |_____^ help: the protected tag was created here, in the initial state Reserved diff --git a/tests/fail/function_calls/return_pointer_aliasing_write.stack.stderr b/tests/fail/function_calls/return_pointer_aliasing_write.stack.stderr index 54f9a7aebd..813042f06a 100644 --- a/tests/fail/function_calls/return_pointer_aliasing_write.stack.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing_write.stack.stderr @@ -14,7 +14,6 @@ LL | | { LL | | let _x = 0; LL | | let ptr = &raw mut _x; ... | -LL | | } LL | | } | |_____^ help: is this argument diff --git a/tests/fail/function_calls/return_pointer_aliasing_write.tree.stderr b/tests/fail/function_calls/return_pointer_aliasing_write.tree.stderr index 693534be2e..5090ec06b7 100644 --- a/tests/fail/function_calls/return_pointer_aliasing_write.tree.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing_write.tree.stderr @@ -16,7 +16,6 @@ LL | | { LL | | let _x = 0; LL | | let ptr = &raw mut _x; ... | -LL | | } LL | | } | |_____^ help: the protected tag was created here, in the initial state Reserved diff --git a/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.stack.stderr b/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.stack.stderr index 520937beae..a6a0362a22 100644 --- a/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.stack.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.stack.stderr @@ -14,7 +14,6 @@ LL | | { LL | | let _x = 0; LL | | let ptr = &raw mut _x; ... | -LL | | } LL | | } | |_____^ help: is this argument diff --git a/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.tree.stderr b/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.tree.stderr index a879189d0c..26a54fe874 100644 --- a/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.tree.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing_write_tail_call.tree.stderr @@ -16,7 +16,6 @@ LL | | { LL | | let _x = 0; LL | | let ptr = &raw mut _x; ... | -LL | | } LL | | } | |_____^ help: the protected tag was created here, in the initial state Reserved From aa4515ef71b1ba1dc95600f5ccbbc1659c275887 Mon Sep 17 00:00:00 2001 From: The Miri Cronjob Bot Date: Sun, 15 Dec 2024 05:00:34 +0000 Subject: [PATCH 6/6] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index ff62667f9b..68131efa38 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -f4f0fafd0c7849e162eddbc69fa5fe82dbec28c7 +7caf35b2e5401d7740fdc567fdc388059208150b