Skip to content

Commit

Permalink
Cleanup dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed May 30, 2019
1 parent 2155f7a commit 5aa0f5c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 149 deletions.
136 changes: 0 additions & 136 deletions src/fn_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
return err!(MachineError("the evaluated program panicked".to_string()));
}

//this.machine.unwinding = true;

// This part is tricky - we need to call BoxMeUp::box_me_up
// on the vtable.
//
Expand Down Expand Up @@ -287,12 +285,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
let temp_ptr = this.allocate(dyn_ptr_layout, MiriMemoryKind::UnwindHelper.into());
this.machine.box_me_up_tmp_ptr = Some(temp_ptr.clone());


// Keep track of our current frame
// This allows us to step throgh the exection of 'box_me_up',
// exiting when we get back to this frame
let cur_frame = this.cur_frame();

this.push_stack_frame(
box_me_up_fn,
box_me_up_mir.span,
Expand All @@ -310,52 +302,6 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
let arg_0 = this.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
this.write_scalar(data_ptr, arg_0)?;

/*// Step through execution of 'box_me_up'
// We know that we're finished when our stack depth
// returns to where it was before.
//
// Note that everything will get completely screwed up
// if 'box_me_up' panics. This is fine, since this
// function should never panic, as it's part of the core
// panic handling infrastructure
//
// Normally, we would just let Miri drive
// the execution of this stack frame.
// However, we need to access its return value
// in order to properly unwind.
//
// When we 'return' from '__rustc_start_panic',
// we need to be executing the panic catch handler.
// Therefore, we take care all all of the unwinding logic
// here, instead of letting the Miri main loop do it
while this.cur_frame() != cur_frame {
this.step()?;
}
// 'box_me_up' has finished. 'temp_ptr' now holds
// a '*mut (dyn Any + Send)'
// We want to split this into its consituient parts -
// the data and vtable pointers - and store them back
// into the panic handler frame
let real_ret = this.read_immediate(temp_ptr.into())?;
let real_ret_data = real_ret.to_scalar_ptr()?;
let real_ret_vtable = real_ret.to_meta()?.expect("Expected fat pointer");
// We're in panic unwind mode. We pop off stack
// frames until one of two things happens: we reach
// a frame with 'catch_panic' set, or we pop of all frames
//
// If we pop off all frames without encountering 'catch_panic',
// we exit.
//
// If we encounter 'catch_panic', we continue execution at that
// frame, filling in data from the panic
//
unwind_stack(this, real_ret_data, real_ret_vtable)?;
this.memory_mut().deallocate(temp_ptr.to_ptr()?, None, MiriMemoryKind::UnwindHelper.into())?;
this.dump_place(*dest.expect("dest is None!"));*/

return Ok(None)

}
Expand Down Expand Up @@ -1165,85 +1111,3 @@ fn gen_random<'a, 'mir, 'tcx>(
this.memory_mut().get_mut(ptr.alloc_id)?
.write_bytes(tcx, ptr, &data)
}

/// A helper method to unwind the stack.
///
/// We execute the 'unwind' blocks associated with frame
/// terminators as we go along (these blocks are responsible
/// for dropping frame locals in the event of a panic)
///
/// When we find our target frame, we write the panic payload
/// directly into its locals, and jump to it.
/// After that, panic handling is done - from the perspective
/// of the caller of '__rust_maybe_catch_panic', the function
/// has 'returned' normally, after which point Miri excecution
/// can proceeed normally.
fn unwind_stack<'a, 'mir, 'tcx>(
this: &mut MiriEvalContext<'a, 'mir, 'tcx>,
payload_data_ptr: Scalar<Tag>,
payload_vtable_ptr: Scalar<Tag>
) -> EvalResult<'tcx> {
while !this.stack().is_empty() {
// When '__rust_maybe_catch_panic' is called, it marks is frame
// with 'catch_panic'. When we find this marker, we've found
// our target frame to jump to.
if let Some(unwind_data) = this.frame_mut().extra.catch_panic.take() {

trace!("unwinding: found target frame: {:?}", this.frame().span);

let data_ptr = unwind_data.data_ptr.clone();
let vtable_ptr = unwind_data.vtable_ptr.clone();
let dest = unwind_data.dest.clone();
let ret = unwind_data.ret.clone();
drop(unwind_data);


// Here, we write directly into the frame of the function
// that called '__rust_maybe_catch_panic'.
// (NOT the function that called '__rust_start_panic')

this.write_scalar(payload_data_ptr, data_ptr.into())?;
this.write_scalar(payload_vtable_ptr, vtable_ptr.into())?;

// We 'return' the value 1 from __rust_maybe_catch_panic,
// since there was a panic
this.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?;

// We're done - continue execution in the frame of the function
// that called '__rust_maybe_catch_panic,'
this.goto_block(Some(ret))?;

return Ok(())
} else {
// This frame is above our target frame on the call stack.
// We pop it off the stack, running its 'unwind' block if applicable
trace!("unwinding: popping frame: {:?}", this.frame().span);
let block = &this.frame().mir.basic_blocks()[this.frame().block];

// All frames in the call stack should be executing their terminators.,
// as that's the only way for a basic block to perform a function call
if let Some(stmt) = block.statements.get(this.frame().stmt) {
panic!("Unexpcted statement '{:?}' for frame {:?}", stmt, this.frame().span);
}

// We're only interested in terminator types which allow for a cleanuup
// block (e.g. Call), and that also actually provide one
if let Some(Some(unwind)) = block.terminator().unwind() {
this.goto_block(Some(*unwind))?;

// Run the 'unwind' block until we encounter
// a 'Resume', which indicates that the block
// is done.
assert_eq!(this.run()?, StepOutcome::Resume);
}

// Pop this frame, and continue on to the next one
//this.pop_stack_frame()?;
//this.pop_stack_frame_unwind()?;
}
}

// We should never get here:
// The 'start_fn' lang item should always install a panic handler
return err!(Unreachable);
}
13 changes: 1 addition & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use std::rc::Rc;
use rand::rngs::StdRng;
use rand::SeedableRng;

use rustc_target::spec::PanicStrategy;
use rustc::ty::{ExistentialPredicate, ExistentialTraitRef, RegionKind, List, ParamEnv};
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
use rustc::ty::layout::{LayoutOf, Size, Align, TyLayout};
Expand Down Expand Up @@ -232,11 +231,6 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>(
}
}

// Cache some data used by unwinding
if ecx.tcx.tcx.sess.panic_strategy() == PanicStrategy::Unwind {

}

assert!(args.next().is_none(), "start lang item has more arguments than expected");

Ok(ecx)
Expand Down Expand Up @@ -330,6 +324,7 @@ pub enum MiriMemoryKind {
C,
/// Part of env var emulation.
Env,
/// Temporary storage for implementing unwinding
UnwindHelper,
/// Mutable statics.
MutStatic,
Expand Down Expand Up @@ -680,7 +675,6 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
let data_ptr = unwind_data.data_ptr.clone();
let vtable_ptr = unwind_data.vtable_ptr.clone();
let dest = unwind_data.dest.clone();
let ret = unwind_data.ret.clone();
drop(unwind_data);


Expand All @@ -697,11 +691,6 @@ impl<'a, 'mir, 'tcx> Machine<'a, 'mir, 'tcx> for Evaluator<'tcx> {
ecx.machine.unwinding = false;

ecx.memory_mut().deallocate(tmp_ptr.to_ptr()?, None, MiriMemoryKind::UnwindHelper.into())?;

// We're done - continue execution in the frame of the function
// that called '__rust_maybe_catch_panic,'
//this.goto_block(Some(ret))?;

}
}
ecx.memory().extra.borrow_mut().end_call(extra.call_id);
Expand Down
1 change: 0 additions & 1 deletion src/stacked_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ trait EvalContextPrivExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
trace!("reborrow: {} reference {:?} derived from {:?} (pointee {}): {:?}, size {}",
kind, new_tag, ptr.tag, place.layout.ty, ptr.erase_tag(), size.bytes());


// Get the allocation. It might not be mutable, so we cannot use `get_mut`.
let alloc = this.memory().get(ptr.alloc_id)?;
alloc.check_bounds(this, ptr, size, CheckInAllocMsg::InboundsTest)?;
Expand Down

0 comments on commit 5aa0f5c

Please sign in to comment.