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

miri: printing with full mir doesn't work because of pointer aligning inside memrchr #50567

Closed
bjorn3 opened this issue May 9, 2018 · 2 comments
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented May 9, 2018

let end_align = (ptr as usize + len) & (usize_bytes - 1);

error: a raw memory access tried to access part of a pointer value as raw bytes

error[E0080]: constant evaluation error
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/slice/memchr.rs:106:21
    |
106 |     let end_align = (ptr as usize + len) & (usize_bytes - 1);
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a raw memory access tried to access part of a pointer value as raw bytes
    |
note: inside call to `core::slice::memchr::memrchr`
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/sys/unix/memchr.rs:53:9
    |
53  |         ::core::slice::memchr::memrchr(needle, haystack)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `std::sys::unix::memchr::memrchr::memrchr_specific`
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/sys/unix/memchr.rs:56:5
    |
56  |     memrchr_specific(needle, haystack)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `std::sys::unix::memchr::memrchr`
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/memchr.rs:55:5
    |
55  |     ::sys::memchr::memrchr(needle, haystack)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `std::memchr::memrchr`
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/buffered.rs:905:23
    |
905 |         let i = match memchr::memrchr(b'/n', buf) {
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `<std::io::LineWriter<W> as std::io::Write><std::io::stdio::Maybe<std::io::stdio::StdoutRaw>>::write`
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/stdio.rs:465:9
    |
465 |         self.inner.borrow_mut().write(buf)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `<std::io::StdoutLock<'a> as std::io::Write>::write`
   --> /Users/bjorn/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libstd/io/mod.rs:1111:19
    |
1111|             match self.write(buf) {
    |                   ^^^^^^^^^^^^^^^
[...]
@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2018

memrchr should be using the align_to function, which was created solely for that purpose.

@kennytm kennytm added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 9, 2018
@bjorn3
Copy link
Member Author

bjorn3 commented Jul 21, 2018

triage: memrchr still uses the same code

@oli-obk oli-obk added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. A-const-eval Area: Constant evaluation (MIR interpretation) labels Jul 21, 2018
bors added a commit that referenced this issue Jul 28, 2018
make memrchr use align_offset

I hope I did not screw that up...

Cc @oli-obk who authored the original #44537

Fixes #50567 (thanks @bjorn3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants