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