fix multiple #[repr(align(N))] on functions

This commit is contained in:
Folkert de Vries 2025-04-16 12:16:40 +02:00
parent 5961e5ba3d
commit a6dcd519f3
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 21 additions and 1 deletions

View file

@ -114,7 +114,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
AttributeKind::Repr(reprs) => {
codegen_fn_attrs.alignment = reprs
.iter()
.find_map(|(r, _)| if let ReprAlign(x) = r { Some(*x) } else { None });
.filter_map(|(r, _)| if let ReprAlign(x) = r { Some(*x) } else { None })
.max();
}
_ => {}

View file

@ -47,3 +47,22 @@ impl T for () {}
pub fn foo() {
().trait_method();
}
// CHECK-LABEL: align_specified_twice_1
// CHECK-SAME: align 64
#[no_mangle]
#[repr(align(32), align(64))]
pub fn align_specified_twice_1() {}
// CHECK-LABEL: align_specified_twice_2
// CHECK-SAME: align 128
#[no_mangle]
#[repr(align(128), align(32))]
pub fn align_specified_twice_2() {}
// CHECK-LABEL: align_specified_twice_3
// CHECK-SAME: align 256
#[no_mangle]
#[repr(align(32))]
#[repr(align(256))]
pub fn align_specified_twice_3() {}