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: Remove ptr-to-int casts #764

Merged
merged 1 commit into from
Jan 8, 2022
Merged

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Jan 7, 2022

This fixes #762 and another stacked borrows violation that seems to have been made detectable by the fix of #762.

@@ -177,7 +190,7 @@ impl<T> Channel<T> {
// heap-allocated packet.
packet.wait_ready();
let msg = packet.msg.get().replace(None).unwrap();
drop(Box::from_raw(packet as *const Packet<T> as *mut Packet<T>));
drop(Box::from_raw(token.zero.0 as *mut Packet<T>));
Ok(msg)
Copy link
Member Author

@taiki-e taiki-e Jan 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another stacked borrows violation that was fixed by this PR is:

error: Undefined Behavior: trying to reborrow for Unique at alloc5094412+0x8, but parent tag <14690213> does not have an appropriate item in the borrow stack
    --> /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:977:9
     |
977  |         Box(unsafe { Unique::new_unchecked(raw) }, alloc)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for Unique at alloc5094412+0x8, but parent tag <14690213> 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 `std::boxed::Box::<crossbeam_channel::flavors::zero::Packet<i32>>::from_raw_in` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:977:9
     = note: inside `std::boxed::Box::<crossbeam_channel::flavors::zero::Packet<i32>>::from_raw` at /Users/taiki/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/boxed.rs:921:18
     = note: inside `crossbeam_channel::flavors::zero::Channel::<i32>::read` at /Users/taiki/projects/crossbeam/crossbeam-channel/src/flavors/zero.rs:193:18
     = note: inside `crossbeam_channel::flavors::zero::Channel::<i32>::recv` at /Users/taiki/projects/crossbeam/crossbeam-channel/src/flavors/zero.rs:302:24
     = note: inside `crossbeam_channel::Receiver::<i32>::recv` at /Users/taiki/projects/crossbeam/crossbeam-channel/src/channel.rs:802:43
note: inside `Chan::<i32>::recv` at crossbeam-channel/tests/golang.rs:64:9
    --> crossbeam-channel/tests/golang.rs:64:9
     |
64   |         r.recv().ok()
     |         ^^^^^^^^
note: inside closure at crossbeam-channel/tests/golang.rs:1420:28
    --> crossbeam-channel/tests/golang.rs:1420:28
     |
1420 |                     l[i] = c.recv().unwrap();
     |                            ^

@taiki-e
Copy link
Member Author

taiki-e commented Jan 8, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 8, 2022

Build succeeded:

@bors bors bot merged commit c6bda10 into master Jan 8, 2022
@bors bors bot deleted the channel-remove-ptr-to-int-casts branch January 8, 2022 04:24
bors bot added a commit that referenced this pull request Jan 8, 2022
769: Prepare for the next release r=taiki-e a=taiki-e

- crossbeam-channel 0.5.1 -> 0.5.2
  - Fix stacked borrows violations. (#763, #764)
- crossbeam-epoch 0.9.5 -> 0.9.6
  - Add `Atomic::fetch_update`. (#706)
- crossbeam-queue 0.3.2 -> 0.3.3
  - Fix stacked borrows violation in `ArrayQueue`. (#763)
- crossbeam-utils 0.8.5 -> 0.8.6
  - Re-add `AtomicCell<{i,u}64>::{fetch_add,fetch_sub,fetch_and,fetch_or,fetch_xor}` that were accidentally removed in 0.8.0 on targets that do not support `Atomic{I,U}64`. (#767)
  - Re-add `AtomicCell<{i,u}128>::{fetch_add,fetch_sub,fetch_and,fetch_or,fetch_xor}` that were accidentally removed in 0.8.0. (#767)


Co-authored-by: Taiki Endo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

channel: stacked borrows violation with -Zmiri-tag-raw-pointers
1 participant