Skip to content

Commit ae38f48

Browse files
committed
Auto merge of #1092 - RalfJung:rustup, r=RalfJung
Rustup
2 parents cde718f + dcdd68b commit ae38f48

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4007d4ef26eab44bdabc2b7574d032152264d3ad
1+
f5c81e0a986e4285d3d0fd781a1bd475753eb12c

src/eval.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ pub struct MiriConfig {
2424
pub seed: Option<u64>,
2525
}
2626

27+
/// Details of premature program termination.
28+
pub enum TerminationInfo {
29+
Exit(i64),
30+
Abort,
31+
}
32+
2733
/// Returns a freshly created `InterpCx`, along with an `MPlaceTy` representing
2834
/// the location where the return value of the `start` lang item will be
2935
/// written to.
@@ -200,7 +206,15 @@ pub fn eval_main<'tcx>(tcx: TyCtxt<'tcx>, main_id: DefId, config: MiriConfig) ->
200206
Err(mut e) => {
201207
// Special treatment for some error kinds
202208
let msg = match e.kind {
203-
InterpError::Exit(code) => return Some(code.into()),
209+
InterpError::MachineStop(ref info) => {
210+
let info = info.downcast_ref::<TerminationInfo>()
211+
.expect("invalid MachineStop payload");
212+
match info {
213+
TerminationInfo::Exit(code) => return Some(*code),
214+
TerminationInfo::Abort =>
215+
format!("the evaluated program aborted execution")
216+
}
217+
}
204218
err_unsup!(NoMirFor(..)) =>
205219
format!("{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.", e),
206220
_ => e.to_string()

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use crate::machine::{
4747
PAGE_SIZE, STACK_ADDR, STACK_SIZE, NUM_CPUS,
4848
MemoryExtra, AllocExtra, MiriMemoryKind, Evaluator, MiriEvalContext, MiriEvalContextExt,
4949
};
50-
pub use crate::eval::{eval_main, create_ecx, MiriConfig};
50+
pub use crate::eval::{eval_main, create_ecx, MiriConfig, TerminationInfo};
5151

5252
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
5353
/// set per default, for maximal validation power.

src/shims/foreign_items.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
152152
}
153153

154154
"exit" | "ExitProcess" => {
155-
// it's really u32 for ExitProcess, but we have to put it into the `Exit` error variant anyway
155+
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
156156
let code = this.read_scalar(args[0])?.to_i32()?;
157-
return Err(InterpError::Exit(code).into());
157+
let ti = Box::new(TerminationInfo::Exit(code.into()));
158+
return Err(InterpError::MachineStop(ti).into());
158159
}
159160
_ => {
160161
if let Some(p) = ret {

src/shims/intrinsics.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3434
// Handle diverging intrinsics.
3535
let (dest, ret) = match intrinsic_name {
3636
"abort" => {
37-
// FIXME: Add a better way of indicating 'abnormal' termination,
38-
// since this is not really an 'unsupported' behavior
39-
throw_unsup_format!("the evaluated program aborted!");
37+
let ti = Box::new(TerminationInfo::Abort);
38+
return Err(InterpError::MachineStop(ti).into());
4039
}
4140
"miri_start_panic" => return this.handle_miri_start_panic(args, unwind),
4241
_ => {

tests/compile-fail/double_panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//error-pattern: the evaluated program aborted
1+
// error-pattern: the evaluated program aborted
22
struct Foo;
33
impl Drop for Foo {
44
fn drop(&mut self) {

tests/run-pass/catch_panic.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,13 @@ fn test(do_panic: impl FnOnce(usize) -> !) {
7070
do_panic_counter(do_panic)
7171
})).expect_err("do_panic() did not panic!");
7272

73-
// See if we can extract panic message.
74-
match res.downcast::<String>() {
75-
Ok(s) => {
76-
eprintln!("Caught panic message (String): {}", s);
77-
}
78-
Err(res) =>
79-
if let Ok(s) = res.downcast::<&str>() {
80-
eprintln!("Caught panic message (&str): {}", s);
81-
} else {
82-
eprintln!("Failed get caught panic message.");
83-
}
73+
// See if we can extract the panic message.
74+
if let Some(s) = res.downcast_ref::<String>() {
75+
eprintln!("Caught panic message (String): {}", s);
76+
} else if let Some(s) = res.downcast_ref::<&str>() {
77+
eprintln!("Caught panic message (&str): {}", s);
78+
} else {
79+
eprintln!("Failed get caught panic message.");
8480
}
8581

8682
// Test flags.

0 commit comments

Comments
 (0)