@@ -4,54 +4,78 @@ use rustc_span::DUMMY_SP;
44
55use crate :: * ;
66
7+ /// Details of premature program termination.
8+ pub enum TerminationInfo {
9+ Exit ( i64 ) ,
10+ Abort ( Option < String > ) ,
11+ UnsupportedInIsolation ( String ) ,
12+ }
13+
714/// Miri specific diagnostics
815pub enum NonHaltingDiagnostic {
916 PoppedTrackedPointerTag ( Item ) ,
1017 CreatedAlloc ( AllocId ) ,
1118}
1219
1320/// 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 > (
1522 ecx : & InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
1623 mut e : InterpErrorInfo < ' tcx > ,
1724) -> Option < i64 > {
1825 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) => {
2830 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)
3471 }
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 ,
4772 } ;
48- e. print_backtrace ( ) ;
4973 report_msg ( ecx, & format ! ( "{}: {}" , title, msg) , msg, help, true )
5074}
5175
5276/// Report an error or note (depending on the `error` argument) at the current frame's current statement.
5377/// Also emits a full stacktrace of the interpreter stack.
54- pub fn report_msg < ' tcx , ' mir > (
78+ fn report_msg < ' tcx , ' mir > (
5579 ecx : & InterpCx < ' mir , ' tcx , Evaluator < ' tcx > > ,
5680 title : & str ,
5781 span_msg : String ,
0 commit comments