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

channel: stacked borrows violation with -Zmiri-tag-raw-pointers #762

Closed
taiki-e opened this issue Jan 7, 2022 · 2 comments · Fixed by #764
Closed

channel: stacked borrows violation with -Zmiri-tag-raw-pointers #762

taiki-e opened this issue Jan 7, 2022 · 2 comments · Fixed by #764

Comments

@taiki-e
Copy link
Member

taiki-e commented Jan 7, 2022

MIRIFLAGS="-Zmiri-tag-raw-pointers -Zmiri-disable-isolation -Zmiri-ignore-leaks" \
    cargo miri test -p crossbeam-channel --test mpsc -- select_tests::sync2
output
error: Undefined Behavior: trying to reborrow for SharedReadWrite at alloc509444, but parent tag <untagged> does not have an appropriate item in the borrow stack
    --> /Users/taiki/projects/crossbeam/crossbeam-channel/src/flavors/zero.rs:137:22
     |
137  |         let packet = &*(token.zero as *const Packet<T>);
     |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for SharedReadWrite at alloc509444, but parent tag <untagged> does not have an appropriate item in the borrow stack
     |
     = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
     = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
             
     = note: inside `crossbeam_channel::flavors::zero::Channel::<i32>::write` at /Users/taiki/projects/crossbeam/crossbeam-channel/src/flavors/zero.rs:137:22
     = note: inside `crossbeam_channel::flavors::zero::Channel::<i32>::send` at /Users/taiki/projects/crossbeam/crossbeam-channel/src/flavors/zero.rs:219:17
     = note: inside `crossbeam_channel::Sender::<i32>::send` at /Users/taiki/projects/crossbeam/crossbeam-channel/src/channel.rs:428:41
note: inside `SyncSender::<i32>::send` at crossbeam-channel/tests/mpsc.rs:54:9
    --> crossbeam-channel/tests/mpsc.rs:54:9
     |
54   |         self.inner.send(t).map_err(|cc::SendError(m)| SendError(m))
     |         ^^^^^^^^^^^^^^^^^^
note: inside closure at crossbeam-channel/tests/mpsc.rs:2099:13
    --> crossbeam-channel/tests/mpsc.rs:2099:13
     |
2099 |             tx.send(1).unwrap();
     |             ^^^^^^^^^^
     = note: inside `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@crossbeam-channel/tests/mpsc.rs:2095:31: 2100:10], ()>` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:123:18
     = note: inside closure at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:477:17
     = note: inside `<std::panic::AssertUnwindSafe<[closure@std::thread::Builder::spawn_unchecked<[closure@crossbeam-channel/tests/mpsc.rs:2095:31: 2100:10], ()>::{closure#1}::{closure#0}]> as std::ops::FnOnce<()>>::call_once` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/panic/unwind_safe.rs:271:9
     = note: inside `std::panicking::r#try::do_call::<std::panic::AssertUnwindSafe<[closure@std::thread::Builder::spawn_unchecked<[closure@crossbeam-channel/tests/mpsc.rs:2095:31: 2100:10], ()>::{closure#1}::{closure#0}]>, ()>` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:406:40
     = note: inside `std::panicking::r#try::<(), std::panic::AssertUnwindSafe<[closure@std::thread::Builder::spawn_unchecked<[closure@crossbeam-channel/tests/mpsc.rs:2095:31: 2100:10], ()>::{closure#1}::{closure#0}]>>` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:370:19
     = note: inside `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<[closure@std::thread::Builder::spawn_unchecked<[closure@crossbeam-channel/tests/mpsc.rs:2095:31: 2100:10], ()>::{closure#1}::{closure#0}]>, ()>` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:133:14
     = note: inside closure at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/mod.rs:476:30
     = note: inside `<[closure@std::thread::Builder::spawn_unchecked<[closure@crossbeam-channel/tests/mpsc.rs:2095:31: 2100:10], ()>::{closure#1}] as std::ops::FnOnce<()>>::call_once - shim(vtable)` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
     = note: inside `<std::boxed::Box<dyn std::ops::FnOnce()> as std::ops::FnOnce<()>>::call_once` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1854:9
     = note: inside `<std::boxed::Box<std::boxed::Box<dyn std::ops::FnOnce()>> as std::ops::FnOnce<()>>::call_once` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1854:9
     = note: inside `std::sys::unix::thread::Thread::new::thread_start` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:108:17

If run without -Zmiri-tag-raw-pointers, the test succeeds.

cc #578

@RalfJung
Copy link
Contributor

RalfJung commented Jan 7, 2022

"parent tag <untagged>" indicates a ptr created by a cast from usize, which is not supported with -Zmiri-tag-raw-pointers.

@taiki-e
Copy link
Member Author

taiki-e commented Jan 7, 2022

@RalfJung Thanks. I filed #764 to remove ptr-to-int casts (and fix another stacked borrows violation in channel).

@bors bors bot closed this as completed in c6bda10 Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants