Skip to content

Commit c49cbd0

Browse files
authored
Rollup merge of rust-lang#152756 - RalfJung:miri-recursive-box, r=Kivooeo
Miri: recursive validity: also recurse into Boxes Now that rust-lang#97270 is fixed, the recursive validity mode for Miri can recuse into Boxes without exploding everywhere.
2 parents 207cda5 + f542160 commit c49cbd0

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,13 +647,8 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
647647
}
648648
} else {
649649
// This is not CTFE, so it's Miri with recursive checking.
650-
// FIXME: we do *not* check behind boxes, since creating a new box first creates it uninitialized
651-
// and then puts the value in there, so briefly we have a box with uninit contents.
652-
// FIXME: should we also skip `UnsafeCell` behind shared references? Currently that is not
650+
// FIXME: should we also `UnsafeCell` behind shared references? Currently that is not
653651
// needed since validation reads bypass Stacked Borrows and data race checks.
654-
if matches!(ptr_kind, PointerKind::Box) {
655-
return interp_ok(());
656-
}
657652
}
658653
let path = &self.path;
659654
ref_tracking.track(place, || {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@compile-flags: -Zmiri-recursive-validation
2+
3+
fn main() {
4+
let x = 3u8;
5+
let xref = &x;
6+
let xref_wrong_type: Box<bool> = unsafe { std::mem::transmute(xref) }; //~ERROR: encountered 0x03, but expected a boolean
7+
let _val = *xref_wrong_type;
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: Undefined Behavior: constructing invalid value at .<deref>: encountered 0x03, but expected a boolean
2+
--> tests/fail/validity/recursive-validity-box-bool.rs:LL:CC
3+
|
4+
LL | let xref_wrong_type: Box<bool> = unsafe { std::mem::transmute(xref) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
6+
|
7+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
8+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
9+
10+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)