Skip to content

Commit 69576fc

Browse files
committed
make ENFORCE_VALIDITY a function
miri needs this extra flexibility
1 parent 3272c98 commit 69576fc

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/librustc_mir/const_eval.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ impl<'a, 'mir, 'tcx> interpret::Machine<'a, 'mir, 'tcx>
343343
type MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation<()>)>;
344344

345345
const STATIC_KIND: Option<!> = None; // no copying of statics allowed
346-
const ENFORCE_VALIDITY: bool = false; // for now, we don't
346+
347+
#[inline(always)]
348+
fn enforce_validity(_ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool {
349+
false // for now, we don't enforce validity
350+
}
347351

348352
fn find_fn(
349353
ecx: &mut EvalContext<'a, 'mir, 'tcx, Self>,

src/librustc_mir/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
524524
}
525525
// Validate the return value.
526526
if let Some(return_place) = frame.return_place {
527-
if M::ENFORCE_VALIDITY {
527+
if M::enforce_validity(self) {
528528
// Data got changed, better make sure it matches the type!
529529
// It is still possible that the return place held invalid data while
530530
// the function is running, but that's okay because nobody could have

src/librustc_mir/interpret/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub trait Machine<'a, 'mir, 'tcx>: Sized {
8686
const STATIC_KIND: Option<Self::MemoryKinds>;
8787

8888
/// Whether to enforce the validity invariant
89-
const ENFORCE_VALIDITY: bool;
89+
fn enforce_validity(ecx: &EvalContext<'a, 'mir, 'tcx, Self>) -> bool;
9090

9191
/// Called before a basic block terminator is executed.
9292
/// You can use this to detect endlessly running programs.

src/librustc_mir/interpret/place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ where
607607
) -> EvalResult<'tcx> {
608608
self.write_value_no_validate(src_val, dest)?;
609609

610-
if M::ENFORCE_VALIDITY {
610+
if M::enforce_validity(self) {
611611
// Data got changed, better make sure it matches the type!
612612
self.validate_operand(self.place_to_op(dest)?, &mut vec![], None, /*const_mode*/false)?;
613613
}
@@ -729,7 +729,7 @@ where
729729
) -> EvalResult<'tcx> {
730730
self.copy_op_no_validate(src, dest)?;
731731

732-
if M::ENFORCE_VALIDITY {
732+
if M::enforce_validity(self) {
733733
// Data got changed, better make sure it matches the type!
734734
self.validate_operand(self.place_to_op(dest)?, &mut vec![], None, /*const_mode*/false)?;
735735
}
@@ -807,7 +807,7 @@ where
807807
PlaceTy::from(MPlaceTy { mplace: *dest, layout: src.layout }),
808808
)?;
809809

810-
if M::ENFORCE_VALIDITY {
810+
if M::enforce_validity(self) {
811811
// Data got changed, better make sure it matches the type!
812812
self.validate_operand(dest.into(), &mut vec![], None, /*const_mode*/false)?;
813813
}

0 commit comments

Comments
 (0)