Skip to content

Commit b7a9cd8

Browse files
Rollup merge of #142923 - folkertdev:min-function-alignment-no-attributes, r=workingjubilee
fix `-Zmin-function-alignment` on functions without attributes tracking issue: #82232 related: #142854 The minimum function alignment was skipped on functions without attributes (because the logic was in a loop that only runs if there is at least one attribute). The underlying reason we didn't catch this before is that in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes. r? `@workingjubilee`
2 parents 1569f14 + 8147646 commit b7a9cd8

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
146146
}
147147
}
148148

149-
// Apply the minimum function alignment here, so that individual backends don't have to.
150-
codegen_fn_attrs.alignment = Ord::max(
151-
codegen_fn_attrs.alignment,
152-
tcx.sess.opts.unstable_opts.min_function_alignment,
153-
);
154-
155149
let Some(Ident { name, .. }) = attr.ident() else {
156150
continue;
157151
};
@@ -454,6 +448,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
454448

455449
mixed_export_name_no_mangle_lint_state.lint_if_mixed(tcx);
456450

451+
// Apply the minimum function alignment here, so that individual backends don't have to.
452+
codegen_fn_attrs.alignment =
453+
Ord::max(codegen_fn_attrs.alignment, tcx.sess.opts.unstable_opts.min_function_alignment);
454+
457455
let inline_span;
458456
(codegen_fn_attrs.inline, inline_span) = if let Some((inline_attr, span)) =
459457
find_attr!(attrs, AttributeKind::Inline(i, span) => (*i, *span))

tests/codegen/min-function-alignment.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
//@ revisions: align16 align1024
2-
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
2+
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0 -Clink-dead-code
33
//@ [align16] compile-flags: -Zmin-function-alignment=16
44
//@ [align1024] compile-flags: -Zmin-function-alignment=1024
55

66
#![crate_type = "lib"]
77
#![feature(fn_align)]
88

9-
// functions without explicit alignment use the global minimum
9+
// Functions without explicit alignment use the global minimum.
1010
//
11-
// CHECK-LABEL: @no_explicit_align
11+
// NOTE: this function deliberately has zero (0) attributes! That is to make sure that
12+
// `-Zmin-function-alignment` is applied regardless of whether attributes are used.
13+
//
14+
// CHECK-LABEL: no_explicit_align
1215
// align16: align 16
1316
// align1024: align 1024
14-
#[no_mangle]
1517
pub fn no_explicit_align() {}
1618

1719
// CHECK-LABEL: @lower_align

0 commit comments

Comments
 (0)