Skip to content

Be aware of alignment checking issues #182

Open
@joshlf

Description

@joshlf

We have code like the following in zerocopy as of this writing:

zerocopy/src/lib.rs

Lines 2323 to 2331 in 27aea67

/// Is `t` aligned to `mem::align_of::<U>()`?
#[inline(always)]
fn aligned_to<T: AsAddress, U>(t: T) -> bool {
// `mem::align_of::<U>()` is guaranteed to return a non-zero value, which in
// turn guarantees that this mod operation will not panic.
#[allow(clippy::arithmetic_side_effects)]
let remainder = t.addr() % mem::align_of::<U>();
remainder == 0
}

According to rust-lang/rust#62420, there's a small chance that this may be decided to be unsound (and it's not supported during const eval, although there are bigger problems regarding using addresses in const eval). We should figure out whether this is a risk we're comfortable with, and consider how we might mitigate it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions