10 impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {}
11 pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> {
14 instance: ty::Instance<'tcx>,
15 args: &[OpTy<'tcx, Tag>],
16 dest: Option<PlaceTy<'tcx, Tag>>,
17 ret: Option<mir::BasicBlock>,
18 ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
19 let this = self.eval_context_mut();
20 trace!("eval_fn_call: {:#?}, {:?}", instance, dest.map(|place| *place));
22 // First, run the common hooks also supported by CTFE.
23 if this.hook_fn(instance, args, dest)? {
24 this.goto_block(ret)?;
27 // There are some more lang items we want to hook that CTFE does not hook (yet).
28 if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
29 // FIXME: return a real value in case the target allocation has an
30 // alignment bigger than the one requested.
31 let n = u128::max_value();
32 let dest = dest.unwrap();
33 let n = this.truncate(n, dest.layout);
34 this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?;
35 this.goto_block(ret)?;
39 // Try to see if we can do something about foreign items.
40 if this.tcx.is_foreign_item(instance.def_id()) {
41 // An external function that we cannot find MIR for, but we can still run enough
42 // of them to make miri viable.
43 this.emulate_foreign_item(instance.def_id(), args, dest, ret)?;
44 // `goto_block` already handled.
48 // Otherwise, load the MIR.
49 Ok(Some(this.load_mir(instance.def)?))