Skip to content

Simd::load implementation does not match documentation #382

Closed
@RalfJung

Description

@RalfJung

The load function is documented as follows:

/// Load a vector from an array of `T`.
///
/// This function is necessary since `repr(simd)` has padding for non-power-of-2 vectors (at the time of writing).
/// With padding, `read_unaligned` will read past the end of an array of N elements.
///
/// # Safety
/// Reading `ptr` must be safe, as if by `<*const [T; N]>::read_unaligned`.

In particular, the last part says that there are no alignment restrictions on the pointer. However, the implementation performs a copy_nonoverlapping at type [T; N], which means that ptr actually must be T-aligned. This is unsound under the stated precondition for this function. (There don't seem to be tests actually using this with unaligned pointers, so Miri can't catch this.)

It is unclear to me what the intended behavior is, though I would have expected that alignment is indeed required -- i.e., I would guess the docs are wrong and the code is right.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions