]> git.lizzy.rs Git - rust.git/commitdiff
tweak int2ptr diagnostics
authorRalf Jung <post@ralfj.de>
Tue, 28 Jun 2022 12:52:22 +0000 (08:52 -0400)
committerRalf Jung <post@ralfj.de>
Tue, 28 Jun 2022 12:52:22 +0000 (08:52 -0400)
src/diagnostics.rs
src/intptrcast.rs
tests/fail/provenance/strict_provenance_cast.rs
tests/fail/provenance/strict_provenance_cast.stderr
tests/pass/box.stderr
tests/pass/extern_types.stderr

index 83949a75dee05fdd87298c9e7bc0f5f227dbb713..c762b3d8106de6ee662feb630de53eb09233bbee 100644 (file)
@@ -21,6 +21,7 @@ pub enum TerminationInfo {
         help: Option<String>,
         history: Option<TagHistory>,
     },
+    Int2PtrWithStrictProvenance,
     Deadlock,
     MultipleSymbolDefinitions {
         link_name: Symbol,
@@ -42,6 +43,11 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
             Exit(code) => write!(f, "the evaluated program completed with exit code {}", code),
             Abort(msg) => write!(f, "{}", msg),
             UnsupportedInIsolation(msg) => write!(f, "{}", msg),
+            Int2PtrWithStrictProvenance =>
+                write!(
+                    f,
+                    "integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`"
+                ),
             StackedBorrowsUb { msg, .. } => write!(f, "{}", msg),
             Deadlock => write!(f, "the evaluated program deadlocked"),
             MultipleSymbolDefinitions { link_name, .. } =>
@@ -148,7 +154,8 @@ pub fn report_error<'tcx, 'mir>(
             let title = match info {
                 Exit(code) => return Some(*code),
                 Abort(_) => Some("abnormal termination"),
-                UnsupportedInIsolation(_) => Some("unsupported operation"),
+                UnsupportedInIsolation(_) | Int2PtrWithStrictProvenance =>
+                    Some("unsupported operation"),
                 StackedBorrowsUb { .. } => Some("Undefined Behavior"),
                 Deadlock => Some("deadlock"),
                 MultipleSymbolDefinitions { .. } | SymbolShimClashing { .. } => None,
@@ -177,7 +184,7 @@ pub fn report_error<'tcx, 'mir>(
                             }
                             if let Some((protecting_tag, protecting_tag_span, protection_span)) = protected {
                                 helps.push((Some(*protecting_tag_span), format!("{:?} was protected due to {:?} which was created here", tag, protecting_tag)));
-                                helps.push((Some(*protection_span), "this protector is live for this call".to_string()));
+                                helps.push((Some(*protection_span), format!("this protector is live for this call")));
                             }
                         }
                         None => {}
@@ -191,6 +198,8 @@ pub fn report_error<'tcx, 'mir>(
                     ],
                 SymbolShimClashing { link_name, span } =>
                     vec![(Some(*span), format!("the `{}` symbol is defined here", link_name))],
+                Int2PtrWithStrictProvenance =>
+                    vec![(None, format!("use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead"))],
                 _ => vec![],
             };
             (title, helps)
@@ -471,12 +480,12 @@ fn process_diagnostics(&self, info: TopFrameInfo<'tcx>) {
                 let helps = match e {
                     Int2Ptr { details: true } =>
                         vec![
-                            (None, format!("this program is using integer-to-pointer casts or (equivalently) `from_exposed_addr`,")),
-                            (None, format!("which means that Miri might miss pointer bugs in this program")),
-                            (None, format!("see https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation")),
-                            (None, format!("to ensure that Miri does not miss bugs in your program, use `with_addr` (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) instead")),
-                            (None, format!("you can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics")),
-                            (None, format!("alternatively, the `-Zmiri-permissive-provenance` flag disables this warning")),
+                            (None, format!("This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,")),
+                            (None, format!("which means that Miri might miss pointer bugs in this program.")),
+                            (None, format!("See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.")),
+                            (None, format!("To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.")),
+                            (None, format!("You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.")),
+                            (None, format!("Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.")),
                         ],
                     _ => vec![],
                 };
index 0ebc62ebbfb198b3701290c01d382283a1e95215..5a33ada450443798b129c252120a6cefc3103f56 100644 (file)
@@ -146,9 +146,7 @@ pub fn ptr_from_addr_cast(
                 });
             }
             ProvenanceMode::Strict => {
-                throw_unsup_format!(
-                    "integer-to-pointer casts and `from_exposed_addr` are not supported with `-Zmiri-strict-provenance`; use `with_addr` instead"
-                )
+                throw_machine_stop!(TerminationInfo::Int2PtrWithStrictProvenance);
             }
             ProvenanceMode::Permissive => {}
         }
index 8b2b053bdb59140e43ca88f2cf18e3d53945dbcb..968c4dfded37ac3fba6051613fdec76db5ccc1f6 100644 (file)
@@ -2,5 +2,5 @@
 
 fn main() {
     let addr = &0 as *const i32 as usize;
-    let _ptr = addr as *const i32; //~ ERROR integer-to-pointer casts and `from_exposed_addr` are not supported
+    let _ptr = addr as *const i32; //~ ERROR integer-to-pointer casts and `ptr::from_exposed_addr` are not supported
 }
index 32a39b81d9d7fb054f2e43d6915618106abf6d96..ab64f2bb288eabab1a05a21f1ee30674a7b6cb77 100644 (file)
@@ -1,10 +1,10 @@
-error: unsupported operation: integer-to-pointer casts and `from_exposed_addr` are not supported with `-Zmiri-strict-provenance`; use `with_addr` instead
+error: unsupported operation: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
   --> $DIR/strict_provenance_cast.rs:LL:CC
    |
 LL |     let _ptr = addr as *const i32;
-   |                ^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `from_exposed_addr` are not supported with `-Zmiri-strict-provenance`; use `with_addr` instead
+   |                ^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
    |
-   = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
+   = help: use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
            
    = note: inside `main` at $DIR/strict_provenance_cast.rs:LL:CC
 
index d821fcd9d15134a805038194ea8bc908240cb63d..41c752d5d0fc727c0f3514145be33dc52454df6d 100644 (file)
@@ -4,12 +4,12 @@ warning: integer-to-pointer cast
 LL |         let r2 = ((r as usize) + 0) as *mut i32;
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
    |
-   = help: this program is using integer-to-pointer casts or (equivalently) `from_exposed_addr`,
-   = help: which means that Miri might miss pointer bugs in this program
-   = help: see https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation
-   = help: to ensure that Miri does not miss bugs in your program, use `with_addr` (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) instead
-   = help: you can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics
-   = help: alternatively, the `-Zmiri-permissive-provenance` flag disables this warning
+   = help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
+   = help: which means that Miri might miss pointer bugs in this program.
+   = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
+   = help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
+   = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
+   = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
            
    = note: inside `into_raw` at $DIR/box.rs:LL:CC
 note: inside `main` at $DIR/box.rs:LL:CC
index f23526b52b4e77209261467e99f508f55fcb98a9..3a4acec5ddb9e7ebdb07471697333daf2d7d54cc 100644 (file)
@@ -4,12 +4,12 @@ warning: integer-to-pointer cast
 LL |     let x: &Foo = unsafe { &*(16 as *const Foo) };
    |                              ^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
    |
-   = help: this program is using integer-to-pointer casts or (equivalently) `from_exposed_addr`,
-   = help: which means that Miri might miss pointer bugs in this program
-   = help: see https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation
-   = help: to ensure that Miri does not miss bugs in your program, use `with_addr` (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance) instead
-   = help: you can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics
-   = help: alternatively, the `-Zmiri-permissive-provenance` flag disables this warning
+   = help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
+   = help: which means that Miri might miss pointer bugs in this program.
+   = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
+   = help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
+   = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
+   = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
            
    = note: inside `main` at $DIR/extern_types.rs:LL:CC