Skip to content
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

Simd::load implementation does not match documentation #382

Closed
RalfJung opened this issue Dec 11, 2023 · 0 comments · Fixed by #383
Closed

Simd::load implementation does not match documentation #382

RalfJung opened this issue Dec 11, 2023 · 0 comments · Fixed by #383
Labels
C-bug Category: Bug

Comments

@RalfJung
Copy link
Member

RalfJung commented Dec 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant