Skip to content

Commit 84a8052

Browse files
committed
document #[align] on functions
1 parent c590f78 commit 84a8052

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/attributes/codegen.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,26 @@ Using the `instruction_set` attribute has the following effects:
668668

669669
* If the address of the function is taken as a function pointer, the low bit of the address will be set to 0 (arm) or 1 (thumb) depending on the instruction set.
670670
* Any inline assembly in the function must use the specified instruction set instead of the target default.
671+
672+
r[attributes.codegen.align]
673+
## The `align` attribute
674+
675+
r[attributes.codegen.align.allowed-positions]
676+
The *`align` [attribute]* may be applied to function items.
677+
678+
r[attributes.codegen.align.behavior]
679+
This attribute raises the aligmnent of a function's generated code.
680+
681+
```rust
682+
#[align(32)]
683+
fn aligned_to_32_bytes() {}
684+
```
685+
686+
> [!NOTE]
687+
> Some targets use pointer tagging on function pointers. Consequently, on those targets, a function's address may not be a multiple of its alignment.
688+
689+
r[attributes.codegen.align.minimum]
690+
The alignment value that is specified is a minimum. The actual alignment may be higher.
691+
692+
r[attributes.codegen.align.syntax]
693+
The alignment is specified as an integer parameter in the form of `#[align(x)]`. The alignment value must be a power of two from 1 up to 2<sup>29</sup>.

0 commit comments

Comments
 (0)