-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #814 - RalfJung:shims, r=RalfJung
move find_fn (which is not specific to foreign items) out of foreign_item
- Loading branch information
Showing
3 changed files
with
48 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,49 @@ | ||
pub mod foreign_items; | ||
pub mod intrinsics; | ||
|
||
use rustc::{ty, mir}; | ||
|
||
use crate::*; | ||
|
||
impl<'mir, 'tcx> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} | ||
pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { | ||
fn find_fn( | ||
&mut self, | ||
instance: ty::Instance<'tcx>, | ||
args: &[OpTy<'tcx, Tag>], | ||
dest: Option<PlaceTy<'tcx, Tag>>, | ||
ret: Option<mir::BasicBlock>, | ||
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> { | ||
let this = self.eval_context_mut(); | ||
trace!("eval_fn_call: {:#?}, {:?}", instance, dest.map(|place| *place)); | ||
|
||
// First, run the common hooks also supported by CTFE. | ||
if this.hook_fn(instance, args, dest)? { | ||
this.goto_block(ret)?; | ||
return Ok(None); | ||
} | ||
// There are some more lang items we want to hook that CTFE does not hook (yet). | ||
if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) { | ||
// FIXME: return a real value in case the target allocation has an | ||
// alignment bigger than the one requested. | ||
let n = u128::max_value(); | ||
let dest = dest.unwrap(); | ||
let n = this.truncate(n, dest.layout); | ||
this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?; | ||
this.goto_block(ret)?; | ||
return Ok(None); | ||
} | ||
|
||
// Try to see if we can do something about foreign items. | ||
if this.tcx.is_foreign_item(instance.def_id()) { | ||
// An external function that we cannot find MIR for, but we can still run enough | ||
// of them to make miri viable. | ||
this.emulate_foreign_item(instance.def_id(), args, dest, ret)?; | ||
// `goto_block` already handled. | ||
return Ok(None); | ||
} | ||
|
||
// Otherwise, load the MIR. | ||
Ok(Some(this.load_mir(instance.def)?)) | ||
} | ||
} |