make Memory::get_fn take a Scalar like most of the Memory API surface
This commit is contained in:
parent
b4be08a666
commit
842bbd2764
4 changed files with 10 additions and 9 deletions
|
|
@ -586,8 +586,9 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
|
|||
|
||||
pub fn get_fn(
|
||||
&self,
|
||||
ptr: Pointer<M::PointerTag>,
|
||||
ptr: Scalar<M::PointerTag>,
|
||||
) -> InterpResult<'tcx, FnVal<'tcx, M::ExtraFnVal>> {
|
||||
let ptr = self.force_ptr(ptr)?; // We definitely need a pointer value.
|
||||
if ptr.offset.bytes() != 0 {
|
||||
return err!(InvalidFunctionPointer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let (fn_val, abi) = match func.layout.ty.sty {
|
||||
ty::FnPtr(sig) => {
|
||||
let caller_abi = sig.abi();
|
||||
let fn_ptr = self.force_ptr(self.read_scalar(func)?.not_undef()?)?;
|
||||
let fn_ptr = self.read_scalar(func)?.not_undef()?;
|
||||
let fn_val = self.memory.get_fn(fn_ptr)?;
|
||||
(fn_val, caller_abi)
|
||||
}
|
||||
|
|
@ -438,7 +438,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
self.tcx.data_layout.pointer_align.abi,
|
||||
)?.expect("cannot be a ZST");
|
||||
let fn_ptr = self.memory.get(vtable_slot.alloc_id)?
|
||||
.read_ptr_sized(self, vtable_slot)?.to_ptr()?;
|
||||
.read_ptr_sized(self, vtable_slot)?.not_undef()?;
|
||||
let drop_fn = self.memory.get_fn(fn_ptr)?;
|
||||
|
||||
// `*mut receiver_place.layout.ty` is almost the layout that we
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let drop_fn = self.memory
|
||||
.get(vtable.alloc_id)?
|
||||
.read_ptr_sized(self, vtable)?
|
||||
.to_ptr()?;
|
||||
.not_undef()?;
|
||||
// We *need* an instance here, no other kind of function value, to be able
|
||||
// to determine the type.
|
||||
let drop_instance = self.memory.get_fn(drop_fn)?.as_instance()?;
|
||||
|
|
|
|||
|
|
@ -457,10 +457,10 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
|||
}
|
||||
ty::FnPtr(_sig) => {
|
||||
let value = value.to_scalar_or_undef();
|
||||
let ptr = try_validation!(value.to_ptr(),
|
||||
value, self.path, "a pointer");
|
||||
let _fn = try_validation!(self.ecx.memory.get_fn(ptr),
|
||||
value, self.path, "a function pointer");
|
||||
let _fn = try_validation!(
|
||||
value.not_undef().and_then(|ptr| self.ecx.memory.get_fn(ptr)),
|
||||
value, self.path, "a function pointer"
|
||||
);
|
||||
// FIXME: Check if the signature matches
|
||||
}
|
||||
// This should be all the primitive types
|
||||
|
|
@ -508,7 +508,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
|
|||
// differentiate between null pointers and dangling pointers
|
||||
if self.ref_tracking_for_consts.is_some() &&
|
||||
self.ecx.memory.get(ptr.alloc_id).is_err() &&
|
||||
self.ecx.memory.get_fn(ptr).is_err() {
|
||||
self.ecx.memory.get_fn(ptr.into()).is_err() {
|
||||
return validation_failure!(
|
||||
"encountered dangling pointer", self.path
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue