Skip to content

Commit

Permalink
Remove trampoline, pass ret and unwind when handling intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Nov 11, 2019
1 parent 607339f commit 4ecb80d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
3 changes: 0 additions & 3 deletions src/libpanic_unwind/lib.rs
Expand Up @@ -39,9 +39,6 @@ cfg_if::cfg_if! {
if #[cfg(miri)] {
#[path = "miri.rs"]
mod imp;
// Export this at the root of the crate so that Miri
// has a stable palce to look it up
pub use imp::miri_panic_trampoline;
} else if #[cfg(target_os = "emscripten")] {
#[path = "emcc.rs"]
mod imp;
Expand Down
5 changes: 0 additions & 5 deletions src/libpanic_unwind/miri.rs
Expand Up @@ -21,8 +21,3 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
fn rust_eh_personality() {
unsafe { core::intrinsics::abort() }
}

// A dummy helper function for Miri.
// Used to push an empty stack frame when we start unwinding
#[cfg(miri)]
pub fn miri_panic_trampoline() {}
2 changes: 2 additions & 0 deletions src/librustc_mir/const_eval.rs
Expand Up @@ -376,6 +376,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx>],
dest: Option<PlaceTy<'tcx>>,
_ret: Option<mir::BasicBlock>,
_unwind: Option<mir::BasicBlock>
) -> InterpResult<'tcx> {
if ecx.emulate_intrinsic(span, instance, args, dest)? {
return Ok(());
Expand Down
16 changes: 6 additions & 10 deletions src/librustc_mir/interpret/eval_context.rs
Expand Up @@ -585,21 +585,17 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
"tried to pop a stack frame, but there were none",
);
let stack_pop_info = M::stack_pop(self, frame.extra, unwinding)?;
match (unwinding, stack_pop_info) {
(true, StackPopInfo::StartUnwinding) =>
bug!("Attempted to start unwinding while already unwinding!"),
(false, StackPopInfo::StopUnwinding) =>
bug!("Attempted to stop unwinding while there is no unwinding!"),
_ => {}
if let (false, StackPopInfo::StopUnwinding) = (unwinding, stack_pop_info) {
bug!("Attempted to stop unwinding while there is no unwinding!");
}

// Now where do we jump next?

// Determine if we leave this function normally or via unwinding.
let cur_unwinding = match stack_pop_info {
StackPopInfo::StartUnwinding => true,
StackPopInfo::StopUnwinding => false,
_ => unwinding
let cur_unwinding = if let StackPopInfo::StopUnwinding = stack_pop_info {
false
} else {
unwinding
};

// Usually we want to clean up (deallocate locals), but in a few rare cases we don't.
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/interpret/machine.rs
Expand Up @@ -20,10 +20,6 @@ use super::{
/// to provide further control over the popping of the stack frame
#[derive(Eq, PartialEq, Debug, Copy, Clone)]
pub enum StackPopInfo {
/// Indicates that we have just started unwinding
/// as the result of panic
StartUnwinding,

/// Indicates that no special handling should be
/// done - we'll either return normally or unwind
/// based on the terminator for the function
Expand Down Expand Up @@ -177,6 +173,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
instance: ty::Instance<'tcx>,
args: &[OpTy<'tcx, Self::PointerTag>],
dest: Option<PlaceTy<'tcx, Self::PointerTag>>,
ret: Option<mir::BasicBlock>,
unwind: Option<mir::BasicBlock>,
) -> InterpResult<'tcx>;

/// Called for read access to a foreign static item.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator.rs
Expand Up @@ -265,7 +265,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
match instance.def {
ty::InstanceDef::Intrinsic(..) => {
let old_stack = self.cur_frame();
M::call_intrinsic(self, span, instance, args, dest)?;
M::call_intrinsic(self, span, instance, args, dest, ret, unwind)?;
// No stack frame gets pushed, the main loop will just act as if the
// call completed.
if ret.is_some() {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -164,6 +164,8 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine {
_instance: ty::Instance<'tcx>,
_args: &[OpTy<'tcx>],
_dest: Option<PlaceTy<'tcx>>,
_ret: Option<BasicBlock>,
_unwind: Option<BasicBlock>
) -> InterpResult<'tcx> {
throw_unsup_format!("calling intrinsics isn't supported in ConstProp");
}
Expand Down

0 comments on commit 4ecb80d

Please sign in to comment.