ferrilab / bitvec

A crate for managing memory bit by bit
https://myrrlyn.net/crates/bitvec
MIT License
1.2k stars 114 forks source link

Miri: unsupported operation with `-Zmiri-strict-provenance` #188

Closed wcampbell0x2a closed 2 years ago

wcampbell0x2a commented 2 years ago

Found within https://github.com/sharksforarms/deku/issues/266, but first found in bitvec.

$ MIRIFLAGS="-Zmiri-strict-provenance" cargo miri test
test array::tests::format::render ... error: unsupported operation: integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
   --> src/ptr/span.rs:254:5
    |
254 |                 (self.ptr.as_ptr() as usize & Self::PTR_ADDR_MASK) as *mut T,
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ integer-to-pointer casts and `ptr::from_exposed_addr` are not supported with `-Zmiri-strict-provenance`
    |
    = help: use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
    = note: backtrace:
    = note: inside `ptr::span::BitSpan::<wyz::Const, u8>::address` at src/ptr/span.rs:254:5
note: inside `ptr::span::BitSpan::<wyz::Const, u8>::render::<std::option::Option<&(&str, &dyn std::fmt::Debug)>>` at src/ptr/span.rs:671:20
   --> src/ptr/span.rs:671:20
    |
671 |             .field("addr", &self.address().fmt_pointer())
    |                             ^^^^^^^^^^^^^^
note: inside `array::traits::<impl std::fmt::Debug for array::BitArray<u8>>::fmt` at src/array/traits.rs:255:3
   --> src/array/traits.rs:255:3
    |
255 |         self.as_bitspan().render(fmt, "Array", None)?;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: inside `std::fmt::write` at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1198:17
    = note: inside `<std::string::String as std::fmt::Write>::write_fmt` at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:188:9
    = note: inside `std::fmt::format::format_inner` at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/fmt.rs:612:9
    = note: inside closure at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/fmt.rs:616:34
    = note: inside `std::option::Option::<&str>::map_or_else::<std::string::String, [closure@std::fmt::format::{closure#0}], for<'r> fn(&'r str) -> <str as std::borrow::ToOwned>::Owned {<str as std::borrow::ToOwned>::to_owned}>` at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1023:21
    = note: inside `std::fmt::format` at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/fmt.rs:616:5
note: inside `array::tests::format::render` at /home/wcampbell/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/macros.rs:116:19
   --> src/array/tests.rs:152:16
    |
152 |         let render = format!("{:?}", BitArray::<u8, Lsb0>::ZERO);
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure at src/array/tests.rs:151:2
   --> src/array/tests.rs:151:2
    |
150 |       #[test]
    |       ------- in this procedural macro expansion
151 | /     fn render() {
152 | |         let render = format!("{:?}", BitArray::<u8, Lsb0>::ZERO);
153 | |         assert!(render.starts_with(&format!(
154 | |             "BitArray<u8, {}>",
...   |
174 | |         );
175 | |     }
    | |_____^
    = note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info)

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error

error: test failed, to rerun pass '--lib'

Not sure on bitvecs working with general miri, or if strict-provenance is a goal of this crate.

myrrlyn commented 2 years ago

Strict provenance is absolutely a goal. Please continue to report Miri violations.

marmeladema commented 1 year ago

Hi! I've just hit the same issue but I see it is fixed in the main branch. @myrrlyn do you think a patch release could be issued for this? crates.io says latest version is still 1.0.1

Thank you in advance :)