let link_name = link_name.get().trim_end_matches("$UNIX2003");
let tcx = &{this.tcx.tcx};
- // First: functions that could diverge.
+ // First: functions that diverge.
match link_name {
"__rust_start_panic" | "panic_impl" => {
return err!(MachineError("the evaluated program panicked".to_string()));
}
+ "exit" => {
+ let code = this.read_scalar(args[0])?.to_i32()?;
+ return err!(Exit(code));
+ }
_ => if dest.is_none() {
return err!(Unimplemented(
format!("can't call diverging foreign function: {}", link_name),
}
}
Err(mut e) => {
+ // Special treatment for some error kinds
+ let msg = match e.kind {
+ InterpError::Exit(code) => std::process::exit(code),
+ InterpError::NoMirFor(..) =>
+ format!("{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.", e),
+ _ => e.to_string()
+ };
e.print_backtrace();
if let Some(frame) = ecx.stack().last() {
let block = &frame.mir.basic_blocks()[frame.block];
block.terminator().source_info.span
};
- let e = e.to_string();
- let msg = format!("constant evaluation error: {}", e);
+ let msg = format!("Miri evaluation error: {}", msg);
let mut err = struct_error(ecx.tcx.tcx.at(span), msg.as_str());
let frames = ecx.generate_stacktrace(None);
- err.span_label(span, e);
+ err.span_label(span, msg);
// We iterate with indices because we need to look at the next frame (the caller).
for idx in 0..frames.len() {
let frame_info = &frames[idx];
}
err.emit();
} else {
- ecx.tcx.sess.err(&e.to_string());
+ ecx.tcx.sess.err(&msg);
}
for (i, frame) in ecx.stack().iter().enumerate() {