]> git.lizzy.rs Git - rust.git/blobdiff - src/diagnostics.rs
Auto merge of #1721 - henryboisdequin:add-atomic-min-and-max, r=oli-obk
[rust.git] / src / diagnostics.rs
index a20e8126c13aeb0619111afa9006cd1625bdce4c..45c0996355bffd43238dd1b4a7436aa395708d1e 100644 (file)
@@ -1,5 +1,6 @@
 use std::cell::RefCell;
 use std::fmt;
+use std::num::NonZeroU64;
 
 use log::trace;
 
@@ -11,7 +12,7 @@
 /// Details of premature program termination.
 pub enum TerminationInfo {
     Exit(i64),
-    Abort(Option<String>),
+    Abort(String),
     UnsupportedInIsolation(String),
     ExperimentalUb { msg: String, url: String },
     Deadlock,
@@ -23,10 +24,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match self {
             Exit(code) =>
                 write!(f, "the evaluated program completed with exit code {}", code),
-            Abort(None) =>
-                write!(f, "the evaluated program aborted execution"),
-            Abort(Some(msg)) =>
-                write!(f, "the evaluated program aborted execution: {}", msg),
+            Abort(msg) =>
+                write!(f, "{}", msg),
             UnsupportedInIsolation(msg) =>
                 write!(f, "{}", msg),
             ExperimentalUb { msg, .. } =>
@@ -41,6 +40,7 @@ impl MachineStopType for TerminationInfo {}
 
 /// Miri specific diagnostics
 pub enum NonHaltingDiagnostic {
+    CreatedPointerTag(NonZeroU64),
     PoppedPointerTag(Item),
     CreatedCallId(CallId),
     CreatedAlloc(AllocId),
@@ -54,7 +54,7 @@ pub fn report_error<'tcx, 'mir>(
 ) -> Option<i64> {
     use InterpError::*;
 
-    let (title, helps) = match &e.kind {
+    let (title, helps) = match &e.kind() {
         MachineStop(info) => {
             let info = info.downcast_ref::<TerminationInfo>().expect("invalid MachineStop payload");
             use TerminationInfo::*;
@@ -81,28 +81,31 @@ pub fn report_error<'tcx, 'mir>(
             (title, helps)
         }
         _ => {
-            let title = match e.kind {
+            let title = match e.kind() {
                 Unsupported(_) =>
                     "unsupported operation",
                 UndefinedBehavior(_) =>
                     "Undefined Behavior",
                 ResourceExhaustion(_) =>
                     "resource exhaustion",
+                InvalidProgram(InvalidProgramInfo::ReferencedConstant) =>
+                    "post-monomorphization error",
                 _ =>
                     bug!("This error should be impossible in Miri: {}", e),
             };
-            let helps = match e.kind {
+            let helps = match e.kind() {
                 Unsupported(UnsupportedOpInfo::NoMirFor(..)) =>
                     vec![format!("make sure to use a Miri sysroot, which you can prepare with `cargo miri setup`")],
                 Unsupported(UnsupportedOpInfo::ReadBytesAsPointer | UnsupportedOpInfo::ThreadLocalStatic(_) | UnsupportedOpInfo::ReadExternStatic(_)) =>
-                    panic!("Error should never be raised by Miri: {:?}", e.kind),
+                    panic!("Error should never be raised by Miri: {:?}", e.kind()),
                 Unsupported(_) =>
                     vec![format!("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support")],
-                UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed { .. }) =>
+                UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed { .. })
+                    if ecx.memory.extra.check_alignment == AlignmentCheck::Symbolic
+                =>
                     vec![
                         format!("this usually indicates that your program performed an invalid operation and caused Undefined Behavior"),
-                        format!("but alignment errors can also be false positives, see https://github.com/rust-lang/miri/issues/1074"),
-                        format!("you can disable the alignment check with `-Zmiri-disable-alignment-check`, but that could hide true bugs")
+                        format!("but due to `-Zmiri-symbolic-alignment-check`, alignment errors can also be false positives"),
                     ],
                 UndefinedBehavior(_) =>
                     vec![
@@ -130,7 +133,7 @@ pub fn report_error<'tcx, 'mir>(
     }
 
     // Extra output to help debug specific issues.
-    match e.kind {
+    match e.kind() {
         UndefinedBehavior(UndefinedBehaviorInfo::InvalidUninitBytes(Some(access))) => {
             eprintln!(
                 "Uninitialized read occurred at offsets 0x{:x}..0x{:x} into this allocation:",
@@ -225,7 +228,7 @@ fn preprocess_diagnostics(&self) -> TopFrameInfo<'tcx> {
         TopFrameInfo {
             stack_size: this.active_thread_stack().len(),
             instance: Some(frame.instance),
-            span: frame.current_source_info().map_or(DUMMY_SP, |si| si.span),
+            span: frame.current_span(),
         }
     }
 
@@ -263,6 +266,8 @@ fn process_diagnostics(&self, info: TopFrameInfo<'tcx>) {
             for e in diagnostics.drain(..) {
                 use NonHaltingDiagnostic::*;
                 let msg = match e {
+                    CreatedPointerTag(tag) =>
+                        format!("created tag {:?}", tag),
                     PoppedPointerTag(item) =>
                         format!("popped tracked tag for item {:?}", item),
                     CreatedCallId(id) =>