Skip to content

Commit 24a9a14

Browse files
committed
fix various small nits
1 parent 633a34d commit 24a9a14

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/bin/miri.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
9595
state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(limits, tcx, state));
9696
} else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
9797
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
98-
let start_wrapper = tcx.lang_items.start_fn()
99-
.and_then(|start_fn| if tcx.is_mir_available(start_fn) { Some(start_fn) } else { None });
98+
let start_wrapper = tcx.lang_items.start_fn().and_then(|start_fn|
99+
if tcx.is_mir_available(start_fn) { Some(start_fn) } else { None });
100100
miri::eval_main(tcx, entry_def_id, start_wrapper, limits);
101101

102102
state.session.abort_if_errors();

src/eval_context.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
15581558
}
15591559

15601560
pub(super) fn dump_local(&self, lvalue: Lvalue<'tcx>) {
1561+
// Debug output
15611562
if let Lvalue::Local { frame, local, field } = lvalue {
15621563
let mut allocs = Vec::new();
15631564
let mut msg = format!("{:?}", local);
@@ -1744,17 +1745,14 @@ pub fn eval_main<'a, 'tcx: 'a>(
17441745
let ty = ecx.tcx.types.isize;
17451746
let layout = ecx.type_layout(ty)?;
17461747
let size = layout.size(&ecx.tcx.data_layout).bytes();
1747-
let align = layout.align(&ecx.tcx.data_layout).pref(); // FIXME is this right?
1748+
let align = layout.align(&ecx.tcx.data_layout).abi();
17481749
ecx.memory.allocate(size, align)?
17491750
};
17501751
ecx.frame_mut().return_lvalue = Lvalue::from_ptr(ret_ptr);
17511752

1752-
loop {
1753-
if !ecx.step()? {
1754-
ecx.memory.deallocate(ret_ptr)?;
1755-
return Ok(());
1756-
}
1757-
}
1753+
while ecx.step()? {}
1754+
ecx.memory.deallocate(ret_ptr)?;
1755+
return Ok(());
17581756
}
17591757

17601758
let mut ecx = EvalContext::new(tcx, limits);

src/terminator/mod.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
131131
Ok(())
132132
}
133133

134-
/// Decides whether it is okay to call the method with signature `real_sig` using signature `sig`
134+
/// Decides whether it is okay to call the method with signature `real_sig` using signature `sig`.
135+
/// FIXME: This should take into account the platform-dependent ABI description.
135136
fn check_sig_compat(
136137
&mut self,
137138
sig: ty::FnSig<'tcx>,
@@ -284,12 +285,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
284285
trace!("arg_locals: {:?}", self.frame().mir.args_iter().collect::<Vec<_>>());
285286
trace!("arg_operands: {:?}", arg_operands);
286287
match sig.abi {
287-
Abi::Rust | Abi::C => {
288-
for (arg_local, (arg_val, arg_ty)) in arg_locals.zip(args) {
289-
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
290-
self.write_value(arg_val, dest, arg_ty)?;
291-
}
292-
}
293288
Abi::RustCall => {
294289
assert_eq!(args.len(), 2);
295290

@@ -332,8 +327,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
332327
} else {
333328
bug!("rust-call ABI tuple argument was {:?}, {:?}", arg_ty, layout);
334329
}
330+
},
331+
_ => {
332+
for (arg_local, (arg_val, arg_ty)) in arg_locals.zip(args) {
333+
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
334+
self.write_value(arg_val, dest, arg_ty)?;
335+
}
335336
}
336-
_ => unimplemented!(),
337337
}
338338
Ok(())
339339
},
@@ -520,7 +520,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
520520
// Still, we can make many things mostly work by "emulating" or ignoring some functions.
521521
match &path[..] {
522522
"std::io::_print" => {
523-
trace!("Ignoring output.");
523+
trace!("Ignoring output. To run programs that print, make sure you have a libstd with full MIR.");
524524
self.goto_block(destination.unwrap().1);
525525
Ok(())
526526
},
@@ -595,15 +595,16 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
595595
}
596596

597597
"__rust_maybe_catch_panic" => {
598+
// fn __rust_maybe_catch_panic(f: fn(*mut u8), data: *mut u8, data_ptr: *mut usize, vtable_ptr: *mut usize) -> u32
598599
// We abort on panic, so not much is going on here, but we still have to call the closure
599600
let u8_ptr_ty = self.tcx.mk_mut_ptr(self.tcx.types.u8);
600601
let f = args[0].read_ptr(&self.memory)?;
601-
let data = args[1].read_ptr(&self.memory)?; // FIXME: Why does value_to_primval(args[2], u8_ptr_ty)?.to_ptr()? here end up doing the Wrong Thing (TM)?
602+
let data = args[1].read_ptr(&self.memory)?;
602603
let f_instance = self.memory.get_fn(f.alloc_id)?;
603604
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
604605

605-
// Now we make a functon call. TODO: Consider making this re-usable? EvalContext::step does sth. similar for the TLS dtors,
606-
// and of coruse eval_main.
606+
// Now we make a function call. TODO: Consider making this re-usable? EvalContext::step does sth. similar for the TLS dtors,
607+
// and of course eval_main.
607608
let mir = self.load_mir(f_instance.def)?;
608609
self.push_stack_frame(
609610
f_instance,
@@ -614,11 +615,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
614615
)?;
615616

616617
let arg_local = self.frame().mir.args_iter().next().ok_or(EvalError::AbiViolation("Argument to __rust_maybe_catch_panic does not take enough arguments.".to_owned()))?;
617-
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
618-
self.write_value(Value::ByVal(PrimVal::Ptr(data)), dest, u8_ptr_ty)?;
618+
let arg_dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
619+
self.write_value(Value::ByVal(PrimVal::Ptr(data)), arg_dest, u8_ptr_ty)?;
620+
621+
// We ourselbes return 0
622+
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
619623

620624
// Don't fall through
621-
// FIXME: Do we have to do self.dump_local(ret) anywhere?
622625
return Ok(());
623626
}
624627

0 commit comments

Comments
 (0)