From c2f232e5a370c13b275f70b1c334e0bbc1f3038d Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 27 Oct 2023 08:53:49 +0200 Subject: [PATCH 01/13] add aarch64-apple-darwin to list of supported targets --- src/tools/miri/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tools/miri/README.md b/src/tools/miri/README.md index ca2bb80bd26d3..f90fd1f7fc54e 100644 --- a/src/tools/miri/README.md +++ b/src/tools/miri/README.md @@ -223,9 +223,10 @@ degree documented below): - All Rust [Tier 1 targets](https://doc.rust-lang.org/rustc/platform-support.html) are supported by Miri. They are all checked on Miri's CI, and some (at least one per OS) are even checked on every Rust PR, so the shipped Miri should always work on these targets. -- We also support `s390x-unknown-linux-gnu` as our "big-endian target of choice". +- `aarch64-apple-darwin` is supported. +- `s390x-unknown-linux-gnu` is supported as our "big-endian target of choice". - For every other target with OS `linux`, `macos`, or `windows`, Miri should generally work, but we - make no promises. + make no promises and we don't run tests for such targets. - For targets on other operating systems, even basic operations such as printing to the standard output might not work, and Miri might fail before even reaching the `main` function. From 052539ece2cfeee8e425f1aab01587245a78feb5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 27 Oct 2023 12:27:58 +0200 Subject: [PATCH 02/13] data-race: preserve structured access information longer, and don't upper-case access types --- src/tools/miri/src/concurrency/data_race.rs | 142 ++++++++++++------ .../both_borrows/retag_data_race_write.rs | 2 +- .../retag_data_race_write.stack.stderr | 4 +- .../retag_data_race_write.tree.stderr | 4 +- .../tests/fail/data_race/alloc_read_race.rs | 2 +- .../fail/data_race/alloc_read_race.stderr | 4 +- .../tests/fail/data_race/alloc_write_race.rs | 2 +- .../fail/data_race/alloc_write_race.stderr | 4 +- .../data_race/atomic_read_na_write_race1.rs | 2 +- .../atomic_read_na_write_race1.stderr | 4 +- .../data_race/atomic_read_na_write_race2.rs | 2 +- .../atomic_read_na_write_race2.stderr | 4 +- .../data_race/atomic_write_na_read_race1.rs | 2 +- .../atomic_write_na_read_race1.stderr | 4 +- .../data_race/atomic_write_na_read_race2.rs | 2 +- .../atomic_write_na_read_race2.stderr | 4 +- .../data_race/atomic_write_na_write_race1.rs | 2 +- .../atomic_write_na_write_race1.stderr | 4 +- .../data_race/atomic_write_na_write_race2.rs | 2 +- .../atomic_write_na_write_race2.stderr | 4 +- .../data_race/dangling_thread_async_race.rs | 2 +- .../dangling_thread_async_race.stderr | 4 +- .../fail/data_race/dangling_thread_race.rs | 2 +- .../data_race/dangling_thread_race.stderr | 4 +- .../fail/data_race/dealloc_read_race1.rs | 2 +- .../fail/data_race/dealloc_read_race1.stderr | 4 +- .../fail/data_race/dealloc_read_race2.rs | 2 +- .../fail/data_race/dealloc_read_race_stack.rs | 2 +- .../data_race/dealloc_read_race_stack.stderr | 4 +- .../fail/data_race/dealloc_write_race1.rs | 2 +- .../fail/data_race/dealloc_write_race1.stderr | 4 +- .../fail/data_race/dealloc_write_race2.rs | 2 +- .../data_race/dealloc_write_race_stack.rs | 2 +- .../data_race/dealloc_write_race_stack.stderr | 4 +- .../data_race/enable_after_join_to_main.rs | 2 +- .../enable_after_join_to_main.stderr | 4 +- .../tests/fail/data_race/fence_after_load.rs | 2 +- .../fail/data_race/fence_after_load.stderr | 4 +- .../tests/fail/data_race/mixed_size_read.rs | 2 +- .../fail/data_race/mixed_size_read.stderr | 4 +- .../tests/fail/data_race/mixed_size_write.rs | 2 +- .../fail/data_race/mixed_size_write.stderr | 4 +- .../tests/fail/data_race/read_read_race1.rs | 2 +- .../fail/data_race/read_read_race1.stderr | 4 +- .../tests/fail/data_race/read_read_race2.rs | 2 +- .../fail/data_race/read_read_race2.stderr | 4 +- .../tests/fail/data_race/read_write_race.rs | 2 +- .../fail/data_race/read_write_race.stderr | 4 +- .../fail/data_race/read_write_race_stack.rs | 2 +- .../data_race/read_write_race_stack.stderr | 4 +- .../fail/data_race/relax_acquire_race.rs | 2 +- .../fail/data_race/relax_acquire_race.stderr | 4 +- .../tests/fail/data_race/release_seq_race.rs | 2 +- .../fail/data_race/release_seq_race.stderr | 4 +- .../data_race/release_seq_race_same_thread.rs | 2 +- .../release_seq_race_same_thread.stderr | 4 +- .../miri/tests/fail/data_race/rmw_race.rs | 2 +- .../miri/tests/fail/data_race/rmw_race.stderr | 4 +- .../tests/fail/data_race/stack_pop_race.rs | 2 +- .../fail/data_race/stack_pop_race.stderr | 4 +- .../tests/fail/data_race/write_write_race.rs | 2 +- .../fail/data_race/write_write_race.stderr | 4 +- .../fail/data_race/write_write_race_stack.rs | 2 +- .../data_race/write_write_race_stack.stderr | 4 +- .../retag_data_race_protected_read.rs | 2 +- .../retag_data_race_protected_read.stderr | 4 +- .../stacked_borrows/retag_data_race_read.rs | 2 +- .../retag_data_race_read.stderr | 4 +- .../fail/weak_memory/racing_mixed_size.stderr | 4 +- .../weak_memory/racing_mixed_size_read.stderr | 4 +- 70 files changed, 196 insertions(+), 154 deletions(-) diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index 4cab86af8861f..76cc0a5689703 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -41,7 +41,6 @@ //! on the data-race detection code. use std::{ - borrow::Cow, cell::{Cell, Ref, RefCell, RefMut}, fmt::Debug, mem, @@ -199,7 +198,7 @@ struct AtomicMemoryCellClocks { /// are all treated as writes for the purpose /// of the data-race detector. #[derive(Copy, Clone, PartialEq, Eq, Debug)] -enum WriteType { +enum NaWriteType { /// Allocate memory. Allocate, @@ -212,12 +211,41 @@ enum WriteType { /// (Same for `Allocate` above.) Deallocate, } -impl WriteType { - fn get_descriptor(self) -> &'static str { + +impl NaWriteType { + fn description(self) -> &'static str { + match self { + NaWriteType::Allocate => "creating a new allocation", + NaWriteType::Write => "non-atomic write", + NaWriteType::Deallocate => "deallocation", + } + } +} + +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +enum AccessType { + NaRead, + NaWrite(NaWriteType), + AtomicLoad, + AtomicStore, + AtomicRmw, +} + +impl AccessType { + fn description(self) -> &'static str { + match self { + AccessType::NaRead => "non-atomic read", + AccessType::NaWrite(w) => w.description(), + AccessType::AtomicLoad => "atomic load", + AccessType::AtomicStore => "atomic store", + AccessType::AtomicRmw => "atomic read-modify-write", + } + } + + fn is_atomic(self) -> bool { match self { - WriteType::Allocate => "Allocate", - WriteType::Write => "Write", - WriteType::Deallocate => "Deallocate", + AccessType::AtomicLoad | AccessType::AtomicStore | AccessType::AtomicRmw => true, + AccessType::NaRead | AccessType::NaWrite(_) => false, } } } @@ -234,7 +262,7 @@ struct MemoryCellClocks { /// The type of operation that the write index represents, /// either newly allocated memory, a non-atomic write or /// a deallocation of memory. - write_type: WriteType, + write_type: NaWriteType, /// The vector-clock of all non-atomic reads that happened since the last non-atomic write /// (i.e., we join together the "singleton" clocks corresponding to each read). It is reset to @@ -265,7 +293,7 @@ impl MemoryCellClocks { MemoryCellClocks { read: VClock::default(), write: (alloc_index, alloc), - write_type: WriteType::Allocate, + write_type: NaWriteType::Allocate, atomic_ops: None, } } @@ -488,7 +516,7 @@ impl MemoryCellClocks { &mut self, thread_clocks: &mut ThreadClockSet, index: VectorIdx, - write_type: WriteType, + write_type: NaWriteType, current_span: Span, ) -> Result<(), DataRace> { log::trace!("Unsynchronized write with vectors: {:#?} :: {:#?}", self, thread_clocks); @@ -838,48 +866,47 @@ impl VClockAlloc { global: &GlobalState, thread_mgr: &ThreadManager<'_, '_>, mem_clocks: &MemoryCellClocks, - action: &str, - is_atomic: bool, + access: AccessType, access_size: Size, ptr_dbg: Pointer, ) -> InterpResult<'tcx> { let (current_index, current_clocks) = global.current_thread_state(thread_mgr); - let mut action = Cow::Borrowed(action); + let mut other_size = None; // if `Some`, this was a size-mismatch race let mut involves_non_atomic = true; let write_clock; let (other_action, other_thread, other_clock) = // First check the atomic-nonatomic cases. If it looks like multiple // cases apply, this one should take precedence, else it might look like // we are reporting races between two non-atomic reads. - if !is_atomic && + if !access.is_atomic() && let Some(atomic) = mem_clocks.atomic() && let Some(idx) = Self::find_gt_index(&atomic.write_vector, ¤t_clocks.clock) { - (format!("Atomic Store"), idx, &atomic.write_vector) - } else if !is_atomic && + (AccessType::AtomicStore, idx, &atomic.write_vector) + } else if !access.is_atomic() && let Some(atomic) = mem_clocks.atomic() && let Some(idx) = Self::find_gt_index(&atomic.read_vector, ¤t_clocks.clock) { - (format!("Atomic Load"), idx, &atomic.read_vector) + (AccessType::AtomicLoad, idx, &atomic.read_vector) // Then check races with non-atomic writes/reads. } else if mem_clocks.write.1 > current_clocks.clock[mem_clocks.write.0] { write_clock = mem_clocks.write(); - (mem_clocks.write_type.get_descriptor().to_owned(), mem_clocks.write.0, &write_clock) + (AccessType::NaWrite(mem_clocks.write_type), mem_clocks.write.0, &write_clock) } else if let Some(idx) = Self::find_gt_index(&mem_clocks.read, ¤t_clocks.clock) { - (format!("Read"), idx, &mem_clocks.read) + (AccessType::NaRead, idx, &mem_clocks.read) // Finally, mixed-size races. - } else if is_atomic && let Some(atomic) = mem_clocks.atomic() && atomic.size != access_size { + } else if access.is_atomic() && let Some(atomic) = mem_clocks.atomic() && atomic.size != access_size { // This is only a race if we are not synchronized with all atomic accesses, so find // the one we are not synchronized with. involves_non_atomic = false; - action = format!("{}-byte (different-size) {action}", access_size.bytes()).into(); + other_size = Some(atomic.size); if let Some(idx) = Self::find_gt_index(&atomic.write_vector, ¤t_clocks.clock) { - (format!("{}-byte Atomic Store", atomic.size.bytes()), idx, &atomic.write_vector) + (AccessType::AtomicStore, idx, &atomic.write_vector) } else if let Some(idx) = Self::find_gt_index(&atomic.read_vector, ¤t_clocks.clock) { - (format!("{}-byte Atomic Load", atomic.size.bytes()), idx, &atomic.read_vector) + (AccessType::AtomicLoad, idx, &atomic.read_vector) } else { unreachable!( "Failed to report data-race for mixed-size access: no race found" @@ -898,12 +925,24 @@ impl VClockAlloc { involves_non_atomic, ptr: ptr_dbg, op1: RacingOp { - action: other_action.to_string(), + action: if let Some(other_size) = other_size { + format!("{}-byte {}", other_size.bytes(), other_action.description()) + } else { + other_action.description().to_owned() + }, thread_info: other_thread_info, span: other_clock.as_slice()[other_thread.index()].span_data(), }, op2: RacingOp { - action: action.to_string(), + action: if other_size.is_some() { + format!( + "{}-byte (different-size) {}", + access_size.bytes(), + access.description() + ) + } else { + access.description().to_owned() + }, thread_info: current_thread_info, span: current_clocks.clock.as_slice()[current_index.index()].span_data(), }, @@ -938,8 +977,7 @@ impl VClockAlloc { global, &machine.threads, mem_clocks, - "Read", - /* is_atomic */ false, + AccessType::NaRead, access_range.size, Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)), ); @@ -956,7 +994,7 @@ impl VClockAlloc { &mut self, alloc_id: AllocId, access_range: AllocRange, - write_type: WriteType, + write_type: NaWriteType, machine: &mut MiriMachine<'_, '_>, ) -> InterpResult<'tcx> { let current_span = machine.current_span(); @@ -978,8 +1016,7 @@ impl VClockAlloc { global, &machine.threads, mem_clocks, - write_type.get_descriptor(), - /* is_atomic */ false, + AccessType::NaWrite(write_type), access_range.size, Pointer::new(alloc_id, Size::from_bytes(mem_clocks_range.start)), ); @@ -1001,7 +1038,7 @@ impl VClockAlloc { range: AllocRange, machine: &mut MiriMachine<'_, '_>, ) -> InterpResult<'tcx> { - self.unique_access(alloc_id, range, WriteType::Write, machine) + self.unique_access(alloc_id, range, NaWriteType::Write, machine) } /// Detect data-races for an unsynchronized deallocate operation, will not perform @@ -1014,7 +1051,7 @@ impl VClockAlloc { range: AllocRange, machine: &mut MiriMachine<'_, '_>, ) -> InterpResult<'tcx> { - self.unique_access(alloc_id, range, WriteType::Deallocate, machine) + self.unique_access(alloc_id, range, NaWriteType::Deallocate, machine) } } @@ -1104,7 +1141,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { this.validate_atomic_op( place, atomic, - "Atomic Load", + AccessType::AtomicLoad, move |memory, clocks, index, atomic| { if atomic == AtomicReadOrd::Relaxed { memory.load_relaxed(&mut *clocks, index, place.layout.size) @@ -1126,7 +1163,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { this.validate_atomic_op( place, atomic, - "Atomic Store", + AccessType::AtomicStore, move |memory, clocks, index, atomic| { if atomic == AtomicWriteOrd::Relaxed { memory.store_relaxed(clocks, index, place.layout.size) @@ -1148,18 +1185,23 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { let acquire = matches!(atomic, Acquire | AcqRel | SeqCst); let release = matches!(atomic, Release | AcqRel | SeqCst); let this = self.eval_context_mut(); - this.validate_atomic_op(place, atomic, "Atomic RMW", move |memory, clocks, index, _| { - if acquire { - memory.load_acquire(clocks, index, place.layout.size)?; - } else { - memory.load_relaxed(clocks, index, place.layout.size)?; - } - if release { - memory.rmw_release(clocks, index, place.layout.size) - } else { - memory.rmw_relaxed(clocks, index, place.layout.size) - } - }) + this.validate_atomic_op( + place, + atomic, + AccessType::AtomicRmw, + move |memory, clocks, index, _| { + if acquire { + memory.load_acquire(clocks, index, place.layout.size)?; + } else { + memory.load_relaxed(clocks, index, place.layout.size)?; + } + if release { + memory.rmw_release(clocks, index, place.layout.size) + } else { + memory.rmw_relaxed(clocks, index, place.layout.size) + } + }, + ) } /// Generic atomic operation implementation @@ -1167,7 +1209,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { &self, place: &MPlaceTy<'tcx, Provenance>, atomic: A, - description: &str, + access: AccessType, mut op: impl FnMut( &mut MemoryCellClocks, &mut ThreadClockSet, @@ -1176,6 +1218,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { ) -> Result<(), DataRace>, ) -> InterpResult<'tcx> { let this = self.eval_context_ref(); + assert!(access.is_atomic()); if let Some(data_race) = &this.machine.data_race { if data_race.race_detecting() { let size = place.layout.size; @@ -1185,7 +1228,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { let alloc_meta = this.get_alloc_extra(alloc_id)?.data_race.as_ref().unwrap(); log::trace!( "Atomic op({}) with ordering {:?} on {:?} (size={})", - description, + access.description(), &atomic, place.ptr(), size.bytes() @@ -1207,8 +1250,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { data_race, &this.machine.threads, mem_clocks, - description, - /* is_atomic */ true, + access, place.layout.size, Pointer::new( alloc_id, diff --git a/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.rs b/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.rs index 868b3beb53b7d..7c67ea45bdff9 100644 --- a/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.rs +++ b/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.rs @@ -17,7 +17,7 @@ fn thread_1(p: SendPtr) { fn thread_2(p: SendPtr) { let p = p.0; unsafe { - *p = 5; //~ ERROR: /Data race detected between \(1\) (Read|Write) on thread `` and \(2\) Write on thread ``/ + *p = 5; //~ ERROR: /Data race detected between \(1\) non-atomic (read|write) on thread `` and \(2\) non-atomic write on thread ``/ } } diff --git a/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.stack.stderr b/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.stack.stderr index da5af60067565..0de2f66fe0b23 100644 --- a/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.stack.stderr +++ b/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.stack.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/retag_data_race_write.rs:LL:CC | LL | *p = 5; - | ^^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/retag_data_race_write.rs:LL:CC diff --git a/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.tree.stderr b/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.tree.stderr index 37d216b9877be..8036c974eec13 100644 --- a/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.tree.stderr +++ b/src/tools/miri/tests/fail/both_borrows/retag_data_race_write.tree.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/retag_data_race_write.rs:LL:CC | LL | *p = 5; - | ^^^^^^ Data race detected between (1) Read on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^ Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/retag_data_race_write.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/alloc_read_race.rs b/src/tools/miri/tests/fail/data_race/alloc_read_race.rs index 42077dfae2d38..786e57666e2ce 100644 --- a/src/tools/miri/tests/fail/data_race/alloc_read_race.rs +++ b/src/tools/miri/tests/fail/data_race/alloc_read_race.rs @@ -39,7 +39,7 @@ pub fn main() { let pointer = &*ptr.0; // Note: could also error due to reading uninitialized memory, but the data-race detector triggers first. - *pointer.load(Ordering::Relaxed) //~ ERROR: Data race detected between (1) Allocate on thread `` and (2) Read on thread `` + *pointer.load(Ordering::Relaxed) //~ ERROR: Data race detected between (1) creating a new allocation on thread `` and (2) non-atomic read on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/alloc_read_race.stderr b/src/tools/miri/tests/fail/data_race/alloc_read_race.stderr index 5b809722c7095..9d21a3e0a454d 100644 --- a/src/tools/miri/tests/fail/data_race/alloc_read_race.stderr +++ b/src/tools/miri/tests/fail/data_race/alloc_read_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Allocate on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) creating a new allocation on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/alloc_read_race.rs:LL:CC | LL | *pointer.load(Ordering::Relaxed) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Allocate on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) creating a new allocation on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/alloc_read_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/alloc_write_race.rs b/src/tools/miri/tests/fail/data_race/alloc_write_race.rs index 53f4e637a197d..8c685dcb7603a 100644 --- a/src/tools/miri/tests/fail/data_race/alloc_write_race.rs +++ b/src/tools/miri/tests/fail/data_race/alloc_write_race.rs @@ -37,7 +37,7 @@ pub fn main() { let j2 = spawn(move || { let ptr = ptr; // avoid field capturing let pointer = &*ptr.0; - *pointer.load(Ordering::Relaxed) = 2; //~ ERROR: Data race detected between (1) Allocate on thread `` and (2) Write on thread `` + *pointer.load(Ordering::Relaxed) = 2; //~ ERROR: Data race detected between (1) creating a new allocation on thread `` and (2) non-atomic write on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/alloc_write_race.stderr b/src/tools/miri/tests/fail/data_race/alloc_write_race.stderr index 8520bcf4e4ee1..13a19109e8868 100644 --- a/src/tools/miri/tests/fail/data_race/alloc_write_race.stderr +++ b/src/tools/miri/tests/fail/data_race/alloc_write_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Allocate on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) creating a new allocation on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/alloc_write_race.rs:LL:CC | LL | *pointer.load(Ordering::Relaxed) = 2; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Allocate on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) creating a new allocation on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/alloc_write_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.rs b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.rs index 9606df1d6ff78..d7e9561caf3a3 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.rs +++ b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.rs @@ -22,7 +22,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing - (&*c.0).load(Ordering::SeqCst) //~ ERROR: Data race detected between (1) Write on thread `` and (2) Atomic Load on thread `` + (&*c.0).load(Ordering::SeqCst) //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) atomic load on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.stderr b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.stderr index e25629e14eada..f55f839d0b8c4 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race1.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Atomic Load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/atomic_read_na_write_race1.rs:LL:CC | LL | (&*c.0).load(Ordering::SeqCst) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Atomic Load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/atomic_read_na_write_race1.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.rs b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.rs index 0e29ab32eef9b..62bf8b6556182 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.rs +++ b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.rs @@ -25,7 +25,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing let atomic_ref = &mut *c.0; - *atomic_ref.get_mut() = 32; //~ ERROR: Data race detected between (1) Atomic Load on thread `` and (2) Write on thread `` + *atomic_ref.get_mut() = 32; //~ ERROR: Data race detected between (1) atomic load on thread `` and (2) non-atomic write on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.stderr b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.stderr index 6953b1403b4b5..a20c220b6c2d8 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/atomic_read_na_write_race2.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Atomic Load on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) atomic load on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/atomic_read_na_write_race2.rs:LL:CC | LL | *atomic_ref.get_mut() = 32; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Atomic Load on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) atomic load on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/atomic_read_na_write_race2.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.rs b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.rs index 6f1792bc8f4f7..9186c562670e1 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.rs +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.rs @@ -25,7 +25,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing let atomic_ref = &mut *c.0; - *atomic_ref.get_mut() //~ ERROR: Data race detected between (1) Atomic Store on thread `` and (2) Read on thread `` + *atomic_ref.get_mut() //~ ERROR: Data race detected between (1) atomic store on thread `` and (2) non-atomic read on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.stderr b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.stderr index e52b8895a6af6..a91d4cee054ca 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race1.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Atomic Store on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) atomic store on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/atomic_write_na_read_race1.rs:LL:CC | LL | *atomic_ref.get_mut() - | ^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Atomic Store on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) atomic store on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/atomic_write_na_read_race1.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.rs b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.rs index e84207e655d61..0fcae906f0912 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.rs +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.rs @@ -22,7 +22,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing - (&*c.0).store(32, Ordering::SeqCst); //~ ERROR: Data race detected between (1) Read on thread `` and (2) Atomic Store on thread `` + (&*c.0).store(32, Ordering::SeqCst); //~ ERROR: Data race detected between (1) non-atomic read on thread `` and (2) atomic store on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.stderr b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.stderr index 513d13b0349a0..8831d9cfc1cd0 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_read_race2.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Atomic Store on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) atomic store on thread `` at ALLOC. (2) just happened here --> $DIR/atomic_write_na_read_race2.rs:LL:CC | LL | (&*c.0).store(32, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Read on thread `` and (2) Atomic Store on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic read on thread `` and (2) atomic store on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/atomic_write_na_read_race2.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.rs b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.rs index ca269b1bd2ac0..822d86c1c1d7d 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.rs +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.rs @@ -22,7 +22,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing - (&*c.0).store(64, Ordering::SeqCst); //~ ERROR: Data race detected between (1) Write on thread `` and (2) Atomic Store on thread `` + (&*c.0).store(64, Ordering::SeqCst); //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) atomic store on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.stderr b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.stderr index 2ff70ef1f6d73..5aed907b16647 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race1.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Atomic Store on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) atomic store on thread `` at ALLOC. (2) just happened here --> $DIR/atomic_write_na_write_race1.rs:LL:CC | LL | (&*c.0).store(64, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Atomic Store on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) atomic store on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/atomic_write_na_write_race1.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.rs b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.rs index 0d69a9a332dc4..d84531646e231 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.rs +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.rs @@ -25,7 +25,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing let atomic_ref = &mut *c.0; - *atomic_ref.get_mut() = 32; //~ ERROR: Data race detected between (1) Atomic Store on thread `` and (2) Write on thread `` + *atomic_ref.get_mut() = 32; //~ ERROR: Data race detected between (1) atomic store on thread `` and (2) non-atomic write on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.stderr b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.stderr index 166b4d2269a88..65114296f52c6 100644 --- a/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/atomic_write_na_write_race2.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Atomic Store on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) atomic store on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/atomic_write_na_write_race2.rs:LL:CC | LL | *atomic_ref.get_mut() = 32; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Atomic Store on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) atomic store on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/atomic_write_na_write_race2.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.rs b/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.rs index 0679b81f0122c..0fdb8e631a1f6 100644 --- a/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.rs +++ b/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.rs @@ -36,7 +36,7 @@ fn main() { let join2 = unsafe { spawn(move || { let c = c; // capture `c`, not just its field. - *c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `` and (2) Write on thread `` + *c.0 = 64; //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` }) }; diff --git a/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.stderr b/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.stderr index a08b21ab0e4ab..7ac3a9cc929ec 100644 --- a/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.stderr +++ b/src/tools/miri/tests/fail/data_race/dangling_thread_async_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/dangling_thread_async_race.rs:LL:CC | LL | *c.0 = 64; - | ^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/dangling_thread_async_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/dangling_thread_race.rs b/src/tools/miri/tests/fail/data_race/dangling_thread_race.rs index 3c5dd424eb110..fa2176d844f26 100644 --- a/src/tools/miri/tests/fail/data_race/dangling_thread_race.rs +++ b/src/tools/miri/tests/fail/data_race/dangling_thread_race.rs @@ -34,6 +34,6 @@ fn main() { spawn(|| ()).join().unwrap(); unsafe { - *c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `` and (2) Write on thread `main` + *c.0 = 64; //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `main` } } diff --git a/src/tools/miri/tests/fail/data_race/dangling_thread_race.stderr b/src/tools/miri/tests/fail/data_race/dangling_thread_race.stderr index aa2e6a6f71265..49256dff51fe0 100644 --- a/src/tools/miri/tests/fail/data_race/dangling_thread_race.stderr +++ b/src/tools/miri/tests/fail/data_race/dangling_thread_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `main` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `main` at ALLOC. (2) just happened here --> $DIR/dangling_thread_race.rs:LL:CC | LL | *c.0 = 64; - | ^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `main` at ALLOC. (2) just happened here + | ^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `main` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/dangling_thread_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs index 3c25cdc0d8d87..1d914f0a80839 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.rs @@ -27,7 +27,7 @@ pub fn main() { let j2 = spawn(move || { let ptr = ptr; // avoid field capturing __rust_dealloc( - //~^ ERROR: Data race detected between (1) Read on thread `` and (2) Deallocate on thread `` + //~^ ERROR: Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `` ptr.0 as *mut _, std::mem::size_of::(), std::mem::align_of::(), diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr index 5e546646479d2..ef6b0c3616b1b 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race1.stderr @@ -1,4 +1,4 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here --> $DIR/dealloc_read_race1.rs:LL:CC | LL | / __rust_dealloc( @@ -7,7 +7,7 @@ LL | | ptr.0 as *mut _, LL | | std::mem::size_of::(), LL | | std::mem::align_of::(), LL | | ); - | |_____________^ Data race detected between (1) Read on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here + | |_____________^ Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/dealloc_read_race1.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs b/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs index c921ce6b71651..53f1d19fa7157 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race2.rs @@ -30,7 +30,7 @@ pub fn main() { let j2 = spawn(move || { let ptr = ptr; // avoid field capturing - // Also an error of the form: Data race detected between (1) Deallocate on thread `` and (2) Read on thread `` + // Also an error of the form: Data race detected between (1) deallocation on thread `` and (2) non-atomic read on thread `` // but the invalid allocation is detected first. *ptr.0 //~ ERROR: has been freed }); diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.rs b/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.rs index 87b5f204816cb..728dc64d828d0 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.rs @@ -36,7 +36,7 @@ pub fn main() { sleep(Duration::from_millis(200)); // Now `stack_var` gets deallocated. - } //~ ERROR: Data race detected between (1) Read on thread `` and (2) Deallocate on thread `` + } //~ ERROR: Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `` }); let j2 = spawn(move || { diff --git a/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.stderr b/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.stderr index beb70c5a7fa82..805d7c1964231 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_read_race_stack.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here --> $DIR/dealloc_read_race_stack.rs:LL:CC | LL | } - | ^ Data race detected between (1) Read on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here + | ^ Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/dealloc_read_race_stack.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs index b700f50ce1911..e0d7f983a6372 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.rs @@ -26,7 +26,7 @@ pub fn main() { let j2 = spawn(move || { let ptr = ptr; // avoid field capturing __rust_dealloc( - //~^ ERROR: Data race detected between (1) Write on thread `` and (2) Deallocate on thread `` + //~^ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) deallocation on thread `` ptr.0 as *mut _, std::mem::size_of::(), std::mem::align_of::(), diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr index cc4c4524ba25d..22ef35959f274 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race1.stderr @@ -1,4 +1,4 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here --> $DIR/dealloc_write_race1.rs:LL:CC | LL | / __rust_dealloc( @@ -7,7 +7,7 @@ LL | | ptr.0 as *mut _, LL | | std::mem::size_of::(), LL | | std::mem::align_of::(), LL | | ); - | |_____________^ Data race detected between (1) Write on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here + | |_____________^ Data race detected between (1) non-atomic write on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/dealloc_write_race1.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs b/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs index e01132202d49e..11b9d97527c00 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race2.rs @@ -29,7 +29,7 @@ pub fn main() { let j2 = spawn(move || { let ptr = ptr; // avoid field capturing - // Also an error of the form: Data race detected between (1) Deallocate on thread `` and (2) Write on thread `` + // Also an error of the form: Data race detected between (1) deallocation on thread `` and (2) non-atomic write on thread `` // but the invalid allocation is detected first. *ptr.0 = 2; //~ ERROR: has been freed }); diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.rs b/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.rs index 3d35187a018c0..da3cdc23ad602 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.rs +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.rs @@ -36,7 +36,7 @@ pub fn main() { sleep(Duration::from_millis(200)); // Now `stack_var` gets deallocated. - } //~ ERROR: Data race detected between (1) Write on thread `` and (2) Deallocate on thread `` + } //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) deallocation on thread `` }); let j2 = spawn(move || { diff --git a/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.stderr b/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.stderr index 5f9f4f9bee423..52c9abd5fe0c2 100644 --- a/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.stderr +++ b/src/tools/miri/tests/fail/data_race/dealloc_write_race_stack.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here --> $DIR/dealloc_write_race_stack.rs:LL:CC | LL | } - | ^ Data race detected between (1) Write on thread `` and (2) Deallocate on thread `` at ALLOC. (2) just happened here + | ^ Data race detected between (1) non-atomic write on thread `` and (2) deallocation on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/dealloc_write_race_stack.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.rs b/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.rs index b44be4ac64e88..c1407fc5391f1 100644 --- a/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.rs +++ b/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.rs @@ -32,7 +32,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing - *c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `` and (2) Write on thread `` + *c.0 = 64; //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.stderr b/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.stderr index 84d1c0bf7e666..1d8bf2d0d26c0 100644 --- a/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.stderr +++ b/src/tools/miri/tests/fail/data_race/enable_after_join_to_main.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/enable_after_join_to_main.rs:LL:CC | LL | *c.0 = 64; - | ^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/enable_after_join_to_main.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/fence_after_load.rs b/src/tools/miri/tests/fail/data_race/fence_after_load.rs index 0648aa55f4aa4..12c74740387db 100644 --- a/src/tools/miri/tests/fail/data_race/fence_after_load.rs +++ b/src/tools/miri/tests/fail/data_race/fence_after_load.rs @@ -20,5 +20,5 @@ fn main() { // The fence is useless, since it did not happen-after the `store` in the other thread. // Hence this is a data race. // Also see https://github.com/rust-lang/miri/issues/2192. - unsafe { V = 2 } //~ERROR: Data race detected between (1) Write on thread `` and (2) Write on thread `main` + unsafe { V = 2 } //~ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `main` } diff --git a/src/tools/miri/tests/fail/data_race/fence_after_load.stderr b/src/tools/miri/tests/fail/data_race/fence_after_load.stderr index c30d2354e768d..17bcf24a50578 100644 --- a/src/tools/miri/tests/fail/data_race/fence_after_load.stderr +++ b/src/tools/miri/tests/fail/data_race/fence_after_load.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `main` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `main` at ALLOC. (2) just happened here --> $DIR/fence_after_load.rs:LL:CC | LL | unsafe { V = 2 } - | ^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `main` at ALLOC. (2) just happened here + | ^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `main` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/fence_after_load.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_read.rs b/src/tools/miri/tests/fail/data_race/mixed_size_read.rs index d530ed2f5a406..129b1bc50d232 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_read.rs +++ b/src/tools/miri/tests/fail/data_race/mixed_size_read.rs @@ -19,7 +19,7 @@ fn main() { }); s.spawn(|| { a8[0].load(Ordering::SeqCst); - //~^ ERROR: Race condition detected between (1) 2-byte Atomic Load on thread `` and (2) 1-byte (different-size) Atomic Load on thread `` + //~^ ERROR: Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte (different-size) atomic load on thread `` }); }); } diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr b/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr index 06944a11db859..cfbd8f7ea8498 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr +++ b/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Race condition detected between (1) 2-byte Atomic Load on thread `` and (2) 1-byte (different-size) Atomic Load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/mixed_size_read.rs:LL:CC | LL | a8[0].load(Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte Atomic Load on thread `` and (2) 1-byte (different-size) Atomic Load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/mixed_size_read.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_write.rs b/src/tools/miri/tests/fail/data_race/mixed_size_write.rs index df3551612c3e4..98fe752fb66d2 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_write.rs +++ b/src/tools/miri/tests/fail/data_race/mixed_size_write.rs @@ -19,7 +19,7 @@ fn main() { }); s.spawn(|| { a8[0].store(1, Ordering::SeqCst); - //~^ ERROR: Race condition detected between (1) 2-byte Atomic Store on thread `` and (2) 1-byte (different-size) Atomic Store on thread `` + //~^ ERROR: Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte (different-size) atomic store on thread `` }); }); } diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr b/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr index 4bb949175bfac..fa70dfc24cb0c 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr +++ b/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Race condition detected between (1) 2-byte Atomic Store on thread `` and (2) 1-byte (different-size) Atomic Store on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte (different-size) atomic store on thread `` at ALLOC. (2) just happened here --> $DIR/mixed_size_write.rs:LL:CC | LL | a8[0].store(1, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte Atomic Store on thread `` and (2) 1-byte (different-size) Atomic Store on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte (different-size) atomic store on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/mixed_size_write.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/read_read_race1.rs b/src/tools/miri/tests/fail/data_race/read_read_race1.rs index eebfbc74d40af..dd800af4af707 100644 --- a/src/tools/miri/tests/fail/data_race/read_read_race1.rs +++ b/src/tools/miri/tests/fail/data_race/read_read_race1.rs @@ -21,7 +21,7 @@ fn main() { unsafe { ptr.read() }; // Then do the atomic access. a.load(Ordering::SeqCst); - //~^ ERROR: Data race detected between (1) Read on thread `` and (2) Atomic Load on thread `` + //~^ ERROR: Data race detected between (1) non-atomic read on thread `` and (2) atomic load on thread `` }); }); } diff --git a/src/tools/miri/tests/fail/data_race/read_read_race1.stderr b/src/tools/miri/tests/fail/data_race/read_read_race1.stderr index 158b438bd0d3e..6e48cfb05a652 100644 --- a/src/tools/miri/tests/fail/data_race/read_read_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/read_read_race1.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Atomic Load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/read_read_race1.rs:LL:CC | LL | a.load(Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) Read on thread `` and (2) Atomic Load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic read on thread `` and (2) atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/read_read_race1.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/read_read_race2.rs b/src/tools/miri/tests/fail/data_race/read_read_race2.rs index 230b429e2878e..1f35cb639c3bf 100644 --- a/src/tools/miri/tests/fail/data_race/read_read_race2.rs +++ b/src/tools/miri/tests/fail/data_race/read_read_race2.rs @@ -21,7 +21,7 @@ fn main() { let ptr = &a as *const AtomicU16 as *mut u16; unsafe { ptr.read() }; - //~^ ERROR: Data race detected between (1) Atomic Load on thread `` and (2) Read on thread `` + //~^ ERROR: Data race detected between (1) atomic load on thread `` and (2) non-atomic read on thread `` }); }); } diff --git a/src/tools/miri/tests/fail/data_race/read_read_race2.stderr b/src/tools/miri/tests/fail/data_race/read_read_race2.stderr index 7f867b9edbb74..806d0fea051b8 100644 --- a/src/tools/miri/tests/fail/data_race/read_read_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/read_read_race2.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Atomic Load on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) atomic load on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/read_read_race2.rs:LL:CC | LL | unsafe { ptr.read() }; - | ^^^^^^^^^^ Data race detected between (1) Atomic Load on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^ Data race detected between (1) atomic load on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/read_read_race2.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/read_write_race.rs b/src/tools/miri/tests/fail/data_race/read_write_race.rs index aed3ca767f627..372085496863e 100644 --- a/src/tools/miri/tests/fail/data_race/read_write_race.rs +++ b/src/tools/miri/tests/fail/data_race/read_write_race.rs @@ -21,7 +21,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing - *c.0 = 64; //~ ERROR: Data race detected between (1) Read on thread `` and (2) Write on thread `` + *c.0 = 64; //~ ERROR: Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/read_write_race.stderr b/src/tools/miri/tests/fail/data_race/read_write_race.stderr index 13bc5c74ae333..c3fdcdf9308f4 100644 --- a/src/tools/miri/tests/fail/data_race/read_write_race.stderr +++ b/src/tools/miri/tests/fail/data_race/read_write_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/read_write_race.rs:LL:CC | LL | *c.0 = 64; - | ^^^^^^^^^ Data race detected between (1) Read on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^ Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/read_write_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/read_write_race_stack.rs b/src/tools/miri/tests/fail/data_race/read_write_race_stack.rs index c3e5c401d879a..df000b7942ef7 100644 --- a/src/tools/miri/tests/fail/data_race/read_write_race_stack.rs +++ b/src/tools/miri/tests/fail/data_race/read_write_race_stack.rs @@ -40,7 +40,7 @@ pub fn main() { sleep(Duration::from_millis(200)); - stack_var //~ ERROR: Data race detected between (1) Write on thread `` and (2) Read on thread `` + stack_var //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` }); let j2 = spawn(move || { diff --git a/src/tools/miri/tests/fail/data_race/read_write_race_stack.stderr b/src/tools/miri/tests/fail/data_race/read_write_race_stack.stderr index 96fcb49482225..1e45878bfddcb 100644 --- a/src/tools/miri/tests/fail/data_race/read_write_race_stack.stderr +++ b/src/tools/miri/tests/fail/data_race/read_write_race_stack.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/read_write_race_stack.rs:LL:CC | LL | stack_var - | ^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/read_write_race_stack.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/relax_acquire_race.rs b/src/tools/miri/tests/fail/data_race/relax_acquire_race.rs index 1b691b996f141..f20dcec4e2812 100644 --- a/src/tools/miri/tests/fail/data_race/relax_acquire_race.rs +++ b/src/tools/miri/tests/fail/data_race/relax_acquire_race.rs @@ -39,7 +39,7 @@ pub fn main() { let j3 = spawn(move || { let c = c; // avoid field capturing if SYNC.load(Ordering::Acquire) == 2 { - *c.0 //~ ERROR: Data race detected between (1) Write on thread `` and (2) Read on thread `` + *c.0 //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` } else { 0 } diff --git a/src/tools/miri/tests/fail/data_race/relax_acquire_race.stderr b/src/tools/miri/tests/fail/data_race/relax_acquire_race.stderr index 92755f5551d97..0c574299b69d1 100644 --- a/src/tools/miri/tests/fail/data_race/relax_acquire_race.stderr +++ b/src/tools/miri/tests/fail/data_race/relax_acquire_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/relax_acquire_race.rs:LL:CC | LL | *c.0 - | ^^^^ Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/relax_acquire_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/release_seq_race.rs b/src/tools/miri/tests/fail/data_race/release_seq_race.rs index 80b30053fc700..4050895f296ef 100644 --- a/src/tools/miri/tests/fail/data_race/release_seq_race.rs +++ b/src/tools/miri/tests/fail/data_race/release_seq_race.rs @@ -43,7 +43,7 @@ pub fn main() { let c = c; // avoid field capturing sleep(Duration::from_millis(500)); if SYNC.load(Ordering::Acquire) == 3 { - *c.0 //~ ERROR: Data race detected between (1) Write on thread `` and (2) Read on thread `` + *c.0 //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` } else { 0 } diff --git a/src/tools/miri/tests/fail/data_race/release_seq_race.stderr b/src/tools/miri/tests/fail/data_race/release_seq_race.stderr index 880268730db13..9aff6c6c3a706 100644 --- a/src/tools/miri/tests/fail/data_race/release_seq_race.stderr +++ b/src/tools/miri/tests/fail/data_race/release_seq_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/release_seq_race.rs:LL:CC | LL | *c.0 - | ^^^^ Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/release_seq_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.rs b/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.rs index 33de1f1755811..2cba38a8e1e07 100644 --- a/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.rs +++ b/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.rs @@ -39,7 +39,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing if SYNC.load(Ordering::Acquire) == 2 { - *c.0 //~ ERROR: Data race detected between (1) Write on thread `` and (2) Read on thread `` + *c.0 //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` } else { 0 } diff --git a/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.stderr b/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.stderr index 386c012ba4e5e..f0522404fde07 100644 --- a/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.stderr +++ b/src/tools/miri/tests/fail/data_race/release_seq_race_same_thread.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/release_seq_race_same_thread.rs:LL:CC | LL | *c.0 - | ^^^^ Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/release_seq_race_same_thread.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/rmw_race.rs b/src/tools/miri/tests/fail/data_race/rmw_race.rs index 4d0ce8f94339a..973ebdf48d3ca 100644 --- a/src/tools/miri/tests/fail/data_race/rmw_race.rs +++ b/src/tools/miri/tests/fail/data_race/rmw_race.rs @@ -40,7 +40,7 @@ pub fn main() { let j3 = spawn(move || { let c = c; // capture `c`, not just its field. if SYNC.load(Ordering::Acquire) == 3 { - *c.0 //~ ERROR: Data race detected between (1) Write on thread `` and (2) Read on thread `` + *c.0 //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` } else { 0 } diff --git a/src/tools/miri/tests/fail/data_race/rmw_race.stderr b/src/tools/miri/tests/fail/data_race/rmw_race.stderr index 82cb2c4ecbb47..b400b2b9a1758 100644 --- a/src/tools/miri/tests/fail/data_race/rmw_race.stderr +++ b/src/tools/miri/tests/fail/data_race/rmw_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here --> $DIR/rmw_race.rs:LL:CC | LL | *c.0 - | ^^^^ Data race detected between (1) Write on thread `` and (2) Read on thread `` at ALLOC. (2) just happened here + | ^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic read on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/rmw_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/stack_pop_race.rs b/src/tools/miri/tests/fail/data_race/stack_pop_race.rs index d3c2ab3e4a464..047d3757f14c6 100644 --- a/src/tools/miri/tests/fail/data_race/stack_pop_race.rs +++ b/src/tools/miri/tests/fail/data_race/stack_pop_race.rs @@ -21,4 +21,4 @@ fn race(local: i32) { // Deallocating the local (when `main` returns) // races with the read in the other thread. // Make sure the error points at this function's end, not just the call site. -} //~ERROR: Data race detected between (1) Read on thread `` and (2) Deallocate on thread `main` +} //~ERROR: Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `main` diff --git a/src/tools/miri/tests/fail/data_race/stack_pop_race.stderr b/src/tools/miri/tests/fail/data_race/stack_pop_race.stderr index 71e38c2727e1a..e6804f6520ce1 100644 --- a/src/tools/miri/tests/fail/data_race/stack_pop_race.stderr +++ b/src/tools/miri/tests/fail/data_race/stack_pop_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Deallocate on thread `main` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `main` at ALLOC. (2) just happened here --> $DIR/stack_pop_race.rs:LL:CC | LL | } - | ^ Data race detected between (1) Read on thread `` and (2) Deallocate on thread `main` at ALLOC. (2) just happened here + | ^ Data race detected between (1) non-atomic read on thread `` and (2) deallocation on thread `main` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/stack_pop_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/write_write_race.rs b/src/tools/miri/tests/fail/data_race/write_write_race.rs index 30e3460f222e1..05ec8d63c7af0 100644 --- a/src/tools/miri/tests/fail/data_race/write_write_race.rs +++ b/src/tools/miri/tests/fail/data_race/write_write_race.rs @@ -21,7 +21,7 @@ pub fn main() { let j2 = spawn(move || { let c = c; // avoid field capturing - *c.0 = 64; //~ ERROR: Data race detected between (1) Write on thread `` and (2) Write on thread `` + *c.0 = 64; //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` }); j1.join().unwrap(); diff --git a/src/tools/miri/tests/fail/data_race/write_write_race.stderr b/src/tools/miri/tests/fail/data_race/write_write_race.stderr index 3b7eb2b800017..bc793e9afb090 100644 --- a/src/tools/miri/tests/fail/data_race/write_write_race.stderr +++ b/src/tools/miri/tests/fail/data_race/write_write_race.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/write_write_race.rs:LL:CC | LL | *c.0 = 64; - | ^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/write_write_race.rs:LL:CC diff --git a/src/tools/miri/tests/fail/data_race/write_write_race_stack.rs b/src/tools/miri/tests/fail/data_race/write_write_race_stack.rs index 25be42bd4eb78..d3ef552eab850 100644 --- a/src/tools/miri/tests/fail/data_race/write_write_race_stack.rs +++ b/src/tools/miri/tests/fail/data_race/write_write_race_stack.rs @@ -40,7 +40,7 @@ pub fn main() { sleep(Duration::from_millis(200)); - stack_var = 1usize; //~ ERROR: Data race detected between (1) Write on thread `` and (2) Write on thread `` + stack_var = 1usize; //~ ERROR: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` // read to silence errors stack_var diff --git a/src/tools/miri/tests/fail/data_race/write_write_race_stack.stderr b/src/tools/miri/tests/fail/data_race/write_write_race_stack.stderr index c501ecd11a6d1..ea62dbf96b994 100644 --- a/src/tools/miri/tests/fail/data_race/write_write_race_stack.stderr +++ b/src/tools/miri/tests/fail/data_race/write_write_race_stack.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/write_write_race_stack.rs:LL:CC | LL | stack_var = 1usize; - | ^^^^^^^^^^^^^^^^^^ Data race detected between (1) Write on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^ Data race detected between (1) non-atomic write on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/write_write_race_stack.rs:LL:CC diff --git a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.rs b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.rs index 670fe9858ed54..71f1f132bc77f 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.rs +++ b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.rs @@ -13,7 +13,7 @@ fn main() { let ptr = ptr; // We do a protected mutable retag (but no write!) in this thread. fn retag(_x: &mut i32) {} - retag(unsafe { &mut *ptr.0 }); //~ERROR: Data race detected between (1) Read on thread `main` and (2) Write on thread `` + retag(unsafe { &mut *ptr.0 }); //~ERROR: Data race detected between (1) non-atomic read on thread `main` and (2) non-atomic write on thread `` }); // We do a read in the main thread. diff --git a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.stderr b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.stderr index 10fb1dece2afc..ce77976f88bc2 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_protected_read.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `main` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `main` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/retag_data_race_protected_read.rs:LL:CC | LL | retag(unsafe { &mut *ptr.0 }); - | ^^^^^^^^^^^ Data race detected between (1) Read on thread `main` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^ Data race detected between (1) non-atomic read on thread `main` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/retag_data_race_protected_read.rs:LL:CC diff --git a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.rs b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.rs index 0637e08af9beb..46694cd49e358 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.rs +++ b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.rs @@ -15,7 +15,7 @@ fn thread_1(p: SendPtr) { fn thread_2(p: SendPtr) { let p = p.0; unsafe { - *p = 5; //~ ERROR: Data race detected between (1) Read on thread `` and (2) Write on thread `` + *p = 5; //~ ERROR: Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` } } diff --git a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.stderr b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.stderr index c53a495b5e18b..1496c353e52a6 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.stderr +++ b/src/tools/miri/tests/fail/stacked_borrows/retag_data_race_read.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Data race detected between (1) Read on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here --> $DIR/retag_data_race_read.rs:LL:CC | LL | *p = 5; - | ^^^^^^ Data race detected between (1) Read on thread `` and (2) Write on thread `` at ALLOC. (2) just happened here + | ^^^^^^ Data race detected between (1) non-atomic read on thread `` and (2) non-atomic write on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/retag_data_race_read.rs:LL:CC diff --git a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr index 055585ab96f5b..0e170e3ee0b51 100644 --- a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr +++ b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Race condition detected between (1) 4-byte Atomic Store on thread `` and (2) 2-byte (different-size) Atomic Load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 4-byte atomic store on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/racing_mixed_size.rs:LL:CC | LL | std::intrinsics::atomic_load_relaxed(hi); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte Atomic Store on thread `` and (2) 2-byte (different-size) Atomic Load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte atomic store on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/racing_mixed_size.rs:LL:CC diff --git a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr index 2eefa0a87b49a..d1d9be4666e1a 100644 --- a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr +++ b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr @@ -1,8 +1,8 @@ -error: Undefined Behavior: Race condition detected between (1) 4-byte Atomic Load on thread `` and (2) 2-byte (different-size) Atomic Load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 4-byte atomic load on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/racing_mixed_size_read.rs:LL:CC | LL | (*hi).load(Relaxed); - | ^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte Atomic Load on thread `` and (2) 2-byte (different-size) Atomic Load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte atomic load on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/racing_mixed_size_read.rs:LL:CC From 278965a0c4964bf53c386c64306e857f4bfb3888 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 27 Oct 2023 12:46:59 +0200 Subject: [PATCH 03/13] give some more help for the unusual data races --- src/tools/miri/src/concurrency/data_race.rs | 34 +++++++++++++------ src/tools/miri/src/diagnostics.rs | 19 +++++++---- .../tests/fail/data_race/mixed_size_read.rs | 2 +- .../fail/data_race/mixed_size_read.stderr | 5 +-- .../tests/fail/data_race/mixed_size_write.rs | 2 +- .../fail/data_race/mixed_size_write.stderr | 5 +-- .../fail/data_race/read_read_race1.stderr | 1 + .../fail/data_race/read_read_race2.stderr | 1 + .../fail/weak_memory/racing_mixed_size.rs | 2 +- .../fail/weak_memory/racing_mixed_size.stderr | 5 +-- .../weak_memory/racing_mixed_size_read.rs | 2 +- .../weak_memory/racing_mixed_size_read.stderr | 5 +-- 12 files changed, 54 insertions(+), 29 deletions(-) diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index 76cc0a5689703..f6432b6e98c1f 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -248,6 +248,13 @@ impl AccessType { AccessType::NaRead | AccessType::NaWrite(_) => false, } } + + fn is_read(self) -> bool { + match self { + AccessType::AtomicLoad | AccessType::NaRead => true, + AccessType::NaWrite(_) | AccessType::AtomicStore | AccessType::AtomicRmw => false, + } + } } /// Memory Cell vector clock metadata @@ -872,9 +879,8 @@ impl VClockAlloc { ) -> InterpResult<'tcx> { let (current_index, current_clocks) = global.current_thread_state(thread_mgr); let mut other_size = None; // if `Some`, this was a size-mismatch race - let mut involves_non_atomic = true; let write_clock; - let (other_action, other_thread, other_clock) = + let (other_access, other_thread, other_clock) = // First check the atomic-nonatomic cases. If it looks like multiple // cases apply, this one should take precedence, else it might look like // we are reporting races between two non-atomic reads. @@ -898,7 +904,6 @@ impl VClockAlloc { } else if access.is_atomic() && let Some(atomic) = mem_clocks.atomic() && atomic.size != access_size { // This is only a race if we are not synchronized with all atomic accesses, so find // the one we are not synchronized with. - involves_non_atomic = false; other_size = Some(atomic.size); if let Some(idx) = Self::find_gt_index(&atomic.write_vector, ¤t_clocks.clock) { @@ -919,27 +924,36 @@ impl VClockAlloc { // Load elaborated thread information about the racing thread actions. let current_thread_info = global.print_thread_metadata(thread_mgr, current_index); let other_thread_info = global.print_thread_metadata(thread_mgr, other_thread); + let involves_non_atomic = !access.is_atomic() || !other_access.is_atomic(); // Throw the data-race detection. + let extra = if other_size.is_some() { + assert!(!involves_non_atomic); + Some("overlapping unsynchronized atomic accesses must use the same access size") + } else if access.is_read() && other_access.is_read() { + assert!(involves_non_atomic); + Some( + "overlapping atomic and non-atomic accesses must be synchronized, even if both are read-only", + ) + } else { + None + }; Err(err_machine_stop!(TerminationInfo::DataRace { involves_non_atomic, + extra, ptr: ptr_dbg, op1: RacingOp { action: if let Some(other_size) = other_size { - format!("{}-byte {}", other_size.bytes(), other_action.description()) + format!("{}-byte {}", other_size.bytes(), other_access.description()) } else { - other_action.description().to_owned() + other_access.description().to_owned() }, thread_info: other_thread_info, span: other_clock.as_slice()[other_thread.index()].span_data(), }, op2: RacingOp { action: if other_size.is_some() { - format!( - "{}-byte (different-size) {}", - access_size.bytes(), - access.description() - ) + format!("{}-byte {}", access_size.bytes(), access.description()) } else { access.description().to_owned() }, diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index 9b8f263b7ce15..b76c82e7de369 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -47,6 +47,7 @@ pub enum TerminationInfo { ptr: Pointer, op1: RacingOp, op2: RacingOp, + extra: Option<&'static str>, }, } @@ -75,7 +76,7 @@ impl fmt::Display for TerminationInfo { write!(f, "multiple definitions of symbol `{link_name}`"), SymbolShimClashing { link_name, .. } => write!(f, "found `{link_name}` symbol definition that clashes with a built-in shim",), - DataRace { involves_non_atomic, ptr, op1, op2 } => + DataRace { involves_non_atomic, ptr, op1, op2, .. } => write!( f, "{} detected between (1) {} on {} and (2) {} on {} at {ptr:?}. (2) just happened here", @@ -266,12 +267,16 @@ pub fn report_error<'tcx, 'mir>( vec![(Some(*span), format!("the `{link_name}` symbol is defined here"))], Int2PtrWithStrictProvenance => vec![(None, format!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead"))], - DataRace { op1, .. } => - vec![ - (Some(op1.span), format!("and (1) occurred earlier here")), - (None, format!("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior")), - (None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information")), - ], + DataRace { op1, extra, .. } => { + let mut helps = vec![(Some(op1.span), format!("and (1) occurred earlier here"))]; + if let Some(extra) = extra { + helps.push((None, format!("{extra}"))) + } + helps.push((None, format!("this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior"))); + helps.push((None, format!("see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information"))); + helps + } + , _ => vec![], }; (title, helps) diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_read.rs b/src/tools/miri/tests/fail/data_race/mixed_size_read.rs index 129b1bc50d232..871d5f9a9db9b 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_read.rs +++ b/src/tools/miri/tests/fail/data_race/mixed_size_read.rs @@ -19,7 +19,7 @@ fn main() { }); s.spawn(|| { a8[0].load(Ordering::SeqCst); - //~^ ERROR: Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte (different-size) atomic load on thread `` + //~^ ERROR: Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte atomic load on thread `` }); }); } diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr b/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr index cfbd8f7ea8498..cb7dc89359a3f 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr +++ b/src/tools/miri/tests/fail/data_race/mixed_size_read.stderr @@ -1,14 +1,15 @@ -error: Undefined Behavior: Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/mixed_size_read.rs:LL:CC | LL | a8[0].load(Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic load on thread `` and (2) 1-byte atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/mixed_size_read.rs:LL:CC | LL | a16.load(Ordering::SeqCst); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: overlapping unsynchronized atomic accesses must use the same access size = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span): diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_write.rs b/src/tools/miri/tests/fail/data_race/mixed_size_write.rs index 98fe752fb66d2..e52e76e4802f6 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_write.rs +++ b/src/tools/miri/tests/fail/data_race/mixed_size_write.rs @@ -19,7 +19,7 @@ fn main() { }); s.spawn(|| { a8[0].store(1, Ordering::SeqCst); - //~^ ERROR: Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte (different-size) atomic store on thread `` + //~^ ERROR: Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte atomic store on thread `` }); }); } diff --git a/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr b/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr index fa70dfc24cb0c..b3908e9c6bfdb 100644 --- a/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr +++ b/src/tools/miri/tests/fail/data_race/mixed_size_write.stderr @@ -1,14 +1,15 @@ -error: Undefined Behavior: Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte (different-size) atomic store on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte atomic store on thread `` at ALLOC. (2) just happened here --> $DIR/mixed_size_write.rs:LL:CC | LL | a8[0].store(1, Ordering::SeqCst); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte (different-size) atomic store on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 2-byte atomic store on thread `` and (2) 1-byte atomic store on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/mixed_size_write.rs:LL:CC | LL | a16.store(1, Ordering::SeqCst); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = help: overlapping unsynchronized atomic accesses must use the same access size = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span): diff --git a/src/tools/miri/tests/fail/data_race/read_read_race1.stderr b/src/tools/miri/tests/fail/data_race/read_read_race1.stderr index 6e48cfb05a652..0846a88f362b6 100644 --- a/src/tools/miri/tests/fail/data_race/read_read_race1.stderr +++ b/src/tools/miri/tests/fail/data_race/read_read_race1.stderr @@ -9,6 +9,7 @@ help: and (1) occurred earlier here | LL | unsafe { ptr.read() }; | ^^^^^^^^^^ + = help: overlapping atomic and non-atomic accesses must be synchronized, even if both are read-only = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span): diff --git a/src/tools/miri/tests/fail/data_race/read_read_race2.stderr b/src/tools/miri/tests/fail/data_race/read_read_race2.stderr index 806d0fea051b8..c6181cc45b200 100644 --- a/src/tools/miri/tests/fail/data_race/read_read_race2.stderr +++ b/src/tools/miri/tests/fail/data_race/read_read_race2.stderr @@ -9,6 +9,7 @@ help: and (1) occurred earlier here | LL | a.load(Ordering::SeqCst); | ^^^^^^^^^^^^^^^^^^^^^^^^ + = help: overlapping atomic and non-atomic accesses must be synchronized, even if both are read-only = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span): diff --git a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.rs b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.rs index 36dc0d5f3f7ed..e36d947565a1d 100644 --- a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.rs +++ b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.rs @@ -31,7 +31,7 @@ pub fn main() { let x_split = split_u32_ptr(x_ptr); unsafe { let hi = ptr::addr_of!((*x_split)[0]); - std::intrinsics::atomic_load_relaxed(hi); //~ ERROR: different-size + std::intrinsics::atomic_load_relaxed(hi); //~ ERROR: (1) 4-byte atomic store on thread `` and (2) 2-byte atomic load } }); diff --git a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr index 0e170e3ee0b51..03b5a4e4c1700 100644 --- a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr +++ b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size.stderr @@ -1,14 +1,15 @@ -error: Undefined Behavior: Race condition detected between (1) 4-byte atomic store on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 4-byte atomic store on thread `` and (2) 2-byte atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/racing_mixed_size.rs:LL:CC | LL | std::intrinsics::atomic_load_relaxed(hi); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte atomic store on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte atomic store on thread `` and (2) 2-byte atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/racing_mixed_size.rs:LL:CC | LL | x.store(1, Relaxed); | ^^^^^^^^^^^^^^^^^^^ + = help: overlapping unsynchronized atomic accesses must use the same access size = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span): diff --git a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.rs b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.rs index 5cd14540ca3f4..34917245ea5b7 100644 --- a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.rs +++ b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.rs @@ -29,7 +29,7 @@ pub fn main() { let x_split = split_u32_ptr(x_ptr); unsafe { let hi = x_split as *const u16 as *const AtomicU16; - (*hi).load(Relaxed); //~ ERROR: different-size + (*hi).load(Relaxed); //~ ERROR: (1) 4-byte atomic load on thread `` and (2) 2-byte atomic load } }); diff --git a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr index d1d9be4666e1a..05eba41f4d54f 100644 --- a/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr +++ b/src/tools/miri/tests/fail/weak_memory/racing_mixed_size_read.stderr @@ -1,14 +1,15 @@ -error: Undefined Behavior: Race condition detected between (1) 4-byte atomic load on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here +error: Undefined Behavior: Race condition detected between (1) 4-byte atomic load on thread `` and (2) 2-byte atomic load on thread `` at ALLOC. (2) just happened here --> $DIR/racing_mixed_size_read.rs:LL:CC | LL | (*hi).load(Relaxed); - | ^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte atomic load on thread `` and (2) 2-byte (different-size) atomic load on thread `` at ALLOC. (2) just happened here + | ^^^^^^^^^^^^^^^^^^^ Race condition detected between (1) 4-byte atomic load on thread `` and (2) 2-byte atomic load on thread `` at ALLOC. (2) just happened here | help: and (1) occurred earlier here --> $DIR/racing_mixed_size_read.rs:LL:CC | LL | x.load(Relaxed); | ^^^^^^^^^^^^^^^ + = help: overlapping unsynchronized atomic accesses must use the same access size = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = note: BACKTRACE (of the first span): From e29845311d004d77750b62f3d5d2223124aa4e7f Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Sat, 28 Oct 2023 05:11:15 +0000 Subject: [PATCH 04/13] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 60ae5d12598a6..6ded1ea1c5da3 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -2e4e2a8f288f642cafcc41fff211955ceddc453d +20952db40d5220e8a15c2e569ae480877bbc8417 From 293501b24ef918ad1fa6e95c16931742561c0813 Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Sat, 28 Oct 2023 05:22:14 +0000 Subject: [PATCH 05/13] fmt --- src/tools/miri/src/bin/miri.rs | 18 +++++++++++++----- .../dangling_pointer_deref_match_never.rs | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index 531128ed2ec92..cd628444fed93 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -241,7 +241,7 @@ fn run_compiler( mut args: Vec, target_crate: bool, callbacks: &mut (dyn rustc_driver::Callbacks + Send), - using_internal_features: std::sync::Arc + using_internal_features: std::sync::Arc, ) -> ! { if target_crate { // Miri needs a custom sysroot for target crates. @@ -275,7 +275,8 @@ fn run_compiler( // Invoke compiler, and handle return code. let exit_code = rustc_driver::catch_with_exit_code(move || { rustc_driver::RunCompiler::new(&args, callbacks) - .set_using_internal_features(using_internal_features).run() + .set_using_internal_features(using_internal_features) + .run() }); std::process::exit(exit_code) } @@ -297,7 +298,8 @@ fn main() { // If the environment asks us to actually be rustc, then do that. if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") { // Earliest rustc setup. - let using_internal_features = rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); + let using_internal_features = + rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); rustc_driver::init_rustc_env_logger(&handler); let target_crate = if crate_kind == "target" { @@ -318,7 +320,8 @@ fn main() { } // Add an ICE bug report hook. - let using_internal_features = rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); + let using_internal_features = + rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); // Init loggers the Miri way. init_early_loggers(&handler); @@ -581,5 +584,10 @@ fn main() { debug!("rustc arguments: {:?}", rustc_args); debug!("crate arguments: {:?}", miri_config.args); - run_compiler(rustc_args, /* target_crate: */ true, &mut MiriCompilerCalls { miri_config }, using_internal_features) + run_compiler( + rustc_args, + /* target_crate: */ true, + &mut MiriCompilerCalls { miri_config }, + using_internal_features, + ) } diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs index 723c3f1e15897..e77c8e06a0f9e 100644 --- a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs @@ -14,4 +14,3 @@ fn main() { } panic!("this should never print"); } - From 0b6c30a865231ff6763298f6eefee184f96c5011 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 28 Oct 2023 10:44:55 +0200 Subject: [PATCH 06/13] =?UTF-8?q?atomic=5Fop=20=E2=86=92=20atomic=5Frmw=5F?= =?UTF-8?q?op?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tools/miri/src/concurrency/data_race.rs | 4 ++-- src/tools/miri/src/shims/intrinsics/atomic.rs | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index 4cab86af8861f..294335f77dcb3 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -558,8 +558,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { this.buffered_atomic_write(val, dest, atomic, val) } - /// Perform an atomic operation on a memory location. - fn atomic_op_immediate( + /// Perform an atomic RMW operation on a memory location. + fn atomic_rmw_op_immediate( &mut self, place: &MPlaceTy<'tcx, Provenance>, rhs: &ImmTy<'tcx, Provenance>, diff --git a/src/tools/miri/src/shims/intrinsics/atomic.rs b/src/tools/miri/src/shims/intrinsics/atomic.rs index e38b677f485f3..4d7f6a6b4e0e2 100644 --- a/src/tools/miri/src/shims/intrinsics/atomic.rs +++ b/src/tools/miri/src/shims/intrinsics/atomic.rs @@ -77,40 +77,40 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> { this.atomic_compare_exchange_weak(args, dest, rw_ord(ord1)?, read_ord(ord2)?)?, ["or", ord] => - this.atomic_op(args, dest, AtomicOp::MirOp(BinOp::BitOr, false), rw_ord(ord)?)?, + this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitOr, false), rw_ord(ord)?)?, ["xor", ord] => - this.atomic_op(args, dest, AtomicOp::MirOp(BinOp::BitXor, false), rw_ord(ord)?)?, + this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitXor, false), rw_ord(ord)?)?, ["and", ord] => - this.atomic_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, false), rw_ord(ord)?)?, + this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, false), rw_ord(ord)?)?, ["nand", ord] => - this.atomic_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, true), rw_ord(ord)?)?, + this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::BitAnd, true), rw_ord(ord)?)?, ["xadd", ord] => - this.atomic_op(args, dest, AtomicOp::MirOp(BinOp::Add, false), rw_ord(ord)?)?, + this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::Add, false), rw_ord(ord)?)?, ["xsub", ord] => - this.atomic_op(args, dest, AtomicOp::MirOp(BinOp::Sub, false), rw_ord(ord)?)?, + this.atomic_rmw_op(args, dest, AtomicOp::MirOp(BinOp::Sub, false), rw_ord(ord)?)?, ["min", ord] => { // Later we will use the type to indicate signed vs unsigned, // so make sure it matches the intrinsic name. assert!(matches!(args[1].layout.ty.kind(), ty::Int(_))); - this.atomic_op(args, dest, AtomicOp::Min, rw_ord(ord)?)?; + this.atomic_rmw_op(args, dest, AtomicOp::Min, rw_ord(ord)?)?; } ["umin", ord] => { // Later we will use the type to indicate signed vs unsigned, // so make sure it matches the intrinsic name. assert!(matches!(args[1].layout.ty.kind(), ty::Uint(_))); - this.atomic_op(args, dest, AtomicOp::Min, rw_ord(ord)?)?; + this.atomic_rmw_op(args, dest, AtomicOp::Min, rw_ord(ord)?)?; } ["max", ord] => { // Later we will use the type to indicate signed vs unsigned, // so make sure it matches the intrinsic name. assert!(matches!(args[1].layout.ty.kind(), ty::Int(_))); - this.atomic_op(args, dest, AtomicOp::Max, rw_ord(ord)?)?; + this.atomic_rmw_op(args, dest, AtomicOp::Max, rw_ord(ord)?)?; } ["umax", ord] => { // Later we will use the type to indicate signed vs unsigned, // so make sure it matches the intrinsic name. assert!(matches!(args[1].layout.ty.kind(), ty::Uint(_))); - this.atomic_op(args, dest, AtomicOp::Max, rw_ord(ord)?)?; + this.atomic_rmw_op(args, dest, AtomicOp::Max, rw_ord(ord)?)?; } _ => throw_unsup_format!("unimplemented intrinsic: `atomic_{intrinsic_name}`"), @@ -178,7 +178,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { Ok(()) } - fn atomic_op( + fn atomic_rmw_op( &mut self, args: &[OpTy<'tcx, Provenance>], dest: &PlaceTy<'tcx, Provenance>, @@ -213,7 +213,7 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { Ok(()) } AtomicOp::MirOp(op, neg) => { - let old = this.atomic_op_immediate(&place, &rhs, op, neg, atomic)?; + let old = this.atomic_rmw_op_immediate(&place, &rhs, op, neg, atomic)?; this.write_immediate(*old, dest)?; // old value is returned Ok(()) } From 9b5b4dde92921275b9629a02132e2139d47a954b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 28 Oct 2023 11:05:15 +0200 Subject: [PATCH 07/13] consolidate and extend testing for _ patterns discarding the place --- ...dangling_pointer_deref_match_underscore.rs | 14 ---- .../miri/tests/pass/underscore_pattern.rs | 76 +++++++++++++++++++ ...score.stdout => underscore_pattern.stdout} | 0 .../union-uninhabited-match-underscore.rs | 17 ----- 4 files changed, 76 insertions(+), 31 deletions(-) delete mode 100644 src/tools/miri/tests/pass/dangling_pointer_deref_match_underscore.rs create mode 100644 src/tools/miri/tests/pass/underscore_pattern.rs rename src/tools/miri/tests/pass/{union-uninhabited-match-underscore.stdout => underscore_pattern.stdout} (100%) delete mode 100644 src/tools/miri/tests/pass/union-uninhabited-match-underscore.rs diff --git a/src/tools/miri/tests/pass/dangling_pointer_deref_match_underscore.rs b/src/tools/miri/tests/pass/dangling_pointer_deref_match_underscore.rs deleted file mode 100644 index c3cff1f4280f4..0000000000000 --- a/src/tools/miri/tests/pass/dangling_pointer_deref_match_underscore.rs +++ /dev/null @@ -1,14 +0,0 @@ -// A `_` binding in a match is a nop, so we do not detect that the pointer is dangling. -//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation - -fn main() { - let p = { - let b = Box::new(42); - &*b as *const i32 - }; - unsafe { - match *p { - _ => {} - } - } -} diff --git a/src/tools/miri/tests/pass/underscore_pattern.rs b/src/tools/miri/tests/pass/underscore_pattern.rs new file mode 100644 index 0000000000000..f9b42c5bc8e20 --- /dev/null +++ b/src/tools/miri/tests/pass/underscore_pattern.rs @@ -0,0 +1,76 @@ +// Various tests ensuring that underscore patterns really just construct the place, but don't check its contents. +#![feature(strict_provenance)] +use std::ptr; + +fn main() { + dangling_deref_match(); + union_uninhabited_match(); + dangling_let(); + invalid_let(); + dangling_let_type_annotation(); + invalid_let_type_annotation(); +} + +fn dangling_deref_match() { + let p = { + let b = Box::new(42); + &*b as *const i32 + }; + unsafe { + match *p { + _ => {} + } + } +} + +fn union_uninhabited_match() { + #[derive(Copy, Clone)] + enum Void {} + union Uninit { + value: T, + uninit: (), + } + unsafe { + let x: Uninit = Uninit { uninit: () }; + match x.value { + // rustc warns about un unreachable pattern, + // but is wrong in unsafe code. + #[allow(unreachable_patterns)] + _ => println!("hi from the void!"), + } + } +} + +fn dangling_let() { + unsafe { + let ptr = ptr::invalid::(0x40); + let _ = *ptr; + } +} + +fn invalid_let() { + unsafe { + let val = 3u8; + let ptr = ptr::addr_of!(val).cast::(); + let _ = *ptr; + } +} + +// Adding a type annotation used to change how MIR is generated, make sure we cover both cases. +fn dangling_let_type_annotation() { + unsafe { + let ptr = ptr::invalid::(0x40); + let _: bool = *ptr; + } +} + +fn invalid_let_type_annotation() { + unsafe { + let val = 3u8; + let ptr = ptr::addr_of!(val).cast::(); + let _: bool = *ptr; + } +} + +// FIXME: we should also test `!`, not just `bool` -- but that s currently buggy: +// https://github.com/rust-lang/rust/issues/117288 diff --git a/src/tools/miri/tests/pass/union-uninhabited-match-underscore.stdout b/src/tools/miri/tests/pass/underscore_pattern.stdout similarity index 100% rename from src/tools/miri/tests/pass/union-uninhabited-match-underscore.stdout rename to src/tools/miri/tests/pass/underscore_pattern.stdout diff --git a/src/tools/miri/tests/pass/union-uninhabited-match-underscore.rs b/src/tools/miri/tests/pass/union-uninhabited-match-underscore.rs deleted file mode 100644 index 33db9c2d347b2..0000000000000 --- a/src/tools/miri/tests/pass/union-uninhabited-match-underscore.rs +++ /dev/null @@ -1,17 +0,0 @@ -fn main() { - #[derive(Copy, Clone)] - enum Void {} - union Uninit { - value: T, - uninit: (), - } - unsafe { - let x: Uninit = Uninit { uninit: () }; - match x.value { - // rustc warns about un unreachable pattern, - // but is wrong in unsafe code. - #[allow(unreachable_patterns)] - _ => println!("hi from the void!"), - } - } -} From d17690065a7f4691926404a72c11c0694f020c66 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 28 Oct 2023 11:18:13 +0200 Subject: [PATCH 08/13] add some tests specifically for validity checks arising from match binders --- .../validity/match_binder_checks_validity1.rs | 15 +++++++++++++++ .../validity/match_binder_checks_validity1.stderr | 15 +++++++++++++++ .../validity/match_binder_checks_validity2.rs | 14 ++++++++++++++ .../validity/match_binder_checks_validity2.stderr | 15 +++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs create mode 100644 src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr create mode 100644 src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs create mode 100644 src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs new file mode 100644 index 0000000000000..6c1df45ac0eca --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.rs @@ -0,0 +1,15 @@ +fn main() { + #[derive(Copy, Clone)] + enum Void {} + union Uninit { + value: T, + uninit: (), + } + unsafe { + let x: Uninit = Uninit { uninit: () }; + match x.value { + #[allow(unreachable_patterns)] + _x => println!("hi from the void!"), //~ERROR: invalid value + } + } +} diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr new file mode 100644 index 0000000000000..c234467bddcbf --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity1.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: constructing invalid value: encountered a value of uninhabited type `main::Void` + --> $DIR/match_binder_checks_validity1.rs:LL:CC + | +LL | _x => println!("hi from the void!"), + | ^^ constructing invalid value: encountered a value of uninhabited type `main::Void` + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/match_binder_checks_validity1.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs new file mode 100644 index 0000000000000..0517263a8f5a3 --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.rs @@ -0,0 +1,14 @@ +fn main() { + #[derive(Copy, Clone)] + union Uninit { + value: T, + uninit: u8, + } + unsafe { + let x: Uninit = Uninit { uninit: 3 }; + match x.value { + #[allow(unreachable_patterns)] + _x => println!("hi from the void!"), //~ERROR: invalid value + } + } +} diff --git a/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr new file mode 100644 index 0000000000000..8af2d37d74a75 --- /dev/null +++ b/src/tools/miri/tests/fail/validity/match_binder_checks_validity2.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: constructing invalid value: encountered 0x03, but expected a boolean + --> $DIR/match_binder_checks_validity2.rs:LL:CC + | +LL | _x => println!("hi from the void!"), + | ^^ constructing invalid value: encountered 0x03, but expected a boolean + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/match_binder_checks_validity2.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + From bd81a5866d67ae56f85f3230a6ccd8435a8a7d26 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 28 Oct 2023 11:11:09 +0200 Subject: [PATCH 09/13] accept some atomic loads from read-only memory --- src/tools/miri/src/concurrency/data_race.rs | 64 ++++++++++++++----- .../concurrency/read_only_atomic_cmpxchg.rs | 2 +- .../read_only_atomic_cmpxchg.stderr | 12 ++-- .../concurrency/read_only_atomic_load.stderr | 21 ------ ...ad.rs => read_only_atomic_load_acquire.rs} | 2 +- .../read_only_atomic_load_acquire.stderr | 19 ++++++ .../read_only_atomic_load_large.rs | 18 ++++++ .../read_only_atomic_load_large.stderr | 19 ++++++ .../miri/tests/pass/atomic-readonly-load.rs | 12 ++++ 9 files changed, 121 insertions(+), 48 deletions(-) delete mode 100644 src/tools/miri/tests/fail/concurrency/read_only_atomic_load.stderr rename src/tools/miri/tests/fail/concurrency/{read_only_atomic_load.rs => read_only_atomic_load_acquire.rs} (79%) create mode 100644 src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.stderr create mode 100644 src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.rs create mode 100644 src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.stderr create mode 100644 src/tools/miri/tests/pass/atomic-readonly-load.rs diff --git a/src/tools/miri/src/concurrency/data_race.rs b/src/tools/miri/src/concurrency/data_race.rs index 294335f77dcb3..f0220d038ae5b 100644 --- a/src/tools/miri/src/concurrency/data_race.rs +++ b/src/tools/miri/src/concurrency/data_race.rs @@ -52,7 +52,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::{Idx, IndexVec}; use rustc_middle::mir; use rustc_span::Span; -use rustc_target::abi::{Align, Size}; +use rustc_target::abi::{Align, HasDataLayout, Size}; use crate::diagnostics::RacingOp; use crate::*; @@ -194,6 +194,13 @@ struct AtomicMemoryCellClocks { size: Size, } +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +enum AtomicAccessType { + Load(AtomicReadOrd), + Store, + Rmw, +} + /// Type of write operation: allocating memory /// non-atomic writes and deallocating memory /// are all treated as writes for the purpose @@ -526,7 +533,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { atomic: AtomicReadOrd, ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_ref(); - this.atomic_access_check(place)?; + this.atomic_access_check(place, AtomicAccessType::Load(atomic))?; // This will read from the last store in the modification order of this location. In case // weak memory emulation is enabled, this may not be the store we will pick to actually read from and return. // This is fine with StackedBorrow and race checks because they don't concern metadata on @@ -546,7 +553,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { atomic: AtomicWriteOrd, ) -> InterpResult<'tcx> { let this = self.eval_context_mut(); - this.atomic_access_check(dest)?; + this.atomic_access_check(dest, AtomicAccessType::Store)?; this.allow_data_races_mut(move |this| this.write_scalar(val, dest))?; this.validate_atomic_store(dest, atomic)?; @@ -568,7 +575,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { atomic: AtomicRwOrd, ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { let this = self.eval_context_mut(); - this.atomic_access_check(place)?; + this.atomic_access_check(place, AtomicAccessType::Rmw)?; let old = this.allow_data_races_mut(|this| this.read_immediate(place))?; @@ -592,7 +599,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { atomic: AtomicRwOrd, ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - this.atomic_access_check(place)?; + this.atomic_access_check(place, AtomicAccessType::Rmw)?; let old = this.allow_data_races_mut(|this| this.read_scalar(place))?; this.allow_data_races_mut(|this| this.write_scalar(new, place))?; @@ -613,7 +620,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { atomic: AtomicRwOrd, ) -> InterpResult<'tcx, ImmTy<'tcx, Provenance>> { let this = self.eval_context_mut(); - this.atomic_access_check(place)?; + this.atomic_access_check(place, AtomicAccessType::Rmw)?; let old = this.allow_data_races_mut(|this| this.read_immediate(place))?; let lt = this.wrapping_binary_op(mir::BinOp::Lt, &old, &rhs)?.to_scalar().to_bool()?; @@ -652,7 +659,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { ) -> InterpResult<'tcx, Immediate> { use rand::Rng as _; let this = self.eval_context_mut(); - this.atomic_access_check(place)?; + this.atomic_access_check(place, AtomicAccessType::Rmw)?; // Failure ordering cannot be stronger than success ordering, therefore first attempt // to read with the failure ordering and if successful then try again with the success @@ -1062,7 +1069,11 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { } /// Checks that an atomic access is legal at the given place. - fn atomic_access_check(&self, place: &MPlaceTy<'tcx, Provenance>) -> InterpResult<'tcx> { + fn atomic_access_check( + &self, + place: &MPlaceTy<'tcx, Provenance>, + access_type: AtomicAccessType, + ) -> InterpResult<'tcx> { let this = self.eval_context_ref(); // Check alignment requirements. Atomics must always be aligned to their size, // even if the type they wrap would be less aligned (e.g. AtomicU64 on 32bit must @@ -1080,15 +1091,34 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: MiriInterpCxExt<'mir, 'tcx> { .ptr_try_get_alloc_id(place.ptr()) .expect("there are no zero-sized atomic accesses"); if this.get_alloc_mutability(alloc_id)? == Mutability::Not { - // FIXME: make this prettier, once these messages have separate title/span/help messages. - throw_ub_format!( - "atomic operations cannot be performed on read-only memory\n\ - many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails \ - (and is hence nominally read-only)\n\ - some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; \ - it is possible that we could have an exception permitting this for specific kinds of loads\n\ - please report an issue at if this is a problem for you" - ); + // See if this is fine. + match access_type { + AtomicAccessType::Rmw | AtomicAccessType::Store => { + throw_ub_format!( + "atomic store and read-modify-write operations cannot be performed on read-only memory\n\ + see for more information" + ); + } + AtomicAccessType::Load(_) + if place.layout.size > this.tcx.data_layout().pointer_size() => + { + throw_ub_format!( + "large atomic load operations cannot be performed on read-only memory\n\ + these operations often have to be implemented using read-modify-write operations, which require writeable memory\n\ + see for more information" + ); + } + AtomicAccessType::Load(o) if o != AtomicReadOrd::Relaxed => { + throw_ub_format!( + "non-relaxed atomic load operations cannot be performed on read-only memory\n\ + these operations sometimes have to be implemented using read-modify-write operations, which require writeable memory\n\ + see for more information" + ); + } + _ => { + // Large relaxed loads are fine! + } + } } Ok(()) } diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.rs b/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.rs index cb6aeea665d39..88c73d14ef72b 100644 --- a/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.rs +++ b/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.rs @@ -7,5 +7,5 @@ fn main() { static X: i32 = 0; let x = &X as *const i32 as *const AtomicI32; let x = unsafe { &*x }; - x.compare_exchange(1, 2, Ordering::Relaxed, Ordering::Relaxed).unwrap_err(); //~ERROR: atomic operations cannot be performed on read-only memory + x.compare_exchange(1, 2, Ordering::Relaxed, Ordering::Relaxed).unwrap_err(); //~ERROR: cannot be performed on read-only memory } diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.stderr b/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.stderr index d51fdee0b256f..fc5982e7f94f9 100644 --- a/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.stderr +++ b/src/tools/miri/tests/fail/concurrency/read_only_atomic_cmpxchg.stderr @@ -1,14 +1,10 @@ -error: Undefined Behavior: atomic operations cannot be performed on read-only memory - many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only) - some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads - please report an issue at if this is a problem for you +error: Undefined Behavior: atomic store and read-modify-write operations cannot be performed on read-only memory + see for more information --> $DIR/read_only_atomic_cmpxchg.rs:LL:CC | LL | x.compare_exchange(1, 2, Ordering::Relaxed, Ordering::Relaxed).unwrap_err(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ atomic operations cannot be performed on read-only memory -many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only) -some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads -please report an issue at if this is a problem for you + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ atomic store and read-modify-write operations cannot be performed on read-only memory +see for more information | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load.stderr b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load.stderr deleted file mode 100644 index 17851d6b470b4..0000000000000 --- a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error: Undefined Behavior: atomic operations cannot be performed on read-only memory - many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only) - some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads - please report an issue at if this is a problem for you - --> $DIR/read_only_atomic_load.rs:LL:CC - | -LL | x.load(Ordering::Relaxed); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ atomic operations cannot be performed on read-only memory -many platforms require atomic read-modify-write instructions to be performed on writeable memory, even if the operation fails (and is hence nominally read-only) -some platforms implement (some) atomic loads via compare-exchange, which means they do not work on read-only memory; it is possible that we could have an exception permitting this for specific kinds of loads -please report an issue at if this is a problem for you - | - = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior - = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information - = note: BACKTRACE: - = note: inside `main` at $DIR/read_only_atomic_load.rs:LL:CC - -note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace - -error: aborting due to previous error - diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load.rs b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.rs similarity index 79% rename from src/tools/miri/tests/fail/concurrency/read_only_atomic_load.rs rename to src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.rs index 6e92453e3c195..af0dc2d3fd64a 100644 --- a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load.rs +++ b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.rs @@ -9,5 +9,5 @@ fn main() { let x = unsafe { &*x }; // Some targets can implement atomic loads via compare_exchange, so we cannot allow them on // read-only memory. - x.load(Ordering::Relaxed); //~ERROR: atomic operations cannot be performed on read-only memory + x.load(Ordering::Acquire); //~ERROR: cannot be performed on read-only memory } diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.stderr b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.stderr new file mode 100644 index 0000000000000..2945344877a5b --- /dev/null +++ b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_acquire.stderr @@ -0,0 +1,19 @@ +error: Undefined Behavior: non-relaxed atomic load operations cannot be performed on read-only memory + these operations sometimes have to be implemented using read-modify-write operations, which require writeable memory + see for more information + --> $DIR/read_only_atomic_load_acquire.rs:LL:CC + | +LL | x.load(Ordering::Acquire); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ non-relaxed atomic load operations cannot be performed on read-only memory +these operations sometimes have to be implemented using read-modify-write operations, which require writeable memory +see for more information + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/read_only_atomic_load_acquire.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.rs b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.rs new file mode 100644 index 0000000000000..a9a8f0f5dddda --- /dev/null +++ b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.rs @@ -0,0 +1,18 @@ +// Should not rely on the aliasing model for its failure. +//@compile-flags: -Zmiri-disable-stacked-borrows +// Needs atomic accesses larger than the pointer size +//@ignore-64bit + +use std::sync::atomic::{AtomicI64, Ordering}; + +#[repr(align(8))] +struct AlignedI64(i64); + +fn main() { + static X: AlignedI64 = AlignedI64(0); + let x = &X as *const AlignedI64 as *const AtomicI64; + let x = unsafe { &*x }; + // Some targets can implement atomic loads via compare_exchange, so we cannot allow them on + // read-only memory. + x.load(Ordering::Relaxed); //~ERROR: cannot be performed on read-only memory +} diff --git a/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.stderr b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.stderr new file mode 100644 index 0000000000000..5d8cb707f3fea --- /dev/null +++ b/src/tools/miri/tests/fail/concurrency/read_only_atomic_load_large.stderr @@ -0,0 +1,19 @@ +error: Undefined Behavior: large atomic load operations cannot be performed on read-only memory + these operations often have to be implemented using read-modify-write operations, which require writeable memory + see for more information + --> $DIR/read_only_atomic_load_large.rs:LL:CC + | +LL | x.load(Ordering::Relaxed); + | ^^^^^^^^^^^^^^^^^^^^^^^^^ large atomic load operations cannot be performed on read-only memory +these operations often have to be implemented using read-modify-write operations, which require writeable memory +see for more information + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/read_only_atomic_load_large.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/pass/atomic-readonly-load.rs b/src/tools/miri/tests/pass/atomic-readonly-load.rs new file mode 100644 index 0000000000000..8f8086b3538c6 --- /dev/null +++ b/src/tools/miri/tests/pass/atomic-readonly-load.rs @@ -0,0 +1,12 @@ +// Stacked Borrows doesn't like this. +//@compile-flags: -Zmiri-tree-borrows + +use std::sync::atomic::*; + +fn main() { + // Atomic loads from read-only memory are fine if they are relaxed and small. + static X: i32 = 0; + let x = &X as *const i32 as *const AtomicI32; + let x = unsafe { &*x }; + x.load(Ordering::Relaxed); +} From 98eb384eab9cf12d39b76689b89264b4e929f587 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 30 Oct 2023 08:23:37 +0100 Subject: [PATCH 10/13] make sure we catch UB with _ pattern in various syntactic positions --- ...angling_pointer_project_underscore_let.rs} | 0 ...ing_pointer_project_underscore_let.stderr} | 8 +++--- ..._project_underscore_let_type_annotation.rs | 12 +++++++++ ...ject_underscore_let_type_annotation.stderr | 25 +++++++++++++++++++ ...ngling_pointer_project_underscore_match.rs | 15 +++++++++++ ...ng_pointer_project_underscore_match.stderr | 25 +++++++++++++++++++ .../miri/tests/pass/underscore_pattern.rs | 17 +++++-------- .../miri/tests/pass/underscore_pattern.stdout | 1 - 8 files changed, 87 insertions(+), 16 deletions(-) rename src/tools/miri/tests/fail/dangling_pointers/{dangling_pointer_project_underscore.rs => dangling_pointer_project_underscore_let.rs} (100%) rename src/tools/miri/tests/fail/dangling_pointers/{dangling_pointer_project_underscore.stderr => dangling_pointer_project_underscore_let.stderr} (82%) create mode 100644 src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.rs create mode 100644 src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.stderr create mode 100644 src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs create mode 100644 src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr delete mode 100644 src/tools/miri/tests/pass/underscore_pattern.stdout diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore.rs b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let.rs similarity index 100% rename from src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore.rs rename to src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let.rs diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore.stderr b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let.stderr similarity index 82% rename from src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore.stderr rename to src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let.stderr index 20f3a25a0b1e7..16841626dc216 100644 --- a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore.stderr +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let.stderr @@ -1,5 +1,5 @@ error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling - --> $DIR/dangling_pointer_project_underscore.rs:LL:CC + --> $DIR/dangling_pointer_project_underscore_let.rs:LL:CC | LL | let _ = (*p).1; | ^^^^^^ out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling @@ -7,17 +7,17 @@ LL | let _ = (*p).1; = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information help: ALLOC was allocated here: - --> $DIR/dangling_pointer_project_underscore.rs:LL:CC + --> $DIR/dangling_pointer_project_underscore_let.rs:LL:CC | LL | let b = Box::new(42); | ^^^^^^^^^^^^ help: ALLOC was deallocated here: - --> $DIR/dangling_pointer_project_underscore.rs:LL:CC + --> $DIR/dangling_pointer_project_underscore_let.rs:LL:CC | LL | }; | ^ = note: BACKTRACE (of the first span): - = note: inside `main` at $DIR/dangling_pointer_project_underscore.rs:LL:CC + = note: inside `main` at $DIR/dangling_pointer_project_underscore_let.rs:LL:CC note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.rs b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.rs new file mode 100644 index 0000000000000..fc10a826c1e14 --- /dev/null +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.rs @@ -0,0 +1,12 @@ +// Make sure we find these even with many checks disabled. +//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation + +fn main() { + let p = { + let b = Box::new(42); + &*b as *const i32 as *const (u8, u8, u8, u8) + }; + unsafe { + let _: u8 = (*p).1; //~ ERROR: out-of-bounds pointer arithmetic + } +} diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.stderr b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.stderr new file mode 100644 index 0000000000000..0cdb6639a2f8d --- /dev/null +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_let_type_annotation.stderr @@ -0,0 +1,25 @@ +error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling + --> $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC + | +LL | let _: u8 = (*p).1; + | ^^^^^^ out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information +help: ALLOC was allocated here: + --> $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC + | +LL | let b = Box::new(42); + | ^^^^^^^^^^^^ +help: ALLOC was deallocated here: + --> $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC + | +LL | }; + | ^ + = note: BACKTRACE (of the first span): + = note: inside `main` at $DIR/dangling_pointer_project_underscore_let_type_annotation.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs new file mode 100644 index 0000000000000..8541da848578b --- /dev/null +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.rs @@ -0,0 +1,15 @@ +// Make sure we find these even with many checks disabled. +//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation + +fn main() { + let p = { + let b = Box::new(42); + &*b as *const i32 as *const (u8, u8, u8, u8) + }; + unsafe { + match (*p).1 { + //~^ ERROR: out-of-bounds pointer arithmetic + _ => {} + } + } +} diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr new file mode 100644 index 0000000000000..625a7b5f60b6d --- /dev/null +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_pointer_project_underscore_match.stderr @@ -0,0 +1,25 @@ +error: Undefined Behavior: out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling + --> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + | +LL | match (*p).1 { + | ^^^^^^ out-of-bounds pointer arithmetic: ALLOC has been freed, so this pointer is dangling + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information +help: ALLOC was allocated here: + --> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + | +LL | let b = Box::new(42); + | ^^^^^^^^^^^^ +help: ALLOC was deallocated here: + --> $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + | +LL | }; + | ^ + = note: BACKTRACE (of the first span): + = note: inside `main` at $DIR/dangling_pointer_project_underscore_match.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/src/tools/miri/tests/pass/underscore_pattern.rs b/src/tools/miri/tests/pass/underscore_pattern.rs index f9b42c5bc8e20..b0e85bc1bb038 100644 --- a/src/tools/miri/tests/pass/underscore_pattern.rs +++ b/src/tools/miri/tests/pass/underscore_pattern.rs @@ -3,15 +3,15 @@ use std::ptr; fn main() { - dangling_deref_match(); - union_uninhabited_match(); + dangling_match(); + invalid_match(); dangling_let(); invalid_let(); dangling_let_type_annotation(); invalid_let_type_annotation(); } -fn dangling_deref_match() { +fn dangling_match() { let p = { let b = Box::new(42); &*b as *const i32 @@ -23,20 +23,15 @@ fn dangling_deref_match() { } } -fn union_uninhabited_match() { - #[derive(Copy, Clone)] - enum Void {} +fn invalid_match() { union Uninit { value: T, uninit: (), } unsafe { - let x: Uninit = Uninit { uninit: () }; + let x: Uninit = Uninit { uninit: () }; match x.value { - // rustc warns about un unreachable pattern, - // but is wrong in unsafe code. - #[allow(unreachable_patterns)] - _ => println!("hi from the void!"), + _ => {} } } } diff --git a/src/tools/miri/tests/pass/underscore_pattern.stdout b/src/tools/miri/tests/pass/underscore_pattern.stdout deleted file mode 100644 index ff731696f01a5..0000000000000 --- a/src/tools/miri/tests/pass/underscore_pattern.stdout +++ /dev/null @@ -1 +0,0 @@ -hi from the void! From 4c3eb37a51c45f650b059fbbab6c2bf1ecdf0bb4 Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Thu, 2 Nov 2023 05:15:52 +0000 Subject: [PATCH 11/13] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index 6ded1ea1c5da3..e2cc39a896d1e 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -20952db40d5220e8a15c2e569ae480877bbc8417 +722b3eeb72b6bca6c38bbcbda57179f073f23431 From 99417f2146f385e540ce277b3eef6dde9f3cabd9 Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Sat, 4 Nov 2023 04:59:51 +0000 Subject: [PATCH 12/13] Preparing for merge from rustc --- src/tools/miri/rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/miri/rust-version b/src/tools/miri/rust-version index e2cc39a896d1e..2beb3bfef9e5f 100644 --- a/src/tools/miri/rust-version +++ b/src/tools/miri/rust-version @@ -1 +1 @@ -722b3eeb72b6bca6c38bbcbda57179f073f23431 +3aaa0f57b7b877ef58532a8de075d1e5a79142bf From 5b187039e4afe41221bb48b082517cc1d5b973e1 Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Sat, 4 Nov 2023 05:10:30 +0000 Subject: [PATCH 13/13] fmt --- src/tools/miri/src/diagnostics.rs | 2 +- src/tools/miri/src/eval.rs | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/tools/miri/src/diagnostics.rs b/src/tools/miri/src/diagnostics.rs index 7bd5b4f2a9233..c146c719ed3b7 100644 --- a/src/tools/miri/src/diagnostics.rs +++ b/src/tools/miri/src/diagnostics.rs @@ -4,7 +4,7 @@ use std::num::NonZeroU64; use log::trace; use rustc_errors::DiagnosticMessage; -use rustc_span::{DUMMY_SP, SpanData, Symbol}; +use rustc_span::{SpanData, Symbol, DUMMY_SP}; use rustc_target::abi::{Align, Size}; use crate::borrow_tracker::stacked_borrows::diagnostics::TagHistory; diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs index a3193dfe20ef3..5b785c0143e4d 100644 --- a/src/tools/miri/src/eval.rs +++ b/src/tools/miri/src/eval.rs @@ -265,12 +265,8 @@ pub fn create_ecx<'mir, 'tcx: 'mir>( ) -> InterpResult<'tcx, InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>> { let param_env = ty::ParamEnv::reveal_all(); let layout_cx = LayoutCx { tcx, param_env }; - let mut ecx = InterpCx::new( - tcx, - rustc_span::DUMMY_SP, - param_env, - MiriMachine::new(config, layout_cx), - ); + let mut ecx = + InterpCx::new(tcx, rustc_span::DUMMY_SP, param_env, MiriMachine::new(config, layout_cx)); // Some parts of initialization require a full `InterpCx`. MiriMachine::late_init(&mut ecx, config, {