Skip to content

Commit 20e8ac9

Browse files
committed
Auto merge of #3479 - rust-lang:rustup-2024-04-17, r=RalfJung
Automatic Rustup
2 parents 2321476 + 3f2d17c commit 20e8ac9

File tree

14 files changed

+72
-26
lines changed

14 files changed

+72
-26
lines changed

cargo-miri/src/phases.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,11 @@ pub fn phase_rustc(mut args: impl Iterator<Item = String>, phase: RustcPhase) {
412412
// Arguments are treated very differently depending on whether this crate is
413413
// for interpretation by Miri, or for use by a build script / proc macro.
414414
if target_crate {
415-
// Set the sysroot.
416-
cmd.arg("--sysroot").arg(env::var_os("MIRI_SYSROOT").unwrap());
415+
if phase != RustcPhase::Setup {
416+
// Set the sysroot -- except during setup, where we don't have an existing sysroot yet
417+
// and where the bootstrap wrapper adds its own `--sysroot` flag so we can't set ours.
418+
cmd.arg("--sysroot").arg(env::var_os("MIRI_SYSROOT").unwrap());
419+
}
417420

418421
// Forward arguments, but patched.
419422
let emit_flag = "--emit";
@@ -578,9 +581,9 @@ pub fn phase_runner(mut binary_args: impl Iterator<Item = String>, phase: Runner
578581
}
579582

580583
if phase != RunnerPhase::Rustdoc {
581-
// Set the sysroot. Not necessary in rustdoc, where we already set the sysroot when invoking
582-
// rustdoc itself, which will forward that flag when invoking rustc (i.e., us), so the flag
583-
// is present in `info.args`.
584+
// Set the sysroot. Not necessary in rustdoc, where we already set the sysroot in
585+
// `phase_rustdoc`. rustdoc will forward that flag when invoking rustc (i.e., us), so the
586+
// flag is present in `info.args`.
584587
cmd.arg("--sysroot").arg(env::var_os("MIRI_SYSROOT").unwrap());
585588
}
586589
// Forward rustc arguments.

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
63f70b3d104e20289a1a0df82747066c3d85b9a1
1+
803e33a4460c82581bd01d4008d0f44aef1ddfe8

src/borrow_tracker/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl GlobalStateInner {
260260
&mut self,
261261
id: AllocId,
262262
alloc_size: Size,
263-
kind: MemoryKind<machine::MiriMemoryKind>,
263+
kind: MemoryKind,
264264
machine: &MiriMachine<'_, '_>,
265265
) -> AllocState {
266266
match self.borrow_tracker_method {

src/borrow_tracker/stacked_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl Stacks {
509509
id: AllocId,
510510
size: Size,
511511
state: &mut GlobalStateInner,
512-
kind: MemoryKind<MiriMemoryKind>,
512+
kind: MemoryKind,
513513
machine: &MiriMachine<'_, '_>,
514514
) -> Self {
515515
let (base_tag, perm) = match kind {

src/borrow_tracker/tree_borrows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'tcx> Tree {
3434
id: AllocId,
3535
size: Size,
3636
state: &mut GlobalStateInner,
37-
_kind: MemoryKind<machine::MiriMemoryKind>,
37+
_kind: MemoryKind,
3838
machine: &MiriMachine<'_, 'tcx>,
3939
) -> Self {
4040
let tag = state.base_ptr_tag(id, machine); // Fresh tag for the root

src/concurrency/data_race.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ impl VClockAlloc {
844844
global: &GlobalState,
845845
thread_mgr: &ThreadManager<'_, '_>,
846846
len: Size,
847-
kind: MemoryKind<MiriMemoryKind>,
847+
kind: MemoryKind,
848848
current_span: Span,
849849
) -> VClockAlloc {
850850
let (alloc_timestamp, alloc_index) = match kind {

src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub enum NonHaltingDiagnostic {
115115
/// This `Item` was popped from the borrow stack. The string explains the reason.
116116
PoppedPointerTag(Item, String),
117117
CreatedCallId(CallId),
118-
CreatedAlloc(AllocId, Size, Align, MemoryKind<MiriMemoryKind>),
118+
CreatedAlloc(AllocId, Size, Align, MemoryKind),
119119
FreedAlloc(AllocId),
120120
AccessedAlloc(AllocId, AccessKind),
121121
RejectedIsolatedOp(String),
@@ -447,7 +447,7 @@ pub fn report_error<'tcx, 'mir>(
447447

448448
pub fn report_leaks<'mir, 'tcx>(
449449
ecx: &InterpCx<'mir, 'tcx, MiriMachine<'mir, 'tcx>>,
450-
leaks: Vec<(AllocId, MemoryKind<MiriMemoryKind>, Allocation<Provenance, AllocExtra<'tcx>>)>,
450+
leaks: Vec<(AllocId, MemoryKind, Allocation<Provenance, AllocExtra<'tcx>>)>,
451451
) {
452452
let mut any_pruned = false;
453453
for (id, kind, mut alloc) in leaks {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub use crate::eval::{
128128
};
129129
pub use crate::helpers::{AccessKind, EvalContextExt as _};
130130
pub use crate::machine::{
131-
AllocExtra, FrameExtra, MiriInterpCx, MiriInterpCxExt, MiriMachine, MiriMemoryKind,
131+
AllocExtra, FrameExtra, MemoryKind, MiriInterpCx, MiriInterpCxExt, MiriMachine, MiriMemoryKind,
132132
PrimitiveLayouts, Provenance, ProvenanceExtra,
133133
};
134134
pub use crate::mono_hash_map::MonoHashMap;

src/machine.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ pub enum MiriMemoryKind {
135135
Mmap,
136136
}
137137

138-
impl From<MiriMemoryKind> for MemoryKind<MiriMemoryKind> {
138+
impl From<MiriMemoryKind> for MemoryKind {
139139
#[inline(always)]
140-
fn from(kind: MiriMemoryKind) -> MemoryKind<MiriMemoryKind> {
140+
fn from(kind: MiriMemoryKind) -> MemoryKind {
141141
MemoryKind::Machine(kind)
142142
}
143143
}
@@ -185,6 +185,8 @@ impl fmt::Display for MiriMemoryKind {
185185
}
186186
}
187187

188+
pub type MemoryKind = interpret::MemoryKind<MiriMemoryKind>;
189+
188190
/// Pointer provenance.
189191
#[derive(Clone, Copy)]
190192
pub enum Provenance {
@@ -863,10 +865,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
863865
type ProvenanceExtra = ProvenanceExtra;
864866
type Bytes = Box<[u8]>;
865867

866-
type MemoryMap = MonoHashMap<
867-
AllocId,
868-
(MemoryKind<MiriMemoryKind>, Allocation<Provenance, Self::AllocExtra, Self::Bytes>),
869-
>;
868+
type MemoryMap =
869+
MonoHashMap<AllocId, (MemoryKind, Allocation<Provenance, Self::AllocExtra, Self::Bytes>)>;
870870

871871
const GLOBAL_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Global);
872872

@@ -1088,7 +1088,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
10881088
ecx: &MiriInterpCx<'mir, 'tcx>,
10891089
id: AllocId,
10901090
alloc: Cow<'b, Allocation>,
1091-
kind: Option<MemoryKind<Self::MemoryKind>>,
1091+
kind: Option<MemoryKind>,
10921092
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra>>> {
10931093
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
10941094
if ecx.machine.tracked_alloc_ids.contains(&id) {
@@ -1280,6 +1280,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
12801280
(alloc_id, prove_extra): (AllocId, Self::ProvenanceExtra),
12811281
size: Size,
12821282
align: Align,
1283+
_kind: MemoryKind,
12831284
) -> InterpResult<'tcx> {
12841285
if machine.tracked_alloc_ids.contains(&alloc_id) {
12851286
machine.emit_diagnostic(NonHaltingDiagnostic::FreedAlloc(alloc_id));

src/shims/os_str.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
137137
fn alloc_os_str_as_c_str(
138138
&mut self,
139139
os_str: &OsStr,
140-
memkind: MemoryKind<MiriMemoryKind>,
140+
memkind: MemoryKind,
141141
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
142142
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0` terminator.
143143
let this = self.eval_context_mut();
@@ -153,7 +153,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
153153
fn alloc_os_str_as_wide_str(
154154
&mut self,
155155
os_str: &OsStr,
156-
memkind: MemoryKind<MiriMemoryKind>,
156+
memkind: MemoryKind,
157157
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
158158
let size = u64::try_from(os_str.len()).unwrap().checked_add(1).unwrap(); // Make space for `0x0000` terminator.
159159
let this = self.eval_context_mut();
@@ -230,7 +230,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
230230
fn alloc_path_as_c_str(
231231
&mut self,
232232
path: &Path,
233-
memkind: MemoryKind<MiriMemoryKind>,
233+
memkind: MemoryKind,
234234
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
235235
let this = self.eval_context_mut();
236236
let os_str =
@@ -243,7 +243,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
243243
fn alloc_path_as_wide_str(
244244
&mut self,
245245
path: &Path,
246-
memkind: MemoryKind<MiriMemoryKind>,
246+
memkind: MemoryKind,
247247
) -> InterpResult<'tcx, Pointer<Option<Provenance>>> {
248248
let this = self.eval_context_mut();
249249
let os_str =

tests/fail/both_borrows/newtype_pair_retagging.stack.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
9-
help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
9+
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1010
--> $DIR/newtype_pair_retagging.rs:LL:CC
1111
|
1212
LL | let ptr = Box::into_raw(Box::new(0i32));

tests/fail/both_borrows/newtype_retagging.stack.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | Box(unsafe { Unique::new_unchecked(raw) }, alloc)
66
|
77
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
88
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
9-
help: <TAG> was created by a Unique retag at offsets [0x0..0x4]
9+
help: <TAG> was created by a SharedReadWrite retag at offsets [0x0..0x4]
1010
--> $DIR/newtype_retagging.rs:LL:CC
1111
|
1212
LL | let ptr = Box::into_raw(Box::new(0i32));

tests/pass/issues/issue-miri-3473.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@revisions: stack tree
2+
//@[tree]compile-flags: -Zmiri-tree-borrows
3+
use std::cell::UnsafeCell;
4+
5+
#[repr(C)]
6+
#[derive(Default)]
7+
struct Node {
8+
_meta: UnsafeCell<usize>,
9+
value: usize,
10+
}
11+
12+
impl Node {
13+
fn value(&self) -> &usize {
14+
&self.value
15+
}
16+
}
17+
18+
/// This used to cause Stacked Borrows errors because of trouble around conversion
19+
/// from Box to raw pointer.
20+
fn main() {
21+
unsafe {
22+
let a = Box::into_raw(Box::new(Node::default()));
23+
let ptr = &*a;
24+
*UnsafeCell::raw_get(a.cast::<UnsafeCell<usize>>()) = 2;
25+
assert_eq!(*ptr.value(), 0);
26+
drop(Box::from_raw(a));
27+
}
28+
}

tests/pass/stacked-borrows/stacked-borrows.rs

+14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fn main() {
2020
wide_raw_ptr_in_tuple();
2121
not_unpin_not_protected();
2222
write_does_not_invalidate_all_aliases();
23+
box_into_raw_allows_interior_mutable_alias();
2324
}
2425

2526
// Make sure that reading from an `&mut` does, like reborrowing to `&`,
@@ -263,3 +264,16 @@ fn write_does_not_invalidate_all_aliases() {
263264
other::lib2();
264265
assert_eq!(*x, 1337); // oops, the value changed! I guess not all pointers were invalidated
265266
}
267+
268+
fn box_into_raw_allows_interior_mutable_alias() {
269+
unsafe {
270+
let b = Box::new(std::cell::Cell::new(42));
271+
let raw = Box::into_raw(b);
272+
let c = &*raw;
273+
let d = raw.cast::<i32>(); // bypassing `Cell` -- only okay in Miri tests
274+
// `c` and `d` should permit arbitrary aliasing with each other now.
275+
*d = 1;
276+
c.set(2);
277+
drop(Box::from_raw(raw));
278+
}
279+
}

0 commit comments

Comments
 (0)