Skip to content

Commit 665a7e8

Browse files
committed
remove some provenance-related machine hooks that Miri no longer needs
1 parent 47ba935 commit 665a7e8

File tree

4 files changed

+17
-46
lines changed

4 files changed

+17
-46
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

-23
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
135135
/// Whether to enforce integers and floats being initialized.
136136
fn enforce_number_init(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
137137

138-
/// Whether to enforce integers and floats not having provenance.
139-
fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
140-
141138
/// Whether function calls should be [ABI](CallAbi)-checked.
142139
fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
143140
true
@@ -300,13 +297,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
300297
addr: u64,
301298
) -> InterpResult<'tcx, Pointer<Option<Self::Provenance>>>;
302299

303-
/// Hook for returning a pointer from a transmute-like operation on an addr.
304-
/// This is only needed to support Miri's (unsound) "allow-ptr-int-transmute" flag.
305-
fn ptr_from_addr_transmute(
306-
ecx: &InterpCx<'mir, 'tcx, Self>,
307-
addr: u64,
308-
) -> Pointer<Option<Self::Provenance>>;
309-
310300
/// Marks a pointer as exposed, allowing it's provenance
311301
/// to be recovered. "Pointer-to-int cast"
312302
fn expose_ptr(
@@ -469,11 +459,6 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
469459
true
470460
}
471461

472-
#[inline(always)]
473-
fn enforce_number_no_provenance(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
474-
true
475-
}
476-
477462
#[inline(always)]
478463
fn checked_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
479464
true
@@ -518,14 +503,6 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
518503
ptr
519504
}
520505

521-
#[inline(always)]
522-
fn ptr_from_addr_transmute(
523-
_ecx: &InterpCx<$mir, $tcx, Self>,
524-
addr: u64,
525-
) -> Pointer<Option<AllocId>> {
526-
Pointer::from_addr(addr)
527-
}
528-
529506
#[inline(always)]
530507
fn ptr_from_addr_cast(
531508
_ecx: &InterpCx<$mir, $tcx, Self>,

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11861186
Err(ptr) => ptr.into(),
11871187
Ok(bits) => {
11881188
let addr = u64::try_from(bits).unwrap();
1189-
M::ptr_from_addr_transmute(&self, addr)
1189+
Pointer::from_addr(addr)
11901190
}
11911191
},
11921192
)

compiler/rustc_const_eval/src/interpret/operand.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -363,17 +363,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
363363
Abi::Scalar(s) if force => Some(s.primitive()),
364364
_ => None,
365365
};
366-
let read_provenance = |s: abi::Primitive, size| {
367-
// Should be just `s.is_ptr()`, but we support a Miri flag that accepts more
368-
// questionable ptr-int transmutes.
369-
let number_may_have_provenance = !M::enforce_number_no_provenance(self);
370-
s.is_ptr() || (number_may_have_provenance && size == self.pointer_size())
371-
};
372366
if let Some(s) = scalar_layout {
373367
let size = s.size(self);
374368
assert_eq!(size, mplace.layout.size, "abi::Scalar size does not match layout size");
375-
let scalar =
376-
alloc.read_scalar(alloc_range(Size::ZERO, size), read_provenance(s, size))?;
369+
let scalar = alloc
370+
.read_scalar(alloc_range(Size::ZERO, size), /*read_provenance*/ s.is_ptr())?;
377371
return Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout }));
378372
}
379373
let scalar_pair_layout = match mplace.layout.abi {
@@ -391,10 +385,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
391385
let (a_size, b_size) = (a.size(self), b.size(self));
392386
let b_offset = a_size.align_to(b.align(self).abi);
393387
assert!(b_offset.bytes() > 0); // in `operand_field` we use the offset to tell apart the fields
394-
let a_val =
395-
alloc.read_scalar(alloc_range(Size::ZERO, a_size), read_provenance(a, a_size))?;
396-
let b_val =
397-
alloc.read_scalar(alloc_range(b_offset, b_size), read_provenance(b, b_size))?;
388+
let a_val = alloc.read_scalar(
389+
alloc_range(Size::ZERO, a_size),
390+
/*read_provenance*/ a.is_ptr(),
391+
)?;
392+
let b_val = alloc
393+
.read_scalar(alloc_range(b_offset, b_size), /*read_provenance*/ b.is_ptr())?;
398394
return Ok(Some(ImmTy {
399395
imm: Immediate::ScalarPair(a_val, b_val),
400396
layout: mplace.layout,

compiler/rustc_const_eval/src/interpret/validity.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -517,15 +517,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
517517
{ "{:x}", value } expected { "initialized bytes" }
518518
);
519519
}
520-
if M::enforce_number_no_provenance(self.ecx) {
521-
// As a special exception we *do* match on a `Scalar` here, since we truly want
522-
// to know its underlying representation (and *not* cast it to an integer).
523-
let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..)));
524-
if is_ptr {
525-
throw_validation_failure!(self.path,
526-
{ "{:x}", value } expected { "plain (non-pointer) bytes" }
527-
)
528-
}
520+
// As a special exception we *do* match on a `Scalar` here, since we truly want
521+
// to know its underlying representation (and *not* cast it to an integer).
522+
let is_ptr = value.check_init().map_or(false, |v| matches!(v, Scalar::Ptr(..)));
523+
if is_ptr {
524+
throw_validation_failure!(self.path,
525+
{ "{:x}", value } expected { "plain (non-pointer) bytes" }
526+
)
529527
}
530528
Ok(true)
531529
}
@@ -906,7 +904,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
906904
match alloc.check_bytes(
907905
alloc_range(Size::ZERO, size),
908906
/*allow_uninit*/ !M::enforce_number_init(self.ecx),
909-
/*allow_ptr*/ !M::enforce_number_no_provenance(self.ecx),
907+
/*allow_ptr*/ false,
910908
) {
911909
// In the happy case, we needn't check anything else.
912910
Ok(()) => {}

0 commit comments

Comments
 (0)