From 269f70007f28cf63aada3a6547f968ea68cb7040 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Tue, 14 Jun 2016 19:30:59 -0600 Subject: [PATCH 1/2] Get the sysroot (like compiletest) in Miri itself. --- src/bin/miri.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index f14eb39439ef6..a29e44cf96066 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -113,12 +113,6 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) { err.emit(); } -fn main() { - init_logger(); - let args: Vec = std::env::args().collect(); - rustc_driver::run_compiler(&args, &mut MiriCompilerCalls); -} - fn init_logger() { const NSPACES: usize = 40; let format = |record: &log::LogRecord| { @@ -142,3 +136,28 @@ fn init_logger() { builder.init().unwrap(); } + +fn find_sysroot() -> String { + // Taken from https://github.com/Manishearth/rust-clippy/pull/911. + let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); + let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); + match (home, toolchain) { + (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), + _ => option_env!("RUST_SYSROOT") + .expect("need to specify RUST_SYSROOT env var or use rustup or multirust") + .to_owned(), + } +} + +fn main() { + init_logger(); + let mut args: Vec = std::env::args().collect(); + + let sysroot_flag = String::from("--sysroot"); + if !args.contains(&sysroot_flag) { + args.push(sysroot_flag); + args.push(find_sysroot()); + } + + rustc_driver::run_compiler(&args, &mut MiriCompilerCalls); +} From 16f778ad207650c0c9f4e049953f5dda2c48ec12 Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Tue, 14 Jun 2016 20:13:59 -0600 Subject: [PATCH 2/2] Rename next_block to block and reorganize Frame fields. --- src/bin/miri.rs | 2 +- src/interpreter/mod.rs | 51 ++++++++++++++++++++++++-------------- src/interpreter/stepper.rs | 4 +-- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index a29e44cf96066..2d6cf22d58958 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -90,7 +90,7 @@ fn interpret_start_points<'a, 'tcx>( fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) { let frame = ecx.stack().last().expect("stackframe was empty"); - let block = &frame.mir.basic_blocks()[frame.next_block]; + let block = &frame.mir.basic_blocks()[frame.block]; let span = if frame.stmt < block.statements.len() { block.statements[frame.stmt].source_info.span } else { diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 1b0b416e0e12c..8b69fc6c2483c 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -42,7 +42,7 @@ pub struct EvalContext<'a, 'tcx: 'a> { /// The virtual memory system. memory: Memory<'tcx>, - /// Precomputed statics, constants and promoteds + /// Precomputed statics, constants and promoteds. statics: HashMap, Pointer>, /// The virtual call stack. @@ -51,20 +51,25 @@ pub struct EvalContext<'a, 'tcx: 'a> { /// A stack frame. pub struct Frame<'a, 'tcx: 'a> { - /// The def_id of the current function - pub def_id: DefId, + //////////////////////////////////////////////////////////////////////////////// + // Function and callsite information + //////////////////////////////////////////////////////////////////////////////// - /// The span of the call site - pub span: codemap::Span, + /// The MIR for the function called on this frame. + pub mir: CachedMir<'a, 'tcx>, + + /// The def_id of the current function. + pub def_id: DefId, - /// type substitutions for the current function invocation + /// type substitutions for the current function invocation. pub substs: &'tcx Substs<'tcx>, - /// The MIR for the function called on this frame. - pub mir: CachedMir<'a, 'tcx>, + /// The span of the call site. + pub span: codemap::Span, - /// The block that is currently executed (or will be executed after the above call stacks return) - pub next_block: mir::BasicBlock, + //////////////////////////////////////////////////////////////////////////////// + // Return pointer and local allocations + //////////////////////////////////////////////////////////////////////////////// /// A pointer for writing the return value of the current call if it's not a diverging call. pub return_ptr: Option, @@ -80,7 +85,15 @@ pub struct Frame<'a, 'tcx: 'a> { /// The offset of the first temporary in `self.locals`. pub temp_offset: usize, - /// The index of the currently evaluated statment + //////////////////////////////////////////////////////////////////////////////// + // Current position within the function + //////////////////////////////////////////////////////////////////////////////// + + /// The block that is currently executed (or will be executed after the above call stacks + /// return). + pub block: mir::BasicBlock, + + /// The index of the currently evaluated statment. pub stmt: usize, } @@ -349,7 +362,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { self.stack.push(Frame { mir: mir.clone(), - next_block: mir::START_BLOCK, + block: mir::START_BLOCK, return_ptr: return_ptr, locals: locals, var_offset: num_args, @@ -374,13 +387,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { Return => self.pop_stack_frame(), Goto { target } => { - self.frame_mut().next_block = target; + self.frame_mut().block = target; }, If { ref cond, targets: (then_target, else_target) } => { let cond_ptr = self.eval_operand(cond)?; let cond_val = self.memory.read_bool(cond_ptr)?; - self.frame_mut().next_block = if cond_val { then_target } else { else_target }; + self.frame_mut().block = if cond_val { then_target } else { else_target }; } SwitchInt { ref discr, ref values, ref targets, .. } => { @@ -403,7 +416,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { } } - self.frame_mut().next_block = target_block; + self.frame_mut().block = target_block; } Switch { ref discr, ref targets, adt_def } => { @@ -415,7 +428,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { match matching { Some(i) => { - self.frame_mut().next_block = targets[i]; + self.frame_mut().block = targets[i]; }, None => return Err(EvalError::InvalidDiscriminant), } @@ -424,7 +437,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { Call { ref func, ref args, ref destination, .. } => { let mut return_ptr = None; if let Some((ref lv, target)) = *destination { - self.frame_mut().next_block = target; + self.frame_mut().block = target; return_ptr = Some(self.eval_lvalue(lv)?.to_ptr()); } @@ -451,14 +464,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> { let ptr = self.eval_lvalue(location)?.to_ptr(); let ty = self.lvalue_ty(location); self.drop(ptr, ty)?; - self.frame_mut().next_block = target; + self.frame_mut().block = target; } Assert { ref cond, expected, ref msg, target, cleanup } => { let actual_ptr = self.eval_operand(cond)?; let actual = self.memory.read_bool(actual_ptr)?; if actual == expected { - self.frame_mut().next_block = target; + self.frame_mut().block = target; } else { panic!("unimplemented: jump to {:?} and print {:?}", cleanup, msg); } diff --git a/src/interpreter/stepper.rs b/src/interpreter/stepper.rs index 8603054d124c2..e92ddd1faa2df 100644 --- a/src/interpreter/stepper.rs +++ b/src/interpreter/stepper.rs @@ -37,7 +37,7 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> { trace!("{:?}", terminator.kind); self.ecx.eval_terminator(terminator)?; if !self.ecx.stack.is_empty() { - trace!("// {:?}", self.ecx.frame().next_block); + trace!("// {:?}", self.ecx.frame().block); } Ok(()) } @@ -48,7 +48,7 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> { return Ok(false); } - let block = self.ecx.frame().next_block; + let block = self.ecx.frame().block; let stmt = self.ecx.frame().stmt; let mir = self.ecx.mir(); let basic_block = &mir.basic_blocks()[block];