Skip to content

Commit 9e4a948

Browse files
committed
Auto merge of #124040 - GuillaumeGomez:rollup-hrrvsgh, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #123673 (Don't ICE for kind mismatches during error rendering) - #123675 (Taint const qualifs if a static is referenced that didn't pass wfcheck) - #123975 (Port the 2 `rust-lld` run-make tests to `rmake`) - #124000 (Use `/* value */` as a placeholder) - #124013 (Box::into_raw: make Miri understand that this is a box-to-raw cast) - #124027 (Prefer identity equality over equating types during coercion.) - #124036 (Remove `default_hidden_visibility: false` from wasm targets) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 34c4db1 + 0a45d7c commit 9e4a948

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

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

+12
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,14 @@ 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() { unsafe {
269+
let b = Box::new(std::cell::Cell::new(42));
270+
let raw = Box::into_raw(b);
271+
let c = &*raw;
272+
let d = raw.cast::<i32>(); // bypassing `Cell` -- only okay in Miri tests
273+
// `c` and `d` should permit arbitrary aliasing with each other now.
274+
*d = 1;
275+
c.set(2);
276+
drop(Box::from_raw(raw));
277+
} }

0 commit comments

Comments
 (0)