1
Fork 0

remove enforce_number_init machine hook that Miri no longer needs

This commit is contained in:
Ralf Jung 2022-07-26 21:45:47 -04:00
parent 9d604f301b
commit da13935ecc
2 changed files with 8 additions and 24 deletions

View file

@ -132,9 +132,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Whether to enforce the validity invariant /// Whether to enforce the validity invariant
fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool; fn enforce_validity(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
/// Whether to enforce integers and floats being initialized.
fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
/// Whether function calls should be [ABI](CallAbi)-checked. /// Whether function calls should be [ABI](CallAbi)-checked.
fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool { fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
true true
@ -442,11 +439,6 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
false false
} }
#[inline(always)]
fn enforce_number_init(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
true
}
#[inline(always)] #[inline(always)]
fn checked_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool { fn checked_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
true true

View file

@ -509,14 +509,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
let value = self.read_scalar(value)?; let value = self.read_scalar(value)?;
// NOTE: Keep this in sync with the array optimization for int/float // NOTE: Keep this in sync with the array optimization for int/float
// types below! // types below!
if M::enforce_number_init(self.ecx) { try_validation!(
try_validation!( value.check_init(),
value.check_init(), self.path,
self.path, err_ub!(InvalidUninitBytes(..)) =>
err_ub!(InvalidUninitBytes(..)) => { "{:x}", value } expected { "initialized bytes" }
{ "{:x}", value } expected { "initialized bytes" } );
);
}
// As a special exception we *do* match on a `Scalar` here, since we truly want // As a special exception we *do* match on a `Scalar` here, since we truly want
// to know its underlying representation (and *not* cast it to an integer). // to know its underlying representation (and *not* cast it to an integer).
let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..))); let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..)));
@ -621,13 +619,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// i.e. that we go over the `check_init` below. // i.e. that we go over the `check_init` below.
let size = scalar_layout.size(self.ecx); let size = scalar_layout.size(self.ecx);
let is_full_range = match scalar_layout { let is_full_range = match scalar_layout {
ScalarAbi::Initialized { .. } => { ScalarAbi::Initialized { .. } => false, // not "full" since uninit is not valid
if M::enforce_number_init(self.ecx) {
false // not "full" since uninit is not accepted
} else {
scalar_layout.is_always_valid(self.ecx)
}
}
ScalarAbi::Union { .. } => true, ScalarAbi::Union { .. } => true,
}; };
if is_full_range { if is_full_range {
@ -903,7 +895,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
match alloc.check_bytes( match alloc.check_bytes(
alloc_range(Size::ZERO, size), alloc_range(Size::ZERO, size),
/*allow_uninit*/ !M::enforce_number_init(self.ecx), /*allow_uninit*/ false,
/*allow_ptr*/ false, /*allow_ptr*/ false,
) { ) {
// In the happy case, we needn't check anything else. // In the happy case, we needn't check anything else.