rust/compiler
Matthias Krüger cbe469a8b1
Rollup merge of #139917 - folkertdev:fn-align-multiple, r=jdonszelmann
fix for multiple `#[repr(align(N))]` on functions

tracking issue: https://github.com/rust-lang/rust/issues/82232
fixes https://github.com/rust-lang/rust/issues/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

afa859f812/compiler/rustc_middle/src/ty/mod.rs (L1529-L1532)

The https://github.com/rust-lang/rust/issues/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
2025-04-17 00:14:28 +02:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi Initial UnsafePinned/UnsafeUnpin impl [Part 1: Libs] 2025-04-13 01:11:04 -04:00
rustc_arena Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_ast Rollup merge of #139392 - compiler-errors:raw-expr, r=oli-obk 2025-04-14 18:15:31 +02:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Rollup merge of #139770 - nnethercote:rename-LifetimeName, r=BoxyUwU 2025-04-17 00:14:26 +02:00
rustc_ast_passes Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obk 2025-04-07 22:29:17 +10:00
rustc_ast_pretty Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_attr_data_structures add rustc_macro_edition_2021 2025-03-19 17:37:35 +01:00
rustc_attr_parsing Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco 2025-04-17 00:14:24 +02:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Rollup merge of #139770 - nnethercote:rename-LifetimeName, r=BoxyUwU 2025-04-17 00:14:26 +02:00
rustc_builtin_macros Auto merge of #139781 - jhpratt:rollup-qadsjvb, r=jhpratt 2025-04-14 07:07:54 +00:00
rustc_codegen_cranelift Move has_self field to hir::AssocKind::Fn. 2025-04-14 16:13:04 +10:00
rustc_codegen_gcc Prepend temp files with a string per invocation of rustc 2025-04-07 20:48:40 +00:00
rustc_codegen_llvm Revert "Deduplicate template parameter creation" 2025-04-15 21:00:11 +03:00
rustc_codegen_ssa fix multiple #[repr(align(N))] on functions 2025-04-16 12:16:40 +02:00
rustc_const_eval Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_data_structures Switch to diagnostic::on_unimplemented 2025-04-14 01:38:18 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_error_codes error on unsafe attributes in pre-2024 editions 2025-04-13 01:22:59 +02:00
rustc_error_messages update cfgs 2025-04-09 12:29:59 +01:00
rustc_errors Rollup merge of #139468 - compiler-errors:has_stashed_diagnostic, r=oli-obk 2025-04-09 14:52:38 +02:00
rustc_expand Rollup merge of #139671 - m-ou-se:proc-macro-span, r=dtolnay 2025-04-15 15:47:27 +10:00
rustc_feature Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco 2025-04-17 00:14:24 +02:00
rustc_fluent_macro Replace proc_macro::SourceFile by Span::{file, local_file}. 2025-04-11 15:07:08 +02:00
rustc_fs_util Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Rename LifetimeName as LifetimeKind. 2025-04-16 07:16:40 +10:00
rustc_hir_analysis Rollup merge of #139770 - nnethercote:rename-LifetimeName, r=BoxyUwU 2025-04-17 00:14:26 +02:00
rustc_hir_pretty Fix HIR pretty-printing of fns with just a variadic arg. 2025-04-15 10:41:10 +10:00
rustc_hir_typeck Rollup merge of #139848 - nnethercote:kw-Empty-5, r=compiler-errors 2025-04-15 21:16:05 +02:00
rustc_incremental Remove safe remove 2025-04-14 18:47:15 +00:00
rustc_index Use {Decodable,Encodable}_NoContext in type_ir 2025-03-15 06:34:36 +00:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer Auto merge of #139768 - compiler-errors:split-fold, r=lcnr 2025-04-16 01:46:01 +00:00
rustc_interface Stabilize -Zdwarf-version as -Cdwarf-version 2025-04-14 21:26:41 -05:00
rustc_lexer Replace rustc_lexer/unescape with rustc-literal-escaper crate 2025-04-04 14:44:45 +02:00
rustc_lint Rollup merge of #139650 - Alexendoo:group-alias, r=davidtwco 2025-04-17 00:14:25 +02:00
rustc_lint_defs Rollup merge of #139001 - folkertdev:naked-function-rustic-abi, r=traviscross,compiler-errors 2025-04-13 17:37:52 -04:00
rustc_llvm Update the minimum external LLVM to 19 2025-04-05 11:44:38 -07:00
rustc_log Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
rustc_metadata Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk 2025-04-15 15:47:27 +10:00
rustc_middle Rollup merge of #139770 - nnethercote:rename-LifetimeName, r=BoxyUwU 2025-04-17 00:14:26 +02:00
rustc_mir_build Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar 2025-04-15 08:02:23 +00:00
rustc_mir_dataflow Remove support for #[rustc_mir(borrowck_graphviz_format="gen_kill")]. 2025-04-16 08:35:34 +10:00
rustc_mir_transform Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar 2025-04-15 08:02:23 +00:00
rustc_monomorphize Rollup merge of #139818 - compiler-errors:normalize-tails, r=oli-obk 2025-04-15 21:16:03 +02:00
rustc_next_trait_solver Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar 2025-04-15 08:02:23 +00:00
rustc_parse Remove old diagnostic notes for type ascription syntax 2025-04-16 20:24:55 +10:00
rustc_parse_format Update rustc-literal-escaper version to 0.0.2 2025-04-04 22:26:10 +02:00
rustc_passes Use newtype_index!-generated types more idiomatically 2025-04-14 16:17:06 +00:00
rustc_pattern_analysis Fix stack overflow in exhaustiveness due to recursive HIR opaque type values 2025-04-07 22:41:48 +00:00
rustc_privacy Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_query_impl Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_query_system Rollup merge of #139236 - Zoxc:anon-counter, r=davidtwco 2025-04-17 00:14:24 +02:00
rustc_resolve Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco 2025-04-17 00:14:24 +02:00
rustc_sanitizers Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk 2025-04-15 15:47:27 +10:00
rustc_serialize Bump FileEncoder buffer size to 64 kB 2025-04-10 18:52:03 +02:00
rustc_session Rollup merge of #139876 - blyxyas:write_type_sizes, r=nnethercote 2025-04-16 13:45:30 +02:00
rustc_smir Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk 2025-04-15 15:47:27 +10:00
rustc_span Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco 2025-04-17 00:14:24 +02:00
rustc_symbol_mangling Rollup merge of #139848 - nnethercote:kw-Empty-5, r=compiler-errors 2025-04-15 21:16:05 +02:00
rustc_target remove compiler support for extern "rust-intrinsic" blocks 2025-04-06 21:32:58 +02:00
rustc_trait_selection Rename LifetimeName as LifetimeKind. 2025-04-16 07:16:40 +10:00
rustc_traits re-use sized fast path 2025-04-09 10:42:26 +00:00
rustc_transmute Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_ty_utils Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk 2025-04-15 15:47:27 +10:00
rustc_type_ir Auto merge of #139768 - compiler-errors:split-fold, r=lcnr 2025-04-16 01:46:01 +00:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00