2018-08-25 21:22:00 +02:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2022-09-02 21:22:43 -04:00
|
|
|
use rustc_ast::ast::InlineAsmOptions;
|
2021-11-28 19:35:50 -05:00
|
|
|
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::ty::Instance;
|
2021-05-09 02:42:43 +08:00
|
|
|
use rustc_middle::{
|
|
|
|
mir,
|
|
|
|
ty::{self, Ty},
|
|
|
|
};
|
2021-08-30 17:38:27 +03:00
|
|
|
use rustc_target::abi;
|
2021-12-02 21:32:10 -05:00
|
|
|
use rustc_target::abi::call::{ArgAbi, ArgAttribute, ArgAttributes, FnAbi, PassMode};
|
2018-04-25 19:30:39 +03:00
|
|
|
use rustc_target::spec::abi::Abi;
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2018-08-24 14:40:55 +02:00
|
|
|
use super::{
|
2022-07-02 17:09:40 -04:00
|
|
|
FnVal, ImmTy, Immediate, InterpCx, InterpResult, MPlaceTy, Machine, MemoryKind, OpTy, Operand,
|
|
|
|
PlaceTy, Scalar, StackPopCleanup, StackPopUnwind,
|
2018-08-24 14:40:55 +02:00
|
|
|
};
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2020-03-16 15:12:42 -07:00
|
|
|
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
2016-06-23 01:03:58 -06:00
|
|
|
pub(super) fn eval_terminator(
|
|
|
|
&mut self,
|
|
|
|
terminator: &mir::Terminator<'tcx>,
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2020-03-29 16:41:09 +02:00
|
|
|
use rustc_middle::mir::TerminatorKind::*;
|
2016-06-23 01:03:58 -06:00
|
|
|
match terminator.kind {
|
2016-11-26 19:13:22 -08:00
|
|
|
Return => {
|
2019-04-16 21:04:54 -04:00
|
|
|
self.pop_stack_frame(/* unwinding */ false)?
|
2016-11-26 19:13:22 -08:00
|
|
|
}
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2019-11-22 22:17:15 +01:00
|
|
|
Goto { target } => self.go_to_block(target),
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2022-12-03 16:03:27 -08:00
|
|
|
SwitchInt { ref discr, ref targets } => {
|
2021-02-15 00:00:00 +00:00
|
|
|
let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
|
2018-08-15 20:18:40 +02:00
|
|
|
trace!("SwitchInt({:?})", *discr);
|
2016-06-23 01:03:58 -06:00
|
|
|
|
|
|
|
// Branch to the `otherwise` case by default, if no match is found.
|
2020-10-10 17:36:04 +02:00
|
|
|
let mut target_block = targets.otherwise();
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2020-10-10 17:36:04 +02:00
|
|
|
for (const_int, target) in targets.iter() {
|
2022-03-03 14:46:29 -05:00
|
|
|
// Compare using MIR BinOp::Eq, to also support pointer values.
|
|
|
|
// (Avoiding `self.binary_op` as that does some redundant layout computation.)
|
2019-08-10 19:40:56 +02:00
|
|
|
let res = self
|
|
|
|
.overflowing_binary_op(
|
|
|
|
mir::BinOp::Eq,
|
2021-02-15 00:00:00 +00:00
|
|
|
&discr,
|
|
|
|
&ImmTy::from_uint(const_int, discr.layout),
|
2019-08-10 19:40:56 +02:00
|
|
|
)?
|
|
|
|
.0;
|
2018-08-13 16:14:22 +02:00
|
|
|
if res.to_bool()? {
|
2020-10-10 17:36:04 +02:00
|
|
|
target_block = target;
|
2016-06-23 01:03:58 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-22 22:17:15 +01:00
|
|
|
self.go_to_block(target_block);
|
2016-06-23 01:03:58 -06:00
|
|
|
}
|
|
|
|
|
2022-04-16 09:27:54 -04:00
|
|
|
Call {
|
|
|
|
ref func,
|
|
|
|
ref args,
|
|
|
|
destination,
|
|
|
|
target,
|
|
|
|
ref cleanup,
|
|
|
|
from_hir_call: _,
|
|
|
|
fn_span: _,
|
|
|
|
} => {
|
2020-04-14 14:40:08 -07:00
|
|
|
let old_stack = self.frame_idx();
|
2020-04-23 19:40:41 +02:00
|
|
|
let old_loc = self.frame().loc;
|
2018-08-20 15:21:04 +02:00
|
|
|
let func = self.eval_operand(func, None)?;
|
2021-11-28 19:35:50 -05:00
|
|
|
let args = self.eval_operands(args)?;
|
|
|
|
|
|
|
|
let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
|
|
|
|
let fn_sig =
|
|
|
|
self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder);
|
|
|
|
let extra_args = &args[fn_sig.inputs().len()..];
|
|
|
|
let extra_args = self.tcx.mk_type_list(extra_args.iter().map(|arg| arg.layout.ty));
|
|
|
|
|
|
|
|
let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
|
|
|
|
ty::FnPtr(_sig) => {
|
2021-07-12 18:22:15 +02:00
|
|
|
let fn_ptr = self.read_pointer(&func)?;
|
2022-04-03 13:05:49 -04:00
|
|
|
let fn_val = self.get_ptr_fn(fn_ptr)?;
|
2021-11-28 19:35:50 -05:00
|
|
|
(fn_val, self.fn_abi_of_fn_ptr(fn_sig_binder, extra_args)?, false)
|
2017-08-10 08:48:38 -07:00
|
|
|
}
|
2018-08-24 14:40:55 +02:00
|
|
|
ty::FnDef(def_id, substs) => {
|
2021-11-28 19:35:50 -05:00
|
|
|
let instance =
|
|
|
|
self.resolve(ty::WithOptConstParam::unknown(def_id), substs)?;
|
2020-09-09 09:43:18 +02:00
|
|
|
(
|
2021-11-28 19:35:50 -05:00
|
|
|
FnVal::Instance(instance),
|
|
|
|
self.fn_abi_of_instance(instance, extra_args)?,
|
|
|
|
instance.def.requires_caller_location(*self.tcx),
|
2020-09-09 09:43:18 +02:00
|
|
|
)
|
2016-11-26 22:58:01 -08:00
|
|
|
}
|
2020-04-05 08:35:31 +02:00
|
|
|
_ => span_bug!(
|
|
|
|
terminator.source_info.span,
|
|
|
|
"invalid callee of type {:?}",
|
|
|
|
func.layout.ty
|
|
|
|
),
|
2017-02-28 12:35:00 +01:00
|
|
|
};
|
2021-11-28 19:35:50 -05:00
|
|
|
|
2022-04-16 09:27:54 -04:00
|
|
|
let destination = self.eval_place(destination)?;
|
2021-05-23 04:37:17 +08:00
|
|
|
self.eval_fn_call(
|
|
|
|
fn_val,
|
2021-11-28 19:35:50 -05:00
|
|
|
(fn_sig.abi, fn_abi),
|
2021-12-03 03:06:36 +01:00
|
|
|
&args,
|
2021-11-28 19:35:50 -05:00
|
|
|
with_caller_location,
|
2022-04-16 09:27:54 -04:00
|
|
|
&destination,
|
|
|
|
target,
|
2021-11-28 19:35:50 -05:00
|
|
|
match (cleanup, fn_abi.can_unwind) {
|
2021-05-26 00:51:51 +08:00
|
|
|
(Some(cleanup), true) => StackPopUnwind::Cleanup(*cleanup),
|
|
|
|
(None, true) => StackPopUnwind::Skip,
|
|
|
|
(_, false) => StackPopUnwind::NotAllowed,
|
2021-05-23 04:37:17 +08:00
|
|
|
},
|
|
|
|
)?;
|
2020-04-04 15:53:47 +02:00
|
|
|
// Sanity-check that `eval_fn_call` either pushed a new frame or
|
|
|
|
// did a jump to another block.
|
2020-04-23 19:40:41 +02:00
|
|
|
if self.frame_idx() == old_stack && self.frame().loc == old_loc {
|
2020-04-05 08:35:31 +02:00
|
|
|
span_bug!(terminator.source_info.span, "evaluating this call made no progress");
|
|
|
|
}
|
2016-06-23 01:03:58 -06:00
|
|
|
}
|
|
|
|
|
2020-06-10 09:56:54 +02:00
|
|
|
Drop { place, target, unwind } => {
|
2022-12-21 15:22:17 -08:00
|
|
|
let frame = self.frame();
|
|
|
|
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
|
|
|
|
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
|
|
|
|
let instance = Instance::resolve_drop_in_place(*self.tcx, ty);
|
|
|
|
if let ty::InstanceDef::DropGlue(_, None) = instance.def {
|
|
|
|
// This is the branch we enter if and only if the dropped type has no drop glue
|
|
|
|
// whatsoever. This can happen as a result of monomorphizing a drop of a
|
|
|
|
// generic. In order to make sure that generic and non-generic code behaves
|
|
|
|
// roughly the same (and in keeping with Mir semantics) we do nothing here.
|
|
|
|
self.go_to_block(target);
|
|
|
|
return Ok(());
|
|
|
|
}
|
2020-06-10 09:56:54 +02:00
|
|
|
let place = self.eval_place(place)?;
|
|
|
|
trace!("TerminatorKind::drop: {:?}, type {}", place, ty);
|
2021-02-15 00:00:00 +00:00
|
|
|
self.drop_in_place(&place, instance, target, unwind)?;
|
2017-03-22 13:13:52 +01:00
|
|
|
}
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2017-08-10 08:48:38 -07:00
|
|
|
Assert { ref cond, expected, ref msg, target, cleanup } => {
|
2023-02-11 17:12:57 +00:00
|
|
|
let ignored = !M::checked_binop_checks_overflow(self)
|
2023-02-11 16:41:37 +00:00
|
|
|
&& match msg {
|
|
|
|
mir::AssertKind::OverflowNeg(..) => true,
|
|
|
|
mir::AssertKind::Overflow(op, ..) => op.is_checkable(),
|
|
|
|
_ => false,
|
|
|
|
};
|
2022-08-01 19:05:20 -04:00
|
|
|
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
|
2023-02-11 16:41:37 +00:00
|
|
|
if ignored || expected == cond_val {
|
2019-11-22 22:17:15 +01:00
|
|
|
self.go_to_block(target);
|
2016-06-23 01:03:58 -06:00
|
|
|
} else {
|
2020-03-09 19:58:58 +01:00
|
|
|
M::assert_panic(self, msg, cleanup)?;
|
2016-06-23 01:03:58 -06:00
|
|
|
}
|
2017-08-10 08:48:38 -07:00
|
|
|
}
|
2016-06-23 01:03:58 -06:00
|
|
|
|
2020-03-09 10:45:20 +01:00
|
|
|
Abort => {
|
2020-12-06 20:25:13 +01:00
|
|
|
M::abort(self, "the program aborted execution".to_owned())?;
|
2020-03-09 10:45:20 +01:00
|
|
|
}
|
|
|
|
|
2019-04-16 21:04:54 -04:00
|
|
|
// When we encounter Resume, we've finished unwinding
|
|
|
|
// cleanup for the current stack frame. We pop it in order
|
|
|
|
// to continue unwinding the next frame
|
|
|
|
Resume => {
|
|
|
|
trace!("unwinding: resuming from cleanup");
|
2019-09-19 13:47:59 -04:00
|
|
|
// By definition, a Resume terminator means
|
2019-04-16 21:04:54 -04:00
|
|
|
// that we're unwinding
|
|
|
|
self.pop_stack_frame(/* unwinding */ true)?;
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2019-11-29 09:59:52 +01:00
|
|
|
// It is UB to ever encounter this.
|
|
|
|
Unreachable => throw_ub!(Unreachable),
|
|
|
|
|
|
|
|
// These should never occur for MIR we actually run.
|
2020-03-08 19:05:18 +01:00
|
|
|
DropAndReplace { .. }
|
2020-06-02 09:15:24 +02:00
|
|
|
| FalseEdge { .. }
|
2020-03-08 19:05:18 +01:00
|
|
|
| FalseUnwind { .. }
|
|
|
|
| Yield { .. }
|
2020-04-05 08:35:31 +02:00
|
|
|
| GeneratorDrop => span_bug!(
|
|
|
|
terminator.source_info.span,
|
|
|
|
"{:#?} should have been eliminated by MIR pass",
|
|
|
|
terminator.kind
|
|
|
|
),
|
2020-02-14 18:17:50 +00:00
|
|
|
|
2022-09-02 21:22:43 -04:00
|
|
|
InlineAsm { template, ref operands, options, destination, .. } => {
|
|
|
|
M::eval_inline_asm(self, template, operands, options)?;
|
|
|
|
if options.contains(InlineAsmOptions::NORETURN) {
|
|
|
|
throw_ub_format!("returned from noreturn inline assembly");
|
|
|
|
}
|
|
|
|
self.go_to_block(
|
|
|
|
destination
|
|
|
|
.expect("InlineAsm terminators without noreturn must have a destination"),
|
|
|
|
)
|
|
|
|
}
|
2016-06-23 01:03:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2018-08-27 13:34:35 +02:00
|
|
|
fn check_argument_compat(
|
2021-11-28 19:35:50 -05:00
|
|
|
caller_abi: &ArgAbi<'tcx, Ty<'tcx>>,
|
|
|
|
callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
|
2018-08-27 13:34:35 +02:00
|
|
|
) -> bool {
|
2021-11-28 19:35:50 -05:00
|
|
|
// Heuristic for type comparison.
|
|
|
|
let layout_compat = || {
|
|
|
|
if caller_abi.layout.ty == callee_abi.layout.ty {
|
|
|
|
// No question
|
|
|
|
return true;
|
|
|
|
}
|
2022-07-02 17:09:40 -04:00
|
|
|
if caller_abi.layout.is_unsized() || callee_abi.layout.is_unsized() {
|
|
|
|
// No, no, no. We require the types to *exactly* match for unsized arguments. If
|
|
|
|
// these are somehow unsized "in a different way" (say, `dyn Trait` vs `[i32]`),
|
|
|
|
// then who knows what happens.
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-25 14:29:46 +02:00
|
|
|
if caller_abi.layout.size != callee_abi.layout.size
|
|
|
|
|| caller_abi.layout.align.abi != callee_abi.layout.align.abi
|
|
|
|
{
|
|
|
|
// This cannot go well...
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// The rest *should* be okay, but we are extra conservative.
|
2021-11-28 19:35:50 -05:00
|
|
|
match (caller_abi.layout.abi, callee_abi.layout.abi) {
|
|
|
|
// Different valid ranges are okay (once we enforce validity,
|
|
|
|
// that will take care to make it UB to leave the range, just
|
|
|
|
// like for transmute).
|
|
|
|
(abi::Abi::Scalar(caller), abi::Abi::Scalar(callee)) => {
|
2022-03-03 12:02:12 +00:00
|
|
|
caller.primitive() == callee.primitive()
|
2021-11-28 19:35:50 -05:00
|
|
|
}
|
|
|
|
(
|
|
|
|
abi::Abi::ScalarPair(caller1, caller2),
|
|
|
|
abi::Abi::ScalarPair(callee1, callee2),
|
2022-03-03 12:02:12 +00:00
|
|
|
) => {
|
|
|
|
caller1.primitive() == callee1.primitive()
|
|
|
|
&& caller2.primitive() == callee2.primitive()
|
|
|
|
}
|
2021-11-28 19:35:50 -05:00
|
|
|
// Be conservative
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
};
|
2021-12-02 21:32:10 -05:00
|
|
|
// When comparing the PassMode, we have to be smart about comparing the attributes.
|
2022-08-25 17:52:37 +10:00
|
|
|
let arg_attr_compat = |a1: &ArgAttributes, a2: &ArgAttributes| {
|
2021-12-02 21:32:10 -05:00
|
|
|
// There's only one regular attribute that matters for the call ABI: InReg.
|
2022-08-18 10:13:37 +08:00
|
|
|
// Everything else is things like noalias, dereferenceable, nonnull, ...
|
2021-12-02 21:32:10 -05:00
|
|
|
// (This also applies to pointee_size, pointee_align.)
|
|
|
|
if a1.regular.contains(ArgAttribute::InReg) != a2.regular.contains(ArgAttribute::InReg)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// We also compare the sign extension mode -- this could let the callee make assumptions
|
|
|
|
// about bits that conceptually were not even passed.
|
|
|
|
if a1.arg_ext != a2.arg_ext {
|
2021-11-28 19:35:50 -05:00
|
|
|
return false;
|
|
|
|
}
|
2018-08-27 13:34:35 +02:00
|
|
|
return true;
|
2021-11-28 19:35:50 -05:00
|
|
|
};
|
2022-08-25 17:52:37 +10:00
|
|
|
let mode_compat = || match (&caller_abi.mode, &callee_abi.mode) {
|
2021-12-02 21:32:10 -05:00
|
|
|
(PassMode::Ignore, PassMode::Ignore) => true,
|
|
|
|
(PassMode::Direct(a1), PassMode::Direct(a2)) => arg_attr_compat(a1, a2),
|
|
|
|
(PassMode::Pair(a1, b1), PassMode::Pair(a2, b2)) => {
|
|
|
|
arg_attr_compat(a1, a2) && arg_attr_compat(b1, b2)
|
2019-12-22 17:42:04 -05:00
|
|
|
}
|
2022-08-25 22:19:38 +10:00
|
|
|
(PassMode::Cast(c1, pad1), PassMode::Cast(c2, pad2)) => c1 == c2 && pad1 == pad2,
|
2021-12-02 21:32:10 -05:00
|
|
|
(
|
|
|
|
PassMode::Indirect { attrs: a1, extra_attrs: None, on_stack: s1 },
|
|
|
|
PassMode::Indirect { attrs: a2, extra_attrs: None, on_stack: s2 },
|
|
|
|
) => arg_attr_compat(a1, a2) && s1 == s2,
|
|
|
|
(
|
|
|
|
PassMode::Indirect { attrs: a1, extra_attrs: Some(e1), on_stack: s1 },
|
|
|
|
PassMode::Indirect { attrs: a2, extra_attrs: Some(e2), on_stack: s2 },
|
|
|
|
) => arg_attr_compat(a1, a2) && arg_attr_compat(e1, e2) && s1 == s2,
|
|
|
|
_ => false,
|
2021-11-28 19:35:50 -05:00
|
|
|
};
|
|
|
|
|
2022-08-25 22:19:38 +10:00
|
|
|
if layout_compat() && mode_compat() {
|
2021-12-02 21:32:10 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
trace!(
|
|
|
|
"check_argument_compat: incompatible ABIs:\ncaller: {:?}\ncallee: {:?}",
|
|
|
|
caller_abi,
|
|
|
|
callee_abi
|
|
|
|
);
|
|
|
|
return false;
|
2018-08-27 13:34:35 +02:00
|
|
|
}
|
2017-05-26 20:02:51 -07:00
|
|
|
|
2021-11-28 19:35:50 -05:00
|
|
|
/// Initialize a single callee argument, checking the types for compatibility.
|
|
|
|
fn pass_argument<'x, 'y>(
|
2018-08-27 13:34:35 +02:00
|
|
|
&mut self,
|
2021-11-28 19:35:50 -05:00
|
|
|
caller_args: &mut impl Iterator<
|
2022-07-18 18:47:31 -04:00
|
|
|
Item = (&'x OpTy<'tcx, M::Provenance>, &'y ArgAbi<'tcx, Ty<'tcx>>),
|
2021-11-28 19:35:50 -05:00
|
|
|
>,
|
|
|
|
callee_abi: &ArgAbi<'tcx, Ty<'tcx>>,
|
2022-07-18 18:47:31 -04:00
|
|
|
callee_arg: &PlaceTy<'tcx, M::Provenance>,
|
2021-11-28 19:35:50 -05:00
|
|
|
) -> InterpResult<'tcx>
|
|
|
|
where
|
|
|
|
'tcx: 'x,
|
|
|
|
'tcx: 'y,
|
|
|
|
{
|
|
|
|
if matches!(callee_abi.mode, PassMode::Ignore) {
|
|
|
|
// This one is skipped.
|
2018-08-27 13:34:35 +02:00
|
|
|
return Ok(());
|
2017-05-26 20:02:51 -07:00
|
|
|
}
|
2021-11-28 19:35:50 -05:00
|
|
|
// Find next caller arg.
|
|
|
|
let (caller_arg, caller_abi) = caller_args.next().ok_or_else(|| {
|
2020-03-08 23:28:00 +01:00
|
|
|
err_ub_format!("calling a function with fewer arguments than it requires")
|
2020-03-08 18:52:30 +01:00
|
|
|
})?;
|
2018-08-27 13:34:35 +02:00
|
|
|
// Now, check
|
2021-11-28 19:35:50 -05:00
|
|
|
if !Self::check_argument_compat(caller_abi, callee_abi) {
|
2020-03-08 18:52:30 +01:00
|
|
|
throw_ub_format!(
|
|
|
|
"calling a function with argument of type {:?} passing data of type {:?}",
|
|
|
|
callee_arg.layout.ty,
|
|
|
|
caller_arg.layout.ty
|
|
|
|
)
|
2018-08-27 13:34:35 +02:00
|
|
|
}
|
2022-07-02 17:09:40 -04:00
|
|
|
// Special handling for unsized parameters.
|
|
|
|
if caller_arg.layout.is_unsized() {
|
|
|
|
// `check_argument_compat` ensures that both have the same type, so we know they will use the metadata the same way.
|
|
|
|
assert_eq!(caller_arg.layout.ty, callee_arg.layout.ty);
|
|
|
|
// We have to properly pre-allocate the memory for the callee.
|
|
|
|
// So let's tear down some wrappers.
|
|
|
|
// This all has to be in memory, there are no immediate unsized values.
|
|
|
|
let src = caller_arg.assert_mem_place();
|
|
|
|
// The destination cannot be one of these "spread args".
|
|
|
|
let (dest_frame, dest_local) = callee_arg.assert_local();
|
|
|
|
// We are just initializing things, so there can't be anything here yet.
|
|
|
|
assert!(matches!(
|
|
|
|
*self.local_to_op(&self.stack()[dest_frame], dest_local, None)?,
|
|
|
|
Operand::Immediate(Immediate::Uninit)
|
|
|
|
));
|
|
|
|
// Allocate enough memory to hold `src`.
|
|
|
|
let Some((size, align)) = self.size_and_align_of_mplace(&src)? else {
|
|
|
|
span_bug!(self.cur_span(), "unsized fn arg with `extern` type tail should not be allowed")
|
|
|
|
};
|
|
|
|
let ptr = self.allocate_ptr(size, align, MemoryKind::Stack)?;
|
|
|
|
let dest_place =
|
|
|
|
MPlaceTy::from_aligned_ptr_with_meta(ptr.into(), callee_arg.layout, src.meta);
|
|
|
|
// Update the local to be that new place.
|
|
|
|
*M::access_local_mut(self, dest_frame, dest_local)? = Operand::Indirect(*dest_place);
|
|
|
|
}
|
2021-11-28 19:35:50 -05:00
|
|
|
// We allow some transmutes here.
|
|
|
|
// FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
|
|
|
|
// is true for all `copy_op`, but there are a lot of special cases for argument passing
|
|
|
|
// specifically.)
|
2022-07-02 20:40:41 -04:00
|
|
|
self.copy_op(&caller_arg, callee_arg, /*allow_transmute*/ true)
|
2017-05-26 20:02:51 -07:00
|
|
|
}
|
|
|
|
|
2018-08-24 14:40:55 +02:00
|
|
|
/// Call this function -- pushing the stack frame and initializing the arguments.
|
2021-11-28 19:35:50 -05:00
|
|
|
///
|
2021-12-01 21:37:23 -05:00
|
|
|
/// `caller_fn_abi` is used to determine if all the arguments are passed the proper way.
|
|
|
|
/// However, we also need `caller_abi` to determine if we need to do untupling of arguments.
|
2021-11-28 19:35:50 -05:00
|
|
|
///
|
|
|
|
/// `with_caller_location` indicates whether the caller passed a caller location. Miri
|
|
|
|
/// implements caller locations without argument passing, but to match `FnAbi` we need to know
|
|
|
|
/// when those arguments are present.
|
2021-10-12 05:06:37 +00:00
|
|
|
pub(crate) fn eval_fn_call(
|
2016-06-23 01:03:58 -06:00
|
|
|
&mut self,
|
2019-06-30 13:51:18 +02:00
|
|
|
fn_val: FnVal<'tcx, M::ExtraFnVal>,
|
2021-11-28 19:35:50 -05:00
|
|
|
(caller_abi, caller_fn_abi): (Abi, &FnAbi<'tcx, Ty<'tcx>>),
|
2022-07-18 18:47:31 -04:00
|
|
|
args: &[OpTy<'tcx, M::Provenance>],
|
2021-11-28 19:35:50 -05:00
|
|
|
with_caller_location: bool,
|
2022-07-18 18:47:31 -04:00
|
|
|
destination: &PlaceTy<'tcx, M::Provenance>,
|
2022-04-16 09:27:54 -04:00
|
|
|
target: Option<mir::BasicBlock>,
|
2021-05-23 04:37:17 +08:00
|
|
|
mut unwind: StackPopUnwind,
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2019-06-30 13:51:18 +02:00
|
|
|
trace!("eval_fn_call: {:#?}", fn_val);
|
|
|
|
|
2019-06-30 15:06:13 +02:00
|
|
|
let instance = match fn_val {
|
|
|
|
FnVal::Instance(instance) => instance,
|
|
|
|
FnVal::Other(extra) => {
|
2022-04-16 09:27:54 -04:00
|
|
|
return M::call_extra_fn(
|
|
|
|
self,
|
|
|
|
extra,
|
|
|
|
caller_abi,
|
|
|
|
args,
|
|
|
|
destination,
|
|
|
|
target,
|
|
|
|
unwind,
|
|
|
|
);
|
2019-06-30 15:06:13 +02:00
|
|
|
}
|
|
|
|
};
|
2018-08-24 14:40:55 +02:00
|
|
|
|
2017-03-22 13:13:52 +01:00
|
|
|
match instance.def {
|
2022-05-13 13:50:21 +00:00
|
|
|
ty::InstanceDef::Intrinsic(def_id) => {
|
|
|
|
assert!(self.tcx.is_intrinsic(def_id));
|
2021-11-28 19:35:50 -05:00
|
|
|
// caller_fn_abi is not relevant here, we interpret the arguments directly for each intrinsic.
|
2022-04-16 09:27:54 -04:00
|
|
|
M::call_intrinsic(self, instance, args, destination, target, unwind)
|
2017-08-10 08:48:38 -07:00
|
|
|
}
|
2022-07-19 19:57:44 -04:00
|
|
|
ty::InstanceDef::VTableShim(..)
|
2019-10-03 19:10:34 -07:00
|
|
|
| ty::InstanceDef::ReifyShim(..)
|
2018-08-24 14:40:55 +02:00
|
|
|
| ty::InstanceDef::ClosureOnceShim { .. }
|
2017-08-23 17:46:36 +02:00
|
|
|
| ty::InstanceDef::FnPtrShim(..)
|
|
|
|
| ty::InstanceDef::DropGlue(..)
|
2017-08-23 17:24:38 +02:00
|
|
|
| ty::InstanceDef::CloneShim(..)
|
2017-03-22 13:13:52 +01:00
|
|
|
| ty::InstanceDef::Item(_) => {
|
2018-08-27 13:34:35 +02:00
|
|
|
// We need MIR for this fn
|
2022-02-19 00:47:43 +01:00
|
|
|
let Some((body, instance)) =
|
2022-04-16 09:27:54 -04:00
|
|
|
M::find_mir_or_eval_fn(self, instance, caller_abi, args, destination, target, unwind)? else {
|
2022-02-19 00:47:43 +01:00
|
|
|
return Ok(());
|
2021-01-10 14:31:02 +00:00
|
|
|
};
|
2018-08-23 19:04:33 +02:00
|
|
|
|
2021-11-28 19:35:50 -05:00
|
|
|
// Compute callee information using the `instance` returned by
|
|
|
|
// `find_mir_or_eval_fn`.
|
2022-03-30 01:39:38 -04:00
|
|
|
// FIXME: for variadic support, do we have to somehow determine callee's extra_args?
|
2021-11-28 19:35:50 -05:00
|
|
|
let callee_fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;
|
2021-12-06 17:58:24 -05:00
|
|
|
|
2022-06-05 13:24:10 -04:00
|
|
|
if callee_fn_abi.c_variadic || caller_fn_abi.c_variadic {
|
2021-12-06 17:58:24 -05:00
|
|
|
throw_unsup_format!("calling a c-variadic function is not supported");
|
|
|
|
}
|
2021-05-22 03:53:00 +08:00
|
|
|
|
|
|
|
if M::enforce_abi(self) {
|
2021-12-01 21:37:23 -05:00
|
|
|
if caller_fn_abi.conv != callee_fn_abi.conv {
|
|
|
|
throw_ub_format!(
|
|
|
|
"calling a function with calling convention {:?} using calling convention {:?}",
|
|
|
|
callee_fn_abi.conv,
|
|
|
|
caller_fn_abi.conv
|
|
|
|
)
|
|
|
|
}
|
2021-05-22 03:53:00 +08:00
|
|
|
}
|
|
|
|
|
2021-11-28 19:35:50 -05:00
|
|
|
if !matches!(unwind, StackPopUnwind::NotAllowed) && !callee_fn_abi.can_unwind {
|
2021-05-25 03:51:41 +08:00
|
|
|
// The callee cannot unwind.
|
2021-05-23 04:37:17 +08:00
|
|
|
unwind = StackPopUnwind::NotAllowed;
|
|
|
|
}
|
2021-05-09 02:42:43 +08:00
|
|
|
|
2018-08-23 19:04:33 +02:00
|
|
|
self.push_stack_frame(
|
|
|
|
instance,
|
2019-06-03 18:26:48 -04:00
|
|
|
body,
|
2022-04-16 09:27:54 -04:00
|
|
|
destination,
|
|
|
|
StackPopCleanup::Goto { ret: target, unwind },
|
2018-08-23 19:04:33 +02:00
|
|
|
)?;
|
2017-03-23 13:36:13 +01:00
|
|
|
|
2020-03-09 21:43:05 +01:00
|
|
|
// If an error is raised here, pop the frame again to get an accurate backtrace.
|
|
|
|
// To this end, we wrap it all in a `try` block.
|
|
|
|
let res: InterpResult<'tcx> = try {
|
2020-03-08 18:52:30 +01:00
|
|
|
trace!(
|
|
|
|
"caller ABI: {:?}, args: {:#?}",
|
|
|
|
caller_abi,
|
|
|
|
args.iter()
|
|
|
|
.map(|arg| (arg.layout.ty, format!("{:?}", **arg)))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
);
|
|
|
|
trace!(
|
|
|
|
"spread_arg: {:?}, locals: {:#?}",
|
|
|
|
body.spread_arg,
|
|
|
|
body.args_iter()
|
|
|
|
.map(|local| (
|
|
|
|
local,
|
|
|
|
self.layout_of_local(self.frame(), local, None).unwrap().ty
|
|
|
|
))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
);
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2021-11-28 19:35:50 -05:00
|
|
|
// In principle, we have two iterators: Where the arguments come from, and where
|
|
|
|
// they go to.
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2020-03-08 18:52:30 +01:00
|
|
|
// For where they come from: If the ABI is RustCall, we untuple the
|
2022-11-16 20:34:16 +00:00
|
|
|
// last incoming argument. These two iterators do not have the same type,
|
2020-03-08 18:52:30 +01:00
|
|
|
// so to keep the code paths uniform we accept an allocation
|
|
|
|
// (for RustCall ABI only).
|
2022-07-18 18:47:31 -04:00
|
|
|
let caller_args: Cow<'_, [OpTy<'tcx, M::Provenance>]> =
|
2020-03-08 18:52:30 +01:00
|
|
|
if caller_abi == Abi::RustCall && !args.is_empty() {
|
|
|
|
// Untuple
|
2021-02-15 00:00:00 +00:00
|
|
|
let (untuple_arg, args) = args.split_last().unwrap();
|
2020-03-08 18:52:30 +01:00
|
|
|
trace!("eval_fn_call: Will pass last argument by untupling");
|
|
|
|
Cow::from(
|
|
|
|
args.iter()
|
2022-07-15 22:58:20 -04:00
|
|
|
.map(|a| Ok(a.clone()))
|
2020-03-08 18:52:30 +01:00
|
|
|
.chain(
|
|
|
|
(0..untuple_arg.layout.fields.count())
|
2020-03-21 17:17:01 +01:00
|
|
|
.map(|i| self.operand_field(untuple_arg, i)),
|
2020-03-08 18:52:30 +01:00
|
|
|
)
|
2022-07-18 18:47:31 -04:00
|
|
|
.collect::<InterpResult<'_, Vec<OpTy<'tcx, M::Provenance>>>>(
|
2020-03-08 18:52:30 +01:00
|
|
|
)?,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
// Plain arg passing
|
|
|
|
Cow::from(args)
|
|
|
|
};
|
2021-11-28 19:35:50 -05:00
|
|
|
// If `with_caller_location` is set we pretend there is an extra argument (that
|
|
|
|
// we will not pass).
|
|
|
|
assert_eq!(
|
|
|
|
caller_args.len() + if with_caller_location { 1 } else { 0 },
|
|
|
|
caller_fn_abi.args.len(),
|
|
|
|
"mismatch between caller ABI and caller arguments",
|
|
|
|
);
|
|
|
|
let mut caller_args = caller_args
|
|
|
|
.iter()
|
|
|
|
.zip(caller_fn_abi.args.iter())
|
|
|
|
.filter(|arg_and_abi| !matches!(arg_and_abi.1.mode, PassMode::Ignore));
|
2019-12-22 17:42:04 -05:00
|
|
|
|
2020-03-08 18:52:30 +01:00
|
|
|
// Now we have to spread them out across the callee's locals,
|
2022-11-16 20:34:16 +00:00
|
|
|
// taking into account the `spread_arg`. If we could write
|
2020-03-08 18:52:30 +01:00
|
|
|
// this is a single iterator (that handles `spread_arg`), then
|
|
|
|
// `pass_argument` would be the loop body. It takes care to
|
|
|
|
// not advance `caller_iter` for ZSTs.
|
2021-11-28 19:35:50 -05:00
|
|
|
let mut callee_args_abis = callee_fn_abi.args.iter();
|
2020-03-08 23:55:25 +01:00
|
|
|
for local in body.args_iter() {
|
2020-03-31 12:19:29 -03:00
|
|
|
let dest = self.eval_place(mir::Place::from(local))?;
|
2020-03-08 18:52:30 +01:00
|
|
|
if Some(local) == body.spread_arg {
|
|
|
|
// Must be a tuple
|
|
|
|
for i in 0..dest.layout.fields.count() {
|
2021-02-15 00:00:00 +00:00
|
|
|
let dest = self.place_field(&dest, i)?;
|
2021-11-28 19:35:50 -05:00
|
|
|
let callee_abi = callee_args_abis.next().unwrap();
|
|
|
|
self.pass_argument(&mut caller_args, callee_abi, &dest)?;
|
2018-08-27 13:34:35 +02:00
|
|
|
}
|
2020-03-08 18:52:30 +01:00
|
|
|
} else {
|
|
|
|
// Normal argument
|
2021-11-28 19:35:50 -05:00
|
|
|
let callee_abi = callee_args_abis.next().unwrap();
|
|
|
|
self.pass_argument(&mut caller_args, callee_abi, &dest)?;
|
2018-08-24 14:40:55 +02:00
|
|
|
}
|
2020-03-08 18:52:30 +01:00
|
|
|
}
|
2021-11-28 19:35:50 -05:00
|
|
|
// If the callee needs a caller location, pretend we consume one more argument from the ABI.
|
|
|
|
if instance.def.requires_caller_location(*self.tcx) {
|
|
|
|
callee_args_abis.next().unwrap();
|
|
|
|
}
|
|
|
|
// Now we should have no more caller args or callee arg ABIs
|
|
|
|
assert!(
|
|
|
|
callee_args_abis.next().is_none(),
|
|
|
|
"mismatch between callee ABI and callee body arguments"
|
|
|
|
);
|
|
|
|
if caller_args.next().is_some() {
|
2020-03-08 23:55:25 +01:00
|
|
|
throw_ub_format!("calling a function with more arguments than it expected")
|
2020-03-08 18:52:30 +01:00
|
|
|
}
|
|
|
|
// Don't forget to check the return type!
|
2021-11-28 19:35:50 -05:00
|
|
|
if !Self::check_argument_compat(&caller_fn_abi.ret, &callee_fn_abi.ret) {
|
|
|
|
throw_ub_format!(
|
|
|
|
"calling a function with return type {:?} passing \
|
|
|
|
return place of type {:?}",
|
|
|
|
callee_fn_abi.ret.layout.ty,
|
|
|
|
caller_fn_abi.ret.layout.ty,
|
|
|
|
)
|
2020-03-08 18:52:30 +01:00
|
|
|
}
|
2020-03-09 21:43:05 +01:00
|
|
|
};
|
2018-08-27 13:34:35 +02:00
|
|
|
match res {
|
|
|
|
Err(err) => {
|
2020-03-16 15:12:42 -07:00
|
|
|
self.stack_mut().pop();
|
2018-08-27 13:34:35 +02:00
|
|
|
Err(err)
|
|
|
|
}
|
2020-03-21 14:24:57 +01:00
|
|
|
Ok(()) => Ok(()),
|
2017-03-23 13:36:13 +01:00
|
|
|
}
|
2017-08-10 08:48:38 -07:00
|
|
|
}
|
2017-08-23 17:46:36 +02:00
|
|
|
// cannot use the shim here, because that will only result in infinite recursion
|
2022-07-20 18:33:51 -04:00
|
|
|
ty::InstanceDef::Virtual(def_id, idx) => {
|
2019-04-07 19:54:43 +02:00
|
|
|
let mut args = args.to_vec();
|
2022-03-18 08:48:34 -04:00
|
|
|
// We have to implement all "object safe receivers". So we have to go search for a
|
|
|
|
// pointer or `dyn Trait` type, but it could be wrapped in newtypes. So recursively
|
|
|
|
// unwrap those newtypes until we are there.
|
2022-07-15 22:58:20 -04:00
|
|
|
let mut receiver = args[0].clone();
|
2022-03-18 08:48:34 -04:00
|
|
|
let receiver_place = loop {
|
|
|
|
match receiver.layout.ty.kind() {
|
|
|
|
ty::Ref(..) | ty::RawPtr(..) => break self.deref_operand(&receiver)?,
|
2022-07-04 08:48:05 -04:00
|
|
|
ty::Dynamic(..) => break receiver.assert_mem_place(), // no immediate unsized values
|
2022-03-18 08:48:34 -04:00
|
|
|
_ => {
|
|
|
|
// Not there yet, search for the only non-ZST field.
|
|
|
|
let mut non_zst_field = None;
|
|
|
|
for i in 0..receiver.layout.fields.count() {
|
|
|
|
let field = self.operand_field(&receiver, i)?;
|
2022-07-28 17:06:58 -04:00
|
|
|
let zst =
|
|
|
|
field.layout.is_zst() && field.layout.align.abi.bytes() == 1;
|
|
|
|
if !zst {
|
2022-03-18 08:48:34 -04:00
|
|
|
assert!(
|
|
|
|
non_zst_field.is_none(),
|
|
|
|
"multiple non-ZST fields in dyn receiver type {}",
|
|
|
|
receiver.layout.ty
|
|
|
|
);
|
|
|
|
non_zst_field = Some(field);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
receiver = non_zst_field.unwrap_or_else(|| {
|
|
|
|
panic!(
|
|
|
|
"no non-ZST fields in dyn receiver type {}",
|
|
|
|
receiver.layout.ty
|
|
|
|
)
|
|
|
|
});
|
|
|
|
}
|
2019-04-07 19:54:43 +02:00
|
|
|
}
|
|
|
|
};
|
2022-07-20 18:33:51 -04:00
|
|
|
// Obtain the underlying trait we are working on.
|
|
|
|
let receiver_tail = self
|
|
|
|
.tcx
|
|
|
|
.struct_tail_erasing_lifetimes(receiver_place.layout.ty, self.param_env);
|
|
|
|
let ty::Dynamic(data, ..) = receiver_tail.kind() else {
|
2022-08-18 10:13:37 +08:00
|
|
|
span_bug!(self.cur_span(), "dynamic call on non-`dyn` type {}", receiver_tail)
|
2022-07-20 18:33:51 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Get the required information from the vtable.
|
2022-07-23 10:36:57 -04:00
|
|
|
let vptr = receiver_place.meta.unwrap_meta().to_pointer(self)?;
|
2022-07-20 18:33:51 -04:00
|
|
|
let (dyn_ty, dyn_trait) = self.get_ptr_vtable(vptr)?;
|
|
|
|
if dyn_trait != data.principal() {
|
2022-07-17 16:02:49 -04:00
|
|
|
throw_ub_format!(
|
2022-07-20 18:33:51 -04:00
|
|
|
"`dyn` call on a pointer whose vtable does not match its type"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now determine the actual method to call. We can do that in two different ways and
|
|
|
|
// compare them to ensure everything fits.
|
2022-07-24 09:21:05 -04:00
|
|
|
let Some(ty::VtblEntry::Method(fn_inst)) = self.get_vtable_entries(vptr)?.get(idx).copied() else {
|
|
|
|
throw_ub_format!("`dyn` call trying to call something that is not a method")
|
2022-07-17 16:02:49 -04:00
|
|
|
};
|
2022-07-20 18:33:51 -04:00
|
|
|
if cfg!(debug_assertions) {
|
|
|
|
let tcx = *self.tcx;
|
|
|
|
|
|
|
|
let trait_def_id = tcx.trait_of_item(def_id).unwrap();
|
|
|
|
let virtual_trait_ref =
|
|
|
|
ty::TraitRef::from_method(tcx, trait_def_id, instance.substs);
|
|
|
|
assert_eq!(
|
|
|
|
receiver_tail,
|
|
|
|
virtual_trait_ref.self_ty(),
|
|
|
|
"mismatch in underlying dyn trait computation within Miri and MIR building",
|
|
|
|
);
|
|
|
|
let existential_trait_ref =
|
|
|
|
ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref);
|
|
|
|
let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty);
|
|
|
|
|
2022-07-22 10:37:03 -04:00
|
|
|
let concrete_method = Instance::resolve_for_vtable(
|
2022-07-20 18:33:51 -04:00
|
|
|
tcx,
|
|
|
|
self.param_env,
|
|
|
|
def_id,
|
|
|
|
instance.substs.rebase_onto(tcx, trait_def_id, concrete_trait_ref.substs),
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(fn_inst, concrete_method);
|
|
|
|
}
|
2018-08-16 10:30:56 +02:00
|
|
|
|
2019-04-07 19:54:43 +02:00
|
|
|
// `*mut receiver_place.layout.ty` is almost the layout that we
|
|
|
|
// want for args[0]: We have to project to field 0 because we want
|
|
|
|
// a thin pointer.
|
|
|
|
assert!(receiver_place.layout.is_unsized());
|
|
|
|
let receiver_ptr_ty = self.tcx.mk_mut_ptr(receiver_place.layout.ty);
|
2021-08-25 18:05:10 +03:00
|
|
|
let this_receiver_ptr = self.layout_of(receiver_ptr_ty)?.field(self, 0);
|
2019-04-07 19:54:43 +02:00
|
|
|
// Adjust receiver argument.
|
2021-07-12 18:22:15 +02:00
|
|
|
args[0] = OpTy::from(ImmTy::from_immediate(
|
|
|
|
Scalar::from_maybe_pointer(receiver_place.ptr, self).into(),
|
|
|
|
this_receiver_ptr,
|
|
|
|
));
|
2022-03-18 08:48:34 -04:00
|
|
|
trace!("Patched receiver operand to {:#?}", args[0]);
|
2017-03-23 14:57:11 +01:00
|
|
|
// recurse with concrete function
|
2021-11-28 19:35:50 -05:00
|
|
|
self.eval_fn_call(
|
2022-07-17 16:02:49 -04:00
|
|
|
FnVal::Instance(fn_inst),
|
2021-11-28 19:35:50 -05:00
|
|
|
(caller_abi, caller_fn_abi),
|
|
|
|
&args,
|
|
|
|
with_caller_location,
|
2022-04-16 09:27:54 -04:00
|
|
|
destination,
|
|
|
|
target,
|
2021-11-28 19:35:50 -05:00
|
|
|
unwind,
|
|
|
|
)
|
2017-08-10 08:48:38 -07:00
|
|
|
}
|
2017-02-28 12:35:00 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-24 14:44:30 +02:00
|
|
|
|
|
|
|
fn drop_in_place(
|
|
|
|
&mut self,
|
2022-07-18 18:47:31 -04:00
|
|
|
place: &PlaceTy<'tcx, M::Provenance>,
|
2018-08-24 14:44:30 +02:00
|
|
|
instance: ty::Instance<'tcx>,
|
|
|
|
target: mir::BasicBlock,
|
2019-04-16 21:04:54 -04:00
|
|
|
unwind: Option<mir::BasicBlock>,
|
2019-06-07 18:56:27 +02:00
|
|
|
) -> InterpResult<'tcx> {
|
2018-08-24 14:44:30 +02:00
|
|
|
trace!("drop_in_place: {:?},\n {:?}, {:?}", *place, place.layout.ty, instance);
|
2022-11-16 20:34:16 +00:00
|
|
|
// We take the address of the object. This may well be unaligned, which is fine
|
|
|
|
// for us here. However, unaligned accesses will probably make the actual drop
|
2018-08-24 14:44:30 +02:00
|
|
|
// implementation fail -- a problem shared by rustc.
|
|
|
|
let place = self.force_allocation(place)?;
|
|
|
|
|
2020-08-03 00:49:11 +02:00
|
|
|
let (instance, place) = match place.layout.ty.kind() {
|
2018-08-24 14:44:30 +02:00
|
|
|
ty::Dynamic(..) => {
|
2022-07-17 16:02:49 -04:00
|
|
|
// Dropping a trait object. Need to find actual drop fn.
|
|
|
|
let place = self.unpack_dyn_trait(&place)?;
|
|
|
|
let instance = ty::Instance::resolve_drop_in_place(*self.tcx, place.layout.ty);
|
|
|
|
(instance, place)
|
2018-08-24 14:44:30 +02:00
|
|
|
}
|
|
|
|
_ => (instance, place),
|
|
|
|
};
|
2021-11-28 19:35:50 -05:00
|
|
|
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;
|
2018-08-24 14:44:30 +02:00
|
|
|
|
2020-04-13 17:07:54 +02:00
|
|
|
let arg = ImmTy::from_immediate(
|
2021-07-12 18:22:15 +02:00
|
|
|
place.to_ref(self),
|
2020-04-13 17:07:54 +02:00
|
|
|
self.layout_of(self.tcx.mk_mut_ptr(place.layout.ty))?,
|
|
|
|
);
|
2022-07-14 11:40:47 -04:00
|
|
|
let ret = MPlaceTy::fake_alloc_zst(self.layout_of(self.tcx.types.unit)?);
|
2018-08-24 14:44:30 +02:00
|
|
|
|
|
|
|
self.eval_fn_call(
|
2019-06-30 13:51:18 +02:00
|
|
|
FnVal::Instance(instance),
|
2021-11-28 19:35:50 -05:00
|
|
|
(Abi::Rust, fn_abi),
|
2019-02-08 12:20:55 +01:00
|
|
|
&[arg.into()],
|
2021-11-28 19:35:50 -05:00
|
|
|
false,
|
2022-07-04 11:46:10 -04:00
|
|
|
&ret.into(),
|
2022-04-16 09:27:54 -04:00
|
|
|
Some(target),
|
2021-05-26 00:51:51 +08:00
|
|
|
match unwind {
|
|
|
|
Some(cleanup) => StackPopUnwind::Cleanup(cleanup),
|
|
|
|
None => StackPopUnwind::Skip,
|
|
|
|
},
|
2018-08-24 14:44:30 +02:00
|
|
|
)
|
|
|
|
}
|
2016-09-20 12:52:01 +02:00
|
|
|
}
|