rust-lang / rust-lang/rust

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

Open
#130,402 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-align A-repr A-SIMD C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the linked nightly playground example and compare the alignment reported by core::mem::align_of::() with the #[repr(simd, align(32))] declaration. Trace the compiler's handling of repr(simd) and repr(align(N)) for this type. Done means the explicit alignment is honored and the example reports an alignment of at least 32.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.