Skip to content

Commit 97c73b6

Browse files
authored
Rollup merge of #113699 - RalfJung:miri, r=RalfJung
update Miri This fixes a pretty nasty bug in the tag GC. r? ghost
2 parents 0baf440 + 21b05e7 commit 97c73b6

23 files changed

+33
-64
lines changed

src/tools/miri/rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
743333f3dd90721461c09387ec73d09c080d5f5f
1+
33a2c2487ac5d9927830ea4c1844335c6b9f77db

src/tools/miri/src/borrow_tracker/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub struct FrameState {
7474

7575
impl VisitTags for FrameState {
7676
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
77-
// `protected_tags` are fine to GC.
77+
// `protected_tags` are already recorded by `GlobalStateInner`.
7878
}
7979
}
8080

@@ -108,9 +108,12 @@ pub struct GlobalStateInner {
108108
}
109109

110110
impl VisitTags for GlobalStateInner {
111-
fn visit_tags(&self, _visit: &mut dyn FnMut(BorTag)) {
112-
// The only candidate is base_ptr_tags, and that does not need visiting since we don't ever
113-
// GC the bottommost tag.
111+
fn visit_tags(&self, visit: &mut dyn FnMut(BorTag)) {
112+
for &tag in self.protected_tags.keys() {
113+
visit(tag);
114+
}
115+
// The only other candidate is base_ptr_tags, and that does not need visiting since we don't ever
116+
// GC the bottommost/root tag.
114117
}
115118
}
116119

src/tools/miri/src/borrow_tracker/stacked_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
996996

997997
/// Protect a place so that it cannot be used any more for the duration of the current function
998998
/// call.
999-
///
999+
///
10001000
/// This is used to ensure soundness of in-place function argument/return passing.
10011001
fn sb_protect_place(&mut self, place: &MPlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
10021002
let this = self.eval_context_mut();

src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
497497

498498
/// Protect a place so that it cannot be used any more for the duration of the current function
499499
/// call.
500-
///
500+
///
501501
/// This is used to ensure soundness of in-place function argument/return passing.
502502
fn tb_protect_place(&mut self, place: &MPlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> {
503503
let this = self.eval_context_mut();

src/tools/miri/src/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,20 @@
4343
// Needed for rustdoc from bootstrap (with `-Znormalize-docs`).
4444
#![recursion_limit = "256"]
4545

46+
extern crate either; // the one from rustc
47+
4648
extern crate rustc_apfloat;
4749
extern crate rustc_ast;
48-
extern crate rustc_errors;
49-
#[macro_use]
50-
extern crate rustc_middle;
5150
extern crate rustc_const_eval;
5251
extern crate rustc_data_structures;
52+
extern crate rustc_errors;
5353
extern crate rustc_hir;
5454
extern crate rustc_index;
55+
#[macro_use]
56+
extern crate rustc_middle;
5557
extern crate rustc_session;
5658
extern crate rustc_span;
5759
extern crate rustc_target;
58-
extern crate either; // the one from rustc
5960

6061
// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
6162
// files.

src/tools/miri/src/machine.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1097,9 +1097,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
10971097
ptr: Pointer<Self::Provenance>,
10981098
) -> InterpResult<'tcx> {
10991099
match ptr.provenance {
1100-
Provenance::Concrete { alloc_id, tag } => {
1101-
intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, tag)
1102-
}
1100+
Provenance::Concrete { alloc_id, tag } =>
1101+
intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, tag),
11031102
Provenance::Wildcard => {
11041103
// No need to do anything for wildcard pointers as
11051104
// their provenances have already been previously exposed.

src/tools/miri/tests/fail/dangling_pointers/dangling_zst_deref.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Make sure we find these even with many checks disabled.
2-
// Some optimizations remove ZST accesses, thus masking this UB.
3-
//@compile-flags: -Zmir-opt-level=0 -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
2+
//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
43

54
fn main() {
65
let p = {

src/tools/miri/tests/fail/dangling_pointers/dyn_size.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// should find the bug even without these, but gets masked by optimizations
2-
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows -Zmir-opt-level=0
1+
// should find the bug even without these
2+
//@compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
33

44
struct SliceWithHead(u8, [u8]);
55

src/tools/miri/tests/fail/dangling_pointers/maybe_null_pointer_deref_zst.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Some optimizations remove ZST accesses, thus masking this UB.
2-
//@compile-flags: -Zmir-opt-level=0
3-
41
fn main() {
52
// This pointer *could* be NULL so we cannot load from it, not even at ZST
63
let ptr = (&0u8 as *const u8).wrapping_sub(0x800) as *const ();

src/tools/miri/tests/fail/dangling_pointers/maybe_null_pointer_write_zst.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Some optimizations remove ZST accesses, thus masking this UB.
2-
//@compile-flags: -Zmir-opt-level=0
3-
41
fn main() {
52
// This pointer *could* be NULL so we cannot load from it, not even at ZST.
63
// Not using the () type here, as writes of that type do not even have MIR generated.

src/tools/miri/tests/fail/dangling_pointers/null_pointer_deref_zst.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Some optimizations remove ZST accesses, thus masking this UB.
2-
//@compile-flags: -Zmir-opt-level=0
3-
41
#[allow(deref_nullptr)]
52
fn main() {
63
let x: () = unsafe { *std::ptr::null() }; //~ ERROR: dereferencing pointer failed: null pointer is a dangling pointer

src/tools/miri/tests/fail/dangling_pointers/null_pointer_write_zst.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Some optimizations remove ZST accesses, thus masking this UB.
2-
//@compile-flags: -Zmir-opt-level=0
3-
41
#[allow(deref_nullptr)]
52
fn main() {
63
// Not using the () type here, as writes of that type do not even have MIR generated.

src/tools/miri/tests/fail/dangling_pointers/stack_temporary.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// This should fail even without validation, but some MIR opts mask the error
2-
//@compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0
1+
// This should fail even without validation
2+
//@compile-flags: -Zmiri-disable-validation
33

44
unsafe fn make_ref<'a>(x: *mut i32) -> &'a mut i32 {
55
&mut *x

src/tools/miri/tests/fail/dangling_pointers/storage_dead_dangling.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// This should fail even without validation, but some MIR opts mask the error
2-
//@compile-flags: -Zmiri-disable-validation -Zmir-opt-level=0 -Zmiri-permissive-provenance
1+
// This should fail even without validation
2+
//@compile-flags: -Zmiri-disable-validation -Zmiri-permissive-provenance
33

44
static mut LEAK: usize = 0;
55

src/tools/miri/tests/fail/data_race/read_write_race_stack.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
//@compile-flags: -Zmir-opt-level=0 -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
2-
3-
// Note: mir-opt-level set to 0 to prevent the read of stack_var in thread 1
4-
// from being optimized away and preventing the detection of the data-race.
1+
//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
52

63
use std::ptr::null_mut;
74
use std::sync::atomic::{AtomicPtr, Ordering};

src/tools/miri/tests/fail/erroneous_const.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Make sure we detect erroneous constants post-monomorphization even when they are unused.
22
//! (https://github.com/rust-lang/miri/issues/1382)
3-
// Inlining changes the error location
4-
//@compile-flags: -Zmir-opt-level=0
53
#![feature(never_type)]
64

75
struct PrintName<T>(T);

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_after.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ pub struct S(i32);
55

66
#[custom_mir(dialect = "runtime", phase = "optimized")]
77
fn main() {
8-
// FIXME: the span is not great (probably caused by custom MIR)
9-
mir! { //~ERROR: uninitialized
8+
mir! {
109
let unit: ();
10+
let _observe: i32;
1111
{
1212
let non_copy = S(42);
1313
// This could change `non_copy` in-place
1414
Call(unit, after_call, change_arg(Move(non_copy)))
1515
}
1616
after_call = {
1717
// So now we must not be allowed to observe non-copy again.
18-
let _observe = non_copy.0;
18+
_observe = non_copy.0; //~ERROR: uninitialized
1919
Return()
2020
}
2121

src/tools/miri/tests/fail/function_calls/arg_inplace_observe_after.stderr

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
22
--> $DIR/arg_inplace_observe_after.rs:LL:CC
33
|
4-
LL | / mir! {
5-
LL | | let unit: ();
6-
LL | | {
7-
LL | | let non_copy = S(42);
8-
... |
9-
LL | |
10-
LL | | }
11-
| |_____^ using uninitialized data, but this operation requires initialized memory
4+
LL | _observe = non_copy.0;
5+
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
126
|
137
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
148
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
159
= note: BACKTRACE:
16-
= note: inside `main` at RUSTLIB/core/src/intrinsics/mir.rs:LL:CC
17-
= note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: inside `main` at $DIR/arg_inplace_observe_after.rs:LL:CC
1811

1912
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
2013

src/tools/miri/tests/fail/unaligned_pointers/dyn_alignment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// should find the bug even without, but gets masked by optimizations
2-
//@compile-flags: -Zmiri-disable-stacked-borrows -Zmir-opt-level=0 -Cdebug-assertions=no
2+
//@compile-flags: -Zmiri-disable-stacked-borrows -Cdebug-assertions=no
33
//@normalize-stderr-test: "but found [0-9]+" -> "but found $$ALIGN"
44

55
#[repr(align(256))]

src/tools/miri/tests/fail/unaligned_pointers/unaligned_ptr_zst.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// This should fail even without validation
2-
// Some optimizations remove ZST accesses, thus masking this UB.
3-
//@compile-flags: -Zmir-opt-level=0 -Zmiri-disable-validation -Cdebug-assertions=no
2+
//@compile-flags: -Zmiri-disable-validation -Cdebug-assertions=no
43

54
fn main() {
65
// Try many times as this might work by chance.

src/tools/miri/tests/fail/validity/nonzero.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// gets masked by optimizations
2-
//@compile-flags: -Zmir-opt-level=0
31
#![feature(rustc_attrs)]
42
#![allow(unused_attributes)]
53

src/tools/miri/tests/fail/zst2.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Some optimizations remove ZST accesses, thus masking this UB.
2-
//@compile-flags: -Zmir-opt-level=0
3-
41
fn main() {
52
// Not using the () type here, as writes of that type do not even have MIR generated.
63
// Also not assigning directly as that's array initialization, not assignment.

src/tools/miri/tests/fail/zst3.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Some optimizations remove ZST accesses, thus masking this UB.
2-
//@compile-flags: -Zmir-opt-level=0
3-
41
fn main() {
52
// Not using the () type here, as writes of that type do not even have MIR generated.
63
// Also not assigning directly as that's array initialization, not assignment.

0 commit comments

Comments
 (0)