-
Notifications
You must be signed in to change notification settings - Fork 118
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
Calls to BitSlice::set_aliased and BitSlice::set_aliased_unchecked on Cell<u8>
is deleted completely by optimizer in release mode
#283
Comments
This appears to have started happening with LLVM 16. cargo bisect-rustc resultsearched toolchains nightly-2022-09-17 through nightly-2024-04-28
********************************************************************************
Regression in nightly-2023-06-15
********************************************************************************
fetching https://static.rust-lang.org/dist/2023-06-14/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2023-06-14: 40 B / 40 B [===================================================================================================================] 100.00 % 542.65 KB/s converted 2023-06-14 to 371994e0d8380600ddda78ca1be937c7fb179b49
fetching https://static.rust-lang.org/dist/2023-06-15/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2023-06-15: 40 B / 40 B [===================================================================================================================] 100.00 % 951.88 KB/s converted 2023-06-15 to 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220
looking for regression commit between 2023-06-14 and 2023-06-15
fetching (via remote github) commits from max(371994e0d8380600ddda78ca1be937c7fb179b49, 2023-06-12) to 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220
ending github query because we found starting sha: 371994e0d8380600ddda78ca1be937c7fb179b49
get_commits_between returning commits, len: 9
commit[0] 2023-06-13: Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3
commit[1] 2023-06-13: Auto merge of #112062 - lukas-code:unsized-layout, r=wesleywiser
commit[2] 2023-06-14: Auto merge of #112448 - nnethercote:no-tiny-cgus, r=wesleywiser
commit[3] 2023-06-14: Auto merge of #112609 - matthiaskrgr:rollup-er6weld, r=matthiaskrgr
commit[4] 2023-06-14: Auto merge of #110662 - bryangarza:safe-transmute-reference-types, r=compiler-errors
commit[5] 2023-06-14: Auto merge of #112400 - WaffleLapkin:vtable_stats, r=compiler-errors
commit[6] 2023-06-14: Auto merge of #112418 - ferrocene:pa-mir-opt-panic, r=ozkanonur,saethlin
commit[7] 2023-06-14: Auto merge of #112624 - matthiaskrgr:rollup-db6ta1b, r=matthiaskrgr
commit[8] 2023-06-14: Auto merge of #112625 - matthiaskrgr:rollup-jcobj3g, r=matthiaskrgr
ERROR: no CI builds available between 371994e0d8380600ddda78ca1be937c7fb179b49 and 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220 within last 167 days The CI artifacts from that far back are gone, and I'm not going to build LLVM locally to test which of these may have caused the difference, Actually, the codegen-unit partition change made me think to try the code with Manually trying all nightlies in that range gives the expected result for this being caused by the LLVM 16 bump:
A simpler example that doesn't require use std::cell::Cell;
use bitvec::prelude::*;
#[inline(never)]
#[no_mangle]
pub extern "C" fn do_the_thing(cell: &Cell<u8>) {
cell.view_bits::<Lsb0>().set_aliased(0, true);
} In release mode, in the "success" nightlies as listed above, this code compiles to: do_the_thing:
or byte ptr [rdi], 1
ret and in the "fail" nightlies, compiles to: do_the_thing:
ret |
Changing |
I was going to post the following as an issue on rust-lang/rust, but now I think this is probably not a miscompilation but UB because would-be Rust issueI tried this code: (using any of use std::cell::Cell;
use bitvec::prelude::*;
#[inline(never)]
#[no_mangle]
pub extern "C" fn do_the_thing(cell: &Cell<u8>) {
cell.view_bits::<Lsb0>().set_aliased(0, true);
} I expected to see this happen: In release mode, in the "success" nightlies as listed below, this code compiles to: do_the_thing:
or byte ptr [rdi], 1
ret Instead, this happened: in the "fail" nightlies (and since), this compiles to: do_the_thing:
ret Original linked issuePut in a use std::cell::Cell;
use bitvec::prelude::*;
#[test]
fn test_cell_bitvec() {
let cell: Cell<u8> = Cell::new(0);
for index in 0..8 {
assert_eq!(*cell.view_bits::<Lsb0>().get(index).unwrap(), false);
}
for index in 0..8 {
cell.view_bits::<Lsb0>().set_aliased(index, true);
}
for index in 0..8 {
assert_eq!(*cell.view_bits::<Lsb0>().get(index).unwrap(), true);
}
}
#[test]
fn test_cell_bitvec_unchecked() {
let cell: Cell<u8> = Cell::new(0);
for index in 0..8 {
assert_eq!(*unsafe { cell.view_bits::<Lsb0>().get_unchecked(index) }, false);
}
for index in 0..8 {
unsafe { cell.view_bits::<Lsb0>().set_aliased_unchecked(index, true) }
}
for index in 0..8 {
assert_eq!(*unsafe { cell.view_bits::<Lsb0>().get_unchecked(index) }, true);
}
} I expected to see this happen: Either the tests pass Miri and suceeds in both debug and release mode, or the tests don't pass Miri. Instead, this happened: The tests pass Miri (though
Meta
rustc 1.70.0-nightly (13afbdaa0 2023-03-17)
binary: rustc
commit-hash: 13afbdaa0655dda23d7129e59ac48f1ec88b2084
commit-date: 2023-03-17
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7
rustc 1.70.0-nightly (0c61c7a97 2023-03-25)
binary: rustc
commit-hash: 0c61c7a978fe9f7b77a1d667c77d2202dadd1c10
commit-date: 2023-03-25
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 16.0.0 Without First nightly with failing rustc 1.72.0-nightly (8c74a5d27 2023-06-14)
binary: rustc
commit-hash: 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220
commit-date: 2023-06-14
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5 cargo bisect-rustc output
#!/bin/bash
#!/bin/bash
cargo test --release
exit $? searched toolchains nightly-2023-05-27 through nightly-2023-08-20
********************************************************************************
Regression in nightly-2023-06-15
********************************************************************************
fetching https://static.rust-lang.org/dist/2023-06-14/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2023-06-14: 40 B / 40 B [===================================================================================================================] 100.00 % 402.12 KB/s converted 2023-06-14 to 371994e0d8380600ddda78ca1be937c7fb179b49
fetching https://static.rust-lang.org/dist/2023-06-15/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2023-06-15: 40 B / 40 B [===================================================================================================================] 100.00 % 530.32 KB/s converted 2023-06-15 to 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220
looking for regression commit between 2023-06-14 and 2023-06-15
fetching (via remote github) commits from max(371994e0d8380600ddda78ca1be937c7fb179b49, 2023-06-12) to 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220
ending github query because we found starting sha: 371994e0d8380600ddda78ca1be937c7fb179b49
get_commits_between returning commits, len: 9
commit[0] 2023-06-13: Auto merge of #112314 - ferrocene:pa-core-alloc-abort, r=bjorn3
commit[1] 2023-06-13: Auto merge of #112062 - lukas-code:unsized-layout, r=wesleywiser
commit[2] 2023-06-14: Auto merge of #112448 - nnethercote:no-tiny-cgus, r=wesleywiser
commit[3] 2023-06-14: Auto merge of #112609 - matthiaskrgr:rollup-er6weld, r=matthiaskrgr
commit[4] 2023-06-14: Auto merge of #110662 - bryangarza:safe-transmute-reference-types, r=compiler-errors
commit[5] 2023-06-14: Auto merge of #112400 - WaffleLapkin:vtable_stats, r=compiler-errors
commit[6] 2023-06-14: Auto merge of #112418 - ferrocene:pa-mir-opt-panic, r=ozkanonur,saethlin
commit[7] 2023-06-14: Auto merge of #112624 - matthiaskrgr:rollup-db6ta1b, r=matthiaskrgr
commit[8] 2023-06-14: Auto merge of #112625 - matthiaskrgr:rollup-jcobj3g, r=matthiaskrgr
ERROR: no CI builds available between 371994e0d8380600ddda78ca1be937c7fb179b49 and 8c74a5d27c644a0f7a22bb2fa8dd3ff8257bc220 within last 167 days |
Hello @myrrlyn
bitvec: v1.0.1
I think I stumbled upon a strange and nasty bug, where the outcome is different in rustc DEV versus RELEASE compilation profile.
The minimal test example which passes in DEV while fails in RELEASE:
When tested with
--release
flag both tests fail as ifset_alias
andset_alias_unchecked
was never called:If I replace
Cell<u8>
with any other primitive type:Cell<u16|u32|u64|usize>
the test does not fail in RELEASE mode. This only happens forCell<u8>
!The only workaround I found so far is to replace
Cell<u8>
withAtomicU8
which is not ideal as I'm using it in a single threaded environment.This happens regardless of the platform, as I first detected the problem on
thumbv7em
but later I confirmed the same is happening onx86_64
.The bug is quite nasty and can give you headaches when trying to debug this, especially that it works fine in DEV and only manifests when optimizations are turned on.
Moreover it does not matter what kind of
opt-level
is enabled as long as it's equal to or aboveopt-level = 1
forprofile.release
.The text was updated successfully, but these errors were encountered: