Skip to content

Commit a81584e

Browse files
authored
Rollup merge of #139917 - folkertdev:fn-align-multiple, r=jdonszelmann
fix for multiple `#[repr(align(N))]` on functions tracking issue: rust-lang/rust#82232 fixes rust-lang/rust#132464 The behavior of align is specified at https://doc.rust-lang.org/reference/type-layout.html#r-layout.repr.alignment.align > For align, if the specified alignment is less than the alignment of the type without the align modifier, then the alignment is unaffected. So in effect that means that the maximum of the specified alignments should be chosen. That is also the current behavior for `align` on ADTs: ```rust #![feature(fn_align)] #[repr(C, align(32), align(64))] struct Foo { x: u64, } const _: () = assert!(core::mem::align_of::<Foo>() == 64); // See the godbolt LLVM output: the alignment of this function is 32 #[no_mangle] #[repr(align(32))] #[repr(align(64))] fn foo() {} // The current logic just picks the first alignment: the alignment of this function is 64 #[no_mangle] #[repr(align(64))] #[repr(align(32))] fn bar() {} ``` https://godbolt.org/z/scco435jE https://github.com/rust-lang/rust/blob/afa859f8121bf2985362a2c8414dc71a825ccf2d/compiler/rustc_middle/src/ty/mod.rs#L1529-L1532 The rust-lang/rust#132464 issue is really about parsing/representing the attribute, which has already been improved and now uses the "parse, don't validate" attribute approach. That means the behavior is already different from what the issue describes: on current `main`, the first value is chosen. This PR fixes a logic error, where we just did not check for the effect of two or more `align` modifiers. In combination, that fixes the issue. cc ``@jdonszelmann`` if you do have further thoughs here
2 parents 7b08723 + 270e89f commit a81584e

File tree

0 file changed

+0
-0
lines changed

    0 file changed

    +0
    -0
    lines changed

    0 commit comments

    Comments
     (0)