Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

_ => {}
Expand Down
19 changes: 19 additions & 0 deletions tests/codegen/align-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Loading