Skip to content

Commit

Permalink
fix UB in a test
Browse files Browse the repository at this point in the history
also add an explicit test for the fact that a Option<WidePtr> has padding when it is None
  • Loading branch information
RalfJung committed Sep 9, 2024
1 parent 55f602f commit d257159
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,20 @@ fn offset_of_addr() {
#[test]
fn const_maybe_uninit_zeroed() {
// Sanity check for `MaybeUninit::zeroed` in a realistic const situation (plugin array term)

// It is crucial that this type has no padding!
#[repr(C)]
struct Foo {
a: Option<&'static str>,
a: Option<&'static u8>,
b: Bar,
c: f32,
_pad: u32,
d: *const u8,
}

#[repr(C)]
struct Bar(usize);

struct FooPtr(*const Foo);
unsafe impl Sync for FooPtr {}

Expand Down

0 comments on commit d257159

Please sign in to comment.