Skip to content

Commit 842bbd2

Browse files
committed
make Memory::get_fn take a Scalar like most of the Memory API surface
1 parent b4be08a commit 842bbd2

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

src/librustc_mir/interpret/memory.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
586586

587587
pub fn get_fn(
588588
&self,
589-
ptr: Pointer<M::PointerTag>,
589+
ptr: Scalar<M::PointerTag>,
590590
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
591+
let ptr = self.force_ptr(ptr)?; // We definitely need a pointer value.
591592
if ptr.offset.bytes() != 0 {
592593
return err!(InvalidFunctionPointer);
593594
}

src/librustc_mir/interpret/terminator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7979
let (fn_val, abi) = match func.layout.ty.sty {
8080
ty::FnPtr(sig) => {
8181
let caller_abi = sig.abi();
82-
let fn_ptr = self.force_ptr(self.read_scalar(func)?.not_undef()?)?;
82+
let fn_ptr = self.read_scalar(func)?.not_undef()?;
8383
let fn_val = self.memory.get_fn(fn_ptr)?;
8484
(fn_val, caller_abi)
8585
}
@@ -438,7 +438,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
438438
self.tcx.data_layout.pointer_align.abi,
439439
)?.expect("cannot be a ZST");
440440
let fn_ptr = self.memory.get(vtable_slot.alloc_id)?
441-
.read_ptr_sized(self, vtable_slot)?.to_ptr()?;
441+
.read_ptr_sized(self, vtable_slot)?.not_undef()?;
442442
let drop_fn = self.memory.get_fn(fn_ptr)?;
443443

444444
// `*mut receiver_place.layout.ty` is almost the layout that we

src/librustc_mir/interpret/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
112112
let drop_fn = self.memory
113113
.get(vtable.alloc_id)?
114114
.read_ptr_sized(self, vtable)?
115-
.to_ptr()?;
115+
.not_undef()?;
116116
// We *need* an instance here, no other kind of function value, to be able
117117
// to determine the type.
118118
let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?;

src/librustc_mir/interpret/validity.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
457457
}
458458
ty::FnPtr(_sig) => {
459459
let value = value.to_scalar_or_undef();
460-
let ptr = try_validation!(value.to_ptr(),
461-
value, self.path, "a pointer");
462-
let _fn = try_validation!(self.ecx.memory.get_fn(ptr),
463-
value, self.path, "a function pointer");
460+
let _fn = try_validation!(
461+
value.not_undef().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
462+
value, self.path, "a function pointer"
463+
);
464464
// FIXME: Check if the signature matches
465465
}
466466
// This should be all the primitive types
@@ -508,7 +508,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
508508
// differentiate between null pointers and dangling pointers
509509
if self.ref_tracking_for_consts.is_some() &&
510510
self.ecx.memory.get(ptr.alloc_id).is_err() &&
511-
self.ecx.memory.get_fn(ptr).is_err() {
511+
self.ecx.memory.get_fn(ptr.into()).is_err() {
512512
return validation_failure!(
513513
"encountered dangling pointer", self.path
514514
);

0 commit comments

Comments
 (0)