Skip to content

Commit c75f23d

Browse files
committed
make Stacked Borrows retags act like data races
1 parent 528935d commit c75f23d

32 files changed

+164
-45
lines changed

src/stacked_borrows/mod.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,8 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
874874
// We need a frozen-sensitive reborrow.
875875
// We have to use shared references to alloc/memory_extra here since
876876
// `visit_freeze_sensitive` needs to access the global state.
877-
let extra = this.get_alloc_extra(alloc_id)?;
878-
let mut stacked_borrows = extra
877+
let alloc_extra = this.get_alloc_extra(alloc_id)?;
878+
let mut stacked_borrows = alloc_extra
879879
.stacked_borrows
880880
.as_ref()
881881
.expect("we should have Stacked Borrows data")
@@ -910,7 +910,16 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
910910
);
911911
stacked_borrows.for_each(range, dcx, |stack, dcx, exposed_tags| {
912912
stack.grant(orig_tag, item, access, &global, dcx, exposed_tags)
913-
})
913+
})?;
914+
drop(global);
915+
if let Some(access) = access {
916+
assert!(access == AccessKind::Read);
917+
// Make sure the data race model also knows about this.
918+
if let Some(data_race) = alloc_extra.data_race.as_ref() {
919+
data_race.read(alloc_id, range, &this.machine)?;
920+
}
921+
}
922+
Ok(())
914923
})?;
915924
return Ok(Some(alloc_id));
916925
}
@@ -938,6 +947,14 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
938947
stacked_borrows.for_each(range, dcx, |stack, dcx, exposed_tags| {
939948
stack.grant(orig_tag, item, access, &global, dcx, exposed_tags)
940949
})?;
950+
drop(global);
951+
if let Some(access) = access {
952+
assert!(access == AccessKind::Write);
953+
// Make sure the data race model also knows about this.
954+
if let Some(data_race) = alloc_extra.data_race.as_mut() {
955+
data_race.write(alloc_id, range, machine)?;
956+
}
957+
}
941958

942959
Ok(Some(alloc_id))
943960
}

tests/fail/data_race/alloc_read_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
1+
//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
22
#![feature(new_uninit)]
33

44
use std::mem::MaybeUninit;

tests/fail/data_race/alloc_write_race.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0
1+
//@compile-flags: -Zmiri-disable-weak-memory-emulation -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
22
#![feature(new_uninit)]
33

44
use std::ptr::null_mut;

tests/fail/data_race/atomic_read_na_write_race1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::sync::atomic::{AtomicUsize, Ordering};
55
use std::thread::spawn;

tests/fail/data_race/atomic_read_na_write_race2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::sync::atomic::AtomicUsize;
55
use std::sync::atomic::Ordering;

tests/fail/data_race/atomic_write_na_read_race1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::sync::atomic::AtomicUsize;
55
use std::sync::atomic::Ordering;

tests/fail/data_race/atomic_write_na_read_race2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::sync::atomic::{AtomicUsize, Ordering};
55
use std::thread::spawn;

tests/fail/data_race/atomic_write_na_write_race1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::sync::atomic::{AtomicUsize, Ordering};
55
use std::thread::spawn;

tests/fail/data_race/atomic_write_na_write_race2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::sync::atomic::AtomicUsize;
55
use std::sync::atomic::Ordering;

tests/fail/data_race/dangling_thread_async_race.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// We want to control preemption here.
2-
//@compile-flags: -Zmiri-disable-isolation -Zmiri-preemption-rate=0
1+
// We want to control preemption here. Stacked borrows interferes by having its own accesses.
2+
//@compile-flags: -Zmiri-preemption-rate=0 -Zmiri-disable-stacked-borrows
33

44
use std::mem;
55
use std::thread::{sleep, spawn};

0 commit comments

Comments
 (0)