Skip to content

Commit bac37e6

Browse files
committed
Merge branch 'wip'
2 parents b24edd6 + 16f778a commit bac37e6

File tree

3 files changed

+60
-28
lines changed

3 files changed

+60
-28
lines changed

src/bin/miri.rs

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
7878

7979
fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
8080
let frame = ecx.stack().last().expect("stackframe was empty");
81-
let block = &frame.mir.basic_blocks()[frame.next_block];
81+
let block = &frame.mir.basic_blocks()[frame.block];
8282
let span = if frame.stmt < block.statements.len() {
8383
block.statements[frame.stmt].source_info.span
8484
} else {
@@ -101,12 +101,6 @@ fn report(tcx: TyCtxt, ecx: &EvalContext, e: EvalError) {
101101
err.emit();
102102
}
103103

104-
fn main() {
105-
init_logger();
106-
let args: Vec<String> = std::env::args().collect();
107-
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
108-
}
109-
110104
fn init_logger() {
111105
const NSPACES: usize = 40;
112106
let format = |record: &log::LogRecord| {
@@ -130,3 +124,28 @@ fn init_logger() {
130124

131125
builder.init().unwrap();
132126
}
127+
128+
fn find_sysroot() -> String {
129+
// Taken from https://github.com/Manishearth/rust-clippy/pull/911.
130+
let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME"));
131+
let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN"));
132+
match (home, toolchain) {
133+
(Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain),
134+
_ => option_env!("RUST_SYSROOT")
135+
.expect("need to specify RUST_SYSROOT env var or use rustup or multirust")
136+
.to_owned(),
137+
}
138+
}
139+
140+
fn main() {
141+
init_logger();
142+
let mut args: Vec<String> = std::env::args().collect();
143+
144+
let sysroot_flag = String::from("--sysroot");
145+
if !args.contains(&sysroot_flag) {
146+
args.push(sysroot_flag);
147+
args.push(find_sysroot());
148+
}
149+
150+
rustc_driver::run_compiler(&args, &mut MiriCompilerCalls);
151+
}

src/interpreter/mod.rs

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub struct EvalContext<'a, 'tcx: 'a> {
4242
/// The virtual memory system.
4343
memory: Memory<'tcx>,
4444

45-
/// Precomputed statics, constants and promoteds
45+
/// Precomputed statics, constants and promoteds.
4646
statics: HashMap<ConstantId<'tcx>, Pointer>,
4747

4848
/// The virtual call stack.
@@ -51,20 +51,25 @@ pub struct EvalContext<'a, 'tcx: 'a> {
5151

5252
/// A stack frame.
5353
pub struct Frame<'a, 'tcx: 'a> {
54-
/// The def_id of the current function
55-
pub def_id: DefId,
54+
////////////////////////////////////////////////////////////////////////////////
55+
// Function and callsite information
56+
////////////////////////////////////////////////////////////////////////////////
5657

57-
/// The span of the call site
58-
pub span: codemap::Span,
58+
/// The MIR for the function called on this frame.
59+
pub mir: CachedMir<'a, 'tcx>,
60+
61+
/// The def_id of the current function.
62+
pub def_id: DefId,
5963

60-
/// type substitutions for the current function invocation
64+
/// type substitutions for the current function invocation.
6165
pub substs: &'tcx Substs<'tcx>,
6266

63-
/// The MIR for the function called on this frame.
64-
pub mir: CachedMir<'a, 'tcx>,
67+
/// The span of the call site.
68+
pub span: codemap::Span,
6569

66-
/// The block that is currently executed (or will be executed after the above call stacks return)
67-
pub next_block: mir::BasicBlock,
70+
////////////////////////////////////////////////////////////////////////////////
71+
// Return pointer and local allocations
72+
////////////////////////////////////////////////////////////////////////////////
6873

6974
/// A pointer for writing the return value of the current call if it's not a diverging call.
7075
pub return_ptr: Option<Pointer>,
@@ -80,7 +85,15 @@ pub struct Frame<'a, 'tcx: 'a> {
8085
/// The offset of the first temporary in `self.locals`.
8186
pub temp_offset: usize,
8287

83-
/// The index of the currently evaluated statment
88+
////////////////////////////////////////////////////////////////////////////////
89+
// Current position within the function
90+
////////////////////////////////////////////////////////////////////////////////
91+
92+
/// The block that is currently executed (or will be executed after the above call stacks
93+
/// return).
94+
pub block: mir::BasicBlock,
95+
96+
/// The index of the currently evaluated statment.
8497
pub stmt: usize,
8598
}
8699

@@ -353,7 +366,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
353366

354367
self.stack.push(Frame {
355368
mir: mir.clone(),
356-
next_block: mir::START_BLOCK,
369+
block: mir::START_BLOCK,
357370
return_ptr: return_ptr,
358371
locals: locals,
359372
var_offset: num_args,
@@ -378,13 +391,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
378391
Return => self.pop_stack_frame(),
379392

380393
Goto { target } => {
381-
self.frame_mut().next_block = target;
394+
self.frame_mut().block = target;
382395
},
383396

384397
If { ref cond, targets: (then_target, else_target) } => {
385398
let cond_ptr = self.eval_operand(cond)?;
386399
let cond_val = self.memory.read_bool(cond_ptr)?;
387-
self.frame_mut().next_block = if cond_val { then_target } else { else_target };
400+
self.frame_mut().block = if cond_val { then_target } else { else_target };
388401
}
389402

390403
SwitchInt { ref discr, ref values, ref targets, .. } => {
@@ -407,7 +420,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
407420
}
408421
}
409422

410-
self.frame_mut().next_block = target_block;
423+
self.frame_mut().block = target_block;
411424
}
412425

413426
Switch { ref discr, ref targets, adt_def } => {
@@ -419,7 +432,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
419432

420433
match matching {
421434
Some(i) => {
422-
self.frame_mut().next_block = targets[i];
435+
self.frame_mut().block = targets[i];
423436
},
424437
None => return Err(EvalError::InvalidDiscriminant),
425438
}
@@ -428,7 +441,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
428441
Call { ref func, ref args, ref destination, .. } => {
429442
let mut return_ptr = None;
430443
if let Some((ref lv, target)) = *destination {
431-
self.frame_mut().next_block = target;
444+
self.frame_mut().block = target;
432445
return_ptr = Some(self.eval_lvalue(lv)?.to_ptr());
433446
}
434447

@@ -458,14 +471,14 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
458471
let ptr = self.eval_lvalue(location)?.to_ptr();
459472
let ty = self.lvalue_ty(location);
460473
self.drop(ptr, ty)?;
461-
self.frame_mut().next_block = target;
474+
self.frame_mut().block = target;
462475
}
463476

464477
Assert { ref cond, expected, ref msg, target, cleanup } => {
465478
let actual_ptr = self.eval_operand(cond)?;
466479
let actual = self.memory.read_bool(actual_ptr)?;
467480
if actual == expected {
468-
self.frame_mut().next_block = target;
481+
self.frame_mut().block = target;
469482
} else {
470483
panic!("unimplemented: jump to {:?} and print {:?}", cleanup, msg);
471484
}

src/interpreter/stepper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> {
3737
trace!("{:?}", terminator.kind);
3838
self.ecx.eval_terminator(terminator)?;
3939
if !self.ecx.stack.is_empty() {
40-
trace!("// {:?}", self.ecx.frame().next_block);
40+
trace!("// {:?}", self.ecx.frame().block);
4141
}
4242
Ok(())
4343
}
@@ -48,7 +48,7 @@ impl<'ecx, 'a, 'tcx> Stepper<'ecx, 'a, 'tcx> {
4848
return Ok(false);
4949
}
5050

51-
let block = self.ecx.frame().next_block;
51+
let block = self.ecx.frame().block;
5252
let stmt = self.ecx.frame().stmt;
5353
let mir = self.ecx.mir();
5454
let basic_block = &mir.basic_blocks()[block];

0 commit comments

Comments
 (0)