commit
b916a079d1
@ -1 +1 @@
|
||||
130dc3e7dac132cf30272ccf4541b512828e2108
|
||||
9224be5fa39f6170f6e046342976efee5453a1ff
|
||||
|
@ -149,11 +149,16 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a + 'mir>: crate::MiriEvalContextExt<'
|
||||
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" | "ExitProcess" => {
|
||||
// it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
|
||||
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),
|
||||
|
14
src/lib.rs
14
src/lib.rs
@ -242,6 +242,13 @@ pub fn eval_main<'a, 'tcx: 'a>(
|
||||
}
|
||||
}
|
||||
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];
|
||||
@ -251,11 +258,10 @@ pub fn eval_main<'a, 'tcx: 'a>(
|
||||
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];
|
||||
@ -269,7 +275,7 @@ pub fn eval_main<'a, 'tcx: 'a>(
|
||||
}
|
||||
err.emit();
|
||||
} else {
|
||||
ecx.tcx.sess.err(&e.to_string());
|
||||
ecx.tcx.sess.err(&msg);
|
||||
}
|
||||
|
||||
for (i, frame) in ecx.stack().iter().enumerate() {
|
||||
|
@ -10,6 +10,6 @@ pub fn main() {
|
||||
unsafe {
|
||||
use crate::rusti::*;
|
||||
|
||||
ctlz_nonzero(0u8); //~ ERROR constant evaluation error: ctlz_nonzero called on 0
|
||||
ctlz_nonzero(0u8); //~ ERROR ctlz_nonzero called on 0
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ pub fn main() {
|
||||
unsafe {
|
||||
use crate::rusti::*;
|
||||
|
||||
cttz_nonzero(0u8); //~ ERROR constant evaluation error: cttz_nonzero called on 0
|
||||
cttz_nonzero(0u8); //~ ERROR cttz_nonzero called on 0
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ fn f() {}
|
||||
|
||||
fn main() {
|
||||
let x: u8 = unsafe {
|
||||
*std::mem::transmute::<fn(), *const u8>(f) //~ ERROR constant evaluation error: tried to dereference a function pointer
|
||||
*std::mem::transmute::<fn(), *const u8>(f) //~ ERROR tried to dereference a function pointer
|
||||
};
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ fn main() {
|
||||
let mut buf = [0u8; 5];
|
||||
unsafe {
|
||||
libc::syscall(libc::SYS_getrandom, buf.as_mut_ptr() as *mut libc::c_void, 5 as libc::size_t, 0 as libc::c_uint);
|
||||
//~^ ERROR constant evaluation error: miri does not support gathering system entropy in deterministic mode!
|
||||
//~^ ERROR miri does not support gathering system entropy in deterministic mode!
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ struct Human;
|
||||
|
||||
fn main() {
|
||||
let _x: ! = unsafe {
|
||||
std::mem::transmute::<Human, !>(Human) //~ ERROR constant evaluation error
|
||||
//^~ NOTE entered unreachable code
|
||||
std::mem::transmute::<Human, !>(Human) //~ ERROR entered unreachable code
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR constant evaluation error: invalid use of NULL pointer
|
||||
let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR invalid use of NULL pointer
|
||||
panic!("this should never print: {}", x);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
fn main() {
|
||||
let x: () = unsafe { *std::ptr::null() }; //~ ERROR constant evaluation error: invalid use of NULL pointer
|
||||
let x: () = unsafe { *std::ptr::null() }; //~ ERROR invalid use of NULL pointer
|
||||
panic!("this should never print: {:?}", x);
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
unsafe { *std::ptr::null_mut() = 0i32 }; //~ ERROR constant evaluation error: invalid use of NULL pointer
|
||||
unsafe { *std::ptr::null_mut() = 0i32 }; //~ ERROR invalid use of NULL pointer
|
||||
}
|
||||
|
@ -2,5 +2,5 @@ fn main() {
|
||||
// Not using the () type here, as writes of that type do not even have MIR generated.
|
||||
// Also not assigning directly as that's array initialization, not assignment.
|
||||
let zst_val = [1u8; 0];
|
||||
unsafe { *std::ptr::null_mut() = zst_val }; //~ ERROR constant evaluation error: invalid use of NULL pointer
|
||||
unsafe { *std::ptr::null_mut() = zst_val }; //~ ERROR invalid use of NULL pointer
|
||||
}
|
||||
|
3
tests/run-pass/exit.rs
Normal file
3
tests/run-pass/exit.rs
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
std::process::exit(0)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user