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