Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing a raw pointer fails in miri #844

Closed
jrmuizel opened this issue Jul 17, 2019 · 3 comments
Closed

Printing a raw pointer fails in miri #844

jrmuizel opened this issue Jul 17, 2019 · 3 comments
Labels
A-intptrcast Area: affects int2ptr and ptr2int casts C-support Category: Not necessarily a bug, but someone asking for support

Comments

@jrmuizel
Copy link

The following safe code fails to run in Miri:

println!("{:?}", Box::into_raw(Box::new(4)));
error[E0080]: Miri evaluation error: a raw memory access tried to access part of a pointer value as raw bytes
   --> /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ops/arith.rs:528:45
    |
528 |             fn rem(self, other: $t) -> $t { self % other }
    |                                             ^^^^^^^^^^^^ Miri evaluation error: a raw memory access tried to access part of a pointer value as raw bytes
    |
    = note: inside call to `<usize as std::ops::Rem>::rem` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/num.rs:61:25
    = note: inside call to `<core::fmt::num::LowerHex as core::fmt::num::GenericRadix>::fmt_int::<usize>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/num.rs:135:46
    = note: inside call to `core::fmt::num::<impl std::fmt::LowerHex for usize>::fmt` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/mod.rs:2024:19
    = note: inside call to `<*const i32 as std::fmt::Pointer>::fmt` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/mod.rs:2036:9
    = note: inside call to `<*mut i32 as std::fmt::Pointer>::fmt` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/mod.rs:2062:54
    = note: inside call to `<*mut i32 as std::fmt::Debug>::fmt` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/fmt/mod.rs:1016:17
    = note: inside call to `std::fmt::write` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/mod.rs:1288:15
    = note: inside call to `<tests::test::Sink as std::io::Write>::write_fmt` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/impls.rs:141:9
    = note: inside call to `std::io::impls::<impl std::io::Write for std::boxed::Box<dyn std::io::Write + std::marker::Send>>::write_fmt` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/stdio.rs:783:24
    = note: inside call to closure at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/thread/local.rs:257:16
    = note: inside call to `std::thread::LocalKey::<std::cell::RefCell<std::option::Option<std::boxed::Box<dyn std::io::Write + std::marker::Send>>>>::try_with::<[closure@DefId(1:2736 ~ std[797b]::io[0]::stdio[0]::print_to[0]::{{closure}}[0]) 0:&std::fmt::Arguments, 1:&fn() -> std::io::Stdout], std::result::Result<(), std::io::Error>>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/stdio.rs:780:18
    = note: inside call to `std::io::stdio::print_to::<std::io::Stdout>` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/stdio.rs:802:5
note: inside call to `std::io::_print` at <::std::macros::println macros>:2:4
   --> src/lib.rs:5:9
    |
5   |         println!("{:?}", Box::into_raw(Box::new(4)));
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@RalfJung
Copy link
Member

RalfJung commented Jul 17, 2019

@jrmuizel thanks for the report! Could you try to pass a seed, by running Miri with -Zmiri-seed=42?

Currently, letting the program observe the integer base address (which requires #224) is still disabled per default; but in #785 we have a plan for enabling it per default.

@RalfJung RalfJung added A-intptrcast Area: affects int2ptr and ptr2int casts C-support Category: Not necessarily a bug, but someone asking for support labels Jul 17, 2019
@jrmuizel
Copy link
Author

Indeed using -Zmiri-seed fixes.

@RalfJung
Copy link
Member

Thanks for checking! I am then closing this issue. Enabling raw pointer printing per default is tracked at #785.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intptrcast Area: affects int2ptr and ptr2int casts C-support Category: Not necessarily a bug, but someone asking for support
Projects
None yet
Development

No branches or pull requests

2 participants