@@ -4,54 +4,78 @@ use rustc_span::DUMMY_SP;
4
4
5
5
use crate :: * ;
6
6
7
+ /// Details of premature program termination.
8
+ pub enum TerminationInfo {
9
+ Exit ( i64 ) ,
10
+ Abort ( Option < String > ) ,
11
+ UnsupportedInIsolation ( String ) ,
12
+ }
13
+
7
14
/// Miri specific diagnostics
8
15
pub enum NonHaltingDiagnostic {
9
16
PoppedTrackedPointerTag ( Item ) ,
10
17
CreatedAlloc ( AllocId ) ,
11
18
}
12
19
13
20
/// Emit a custom diagnostic without going through the miri-engine machinery
14
- pub fn report_diagnostic < ' tcx , ' mir > (
21
+ pub fn report_error < ' tcx , ' mir > (
15
22
ecx : & InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
16
23
mut e : InterpErrorInfo < ' tcx > ,
17
24
) -> Option < i64 > {
18
25
use InterpError :: * ;
19
- let title = match e. kind {
20
- Unsupported ( _) => "unsupported operation" ,
21
- UndefinedBehavior ( _) => "Undefined Behavior" ,
22
- InvalidProgram ( _) => bug ! ( "This error should be impossible in Miri: {}" , e) ,
23
- ResourceExhaustion ( _) => "resource exhaustion" ,
24
- MachineStop ( _) => "program stopped" ,
25
- } ;
26
- let msg = match e. kind {
27
- MachineStop ( ref info) => {
26
+
27
+ e. print_backtrace ( ) ;
28
+ let ( title, msg, help) = match e. kind {
29
+ MachineStop ( info) => {
28
30
let info = info. downcast_ref :: < TerminationInfo > ( ) . expect ( "invalid MachineStop payload" ) ;
29
- match info {
30
- TerminationInfo :: Exit ( code) => return Some ( * code) ,
31
- TerminationInfo :: Abort ( None ) => format ! ( "the evaluated program aborted execution" ) ,
32
- TerminationInfo :: Abort ( Some ( msg) ) => format ! ( "the evaluated program aborted execution: {}" , msg) ,
33
- }
31
+ use TerminationInfo :: * ;
32
+ let ( title, msg) = match info {
33
+ Exit ( code) => return Some ( * code) ,
34
+ Abort ( None ) =>
35
+ ( "abnormal termination" , format ! ( "the evaluated program aborted execution" ) ) ,
36
+ Abort ( Some ( msg) ) =>
37
+ ( "abnormal termination" , format ! ( "the evaluated program aborted execution: {}" , msg) ) ,
38
+ UnsupportedInIsolation ( msg) =>
39
+ ( "unsupported operation" , format ! ( "{}" , msg) ) ,
40
+ } ;
41
+ let help = match info {
42
+ UnsupportedInIsolation ( _) =>
43
+ Some ( "pass the flag `-Zmiri-disable-isolation` to disable isolation" ) ,
44
+ _ => None ,
45
+ } ;
46
+ ( title, msg, help)
47
+ }
48
+ _ => {
49
+ let ( title, msg) = match e. kind {
50
+ Unsupported ( _) =>
51
+ ( "unsupported operation" , e. to_string ( ) ) ,
52
+ UndefinedBehavior ( _) =>
53
+ ( "Undefined Behavior" , e. to_string ( ) ) ,
54
+ ResourceExhaustion ( _) =>
55
+ ( "resource exhaustion" , e. to_string ( ) ) ,
56
+ _ =>
57
+ bug ! ( "This error should be impossible in Miri: {}" , e) ,
58
+ } ;
59
+ let help = match e. kind {
60
+ Unsupported ( UnsupportedOpInfo :: NoMirFor ( ..) ) =>
61
+ Some ( "set `MIRI_SYSROOT` to a Miri sysroot, which you can prepare with `cargo miri setup`" ) ,
62
+ Unsupported ( _) =>
63
+ Some ( "this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support" ) ,
64
+ UndefinedBehavior ( UndefinedBehaviorInfo :: UbExperimental ( _) ) =>
65
+ Some ( "this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental" ) ,
66
+ UndefinedBehavior ( _) =>
67
+ Some ( "this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior" ) ,
68
+ _ => None ,
69
+ } ;
70
+ ( title, msg, help)
34
71
}
35
- _ => e. to_string ( ) ,
36
- } ;
37
- let help = match e. kind {
38
- Unsupported ( UnsupportedOpInfo :: NoMirFor ( ..) ) =>
39
- Some ( "set `MIRI_SYSROOT` to a Miri sysroot, which you can prepare with `cargo miri setup`" ) ,
40
- Unsupported ( _) =>
41
- Some ( "this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support" ) ,
42
- UndefinedBehavior ( UndefinedBehaviorInfo :: UbExperimental ( _) ) =>
43
- Some ( "this indicates a potential bug in the program: it violated *experimental* rules, and caused Undefined Behavior" ) ,
44
- UndefinedBehavior ( _) =>
45
- Some ( "this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior" ) ,
46
- _ => None ,
47
72
} ;
48
- e. print_backtrace ( ) ;
49
73
report_msg ( ecx, & format ! ( "{}: {}" , title, msg) , msg, help, true )
50
74
}
51
75
52
76
/// Report an error or note (depending on the `error` argument) at the current frame's current statement.
53
77
/// Also emits a full stacktrace of the interpreter stack.
54
- pub fn report_msg < ' tcx , ' mir > (
78
+ fn report_msg < ' tcx , ' mir > (
55
79
ecx : & InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
56
80
title : & str ,
57
81
span_msg : String ,
0 commit comments