Skip to content

When a type is #[repr(simd)], #[repr(align(N))] annotations are ignored. #130402

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

Open
fu5ha opened this issue Sep 15, 2024 · 3 comments · May be fixed by #130460
Open

When a type is #[repr(simd)], #[repr(align(N))] annotations are ignored. #130402

fu5ha opened this issue Sep 15, 2024 · 3 comments · May be fixed by #130460
Labels
A-align Area: alignment control (`repr(align(N))` and so on) A-repr Area: the `#[repr(stuff)]` attribute A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fu5ha
Copy link
Contributor

fu5ha commented Sep 15, 2024

See this example playground

#[repr(simd, align(32))]
struct Test([f32; 4]);

fn main() {
    println!("{}", core::mem::align_of::<Test>());
}

I expected to see this happen: an alignment of at least 32 to be printed.

Instead, this happened: the alignment is only 16, the align of the underlying platform 128bit simd vector type.

Meta

Seen on playground nightly with version

(2024-09-14 9b72238eb813e9d06e9e)
@fu5ha fu5ha added the C-bug Category: This is a bug. label Sep 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 15, 2024
@workingjubilee workingjubilee added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-SIMD Area: SIMD (Single Instruction Multiple Data) labels Sep 15, 2024
@workingjubilee
Copy link
Member

@fu5ha Just curious: For the use-case in question (the Vec3A type), do you expect unbounded align-up?

@fu5ha
Copy link
Contributor Author

fu5ha commented Sep 17, 2024

@workingjubilee It mostly matters for me up to align(16) and I guess there could be similar reasons for align(32) or align(64)

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 18, 2024
@workingjubilee workingjubilee added A-repr Area: the `#[repr(stuff)]` attribute A-align Area: alignment control (`repr(align(N))` and so on) labels Nov 1, 2024
@workingjubilee
Copy link
Member

I will be able to fix this after #137256

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-align Area: alignment control (`repr(align(N))` and so on) A-repr Area: the `#[repr(stuff)]` attribute A-SIMD Area: SIMD (Single Instruction Multiple Data) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants