-
Notifications
You must be signed in to change notification settings - Fork 501
Closed
Labels
Description
Run the follow code sample with cargo +nightly miri run
use crossbeam_utils::atomic::AtomicCell;
#[allow(dead_code)]
#[repr(align(8))]
#[derive(Copy, Clone, Debug)]
enum Test {
Field(u32),
FieldLess,
}
fn main() {
assert!(AtomicCell::<Test>::is_lock_free());
let x = AtomicCell::new(Test::FieldLess);
println!("{:?}", x.load());
}
I see the following error from Miri
error: Undefined Behavior: type validation failed at .value.<enum-tag>: encountered uninitialized bytes, but expected a valid enum tag
note: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
I think the root of this issue is that AtomicCell
is trying to do a transmute_copy
on the None
value, but the upper bits are uninitialized, therefore AtomicCell
is reading uninitialized data.
crossbeam-utils = "0.8.5"
cargo 1.56.0-nightly (cc17afbb0 2021-08-02)