GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

gccrs: Add new checks for `#[repr(align)]` attribute

Enforces that the alignment parameter in `#[repr(align)]` is a power of two.

The Rust compiler frontend now includes checks for the #[repr(align)] attribute to ensure that the specified alignment value is a power of two. This is a requirement for valid alignment specifications in Rust, preventing potential misinterpretations or undefined behavior related to memory alignment.

In Details

In gccrs, the TypeCheckBase::parse_repr_options function now validates that the integer argument provided to the #[repr(align)] attribute is a power of two. This check is crucial for maintaining ABI compatibility and preventing incorrect memory layout assumptions, as standard alignment values are typically powers of two.

For Context
alignment
The requirement that memory addresses for certain data types fall on boundaries that are multiples of their size or a specific value. Proper alignment is crucial for performance and correctness on many architectures.
`#[repr(align)]` attribute
A Rust attribute that allows a developer to specify the required memory alignment for a struct or enum. For example, #[repr(align(16))] requests that instances of the type be aligned to a 16-byte boundary.
power of two
A number that can be expressed as 2 raised to an integer exponent (e.g., 1, 2, 4, 8, 16). Many low-level operations, especially those involving bitwise manipulation for alignment checks, rely on powers of two.
Filed Under: gccrsrustattributetype system