[AIX] Lint on structs that have a different alignment in AIX's C ABI by amy-kwan · Pull Request #135552 · rust-lang/rust (original) (raw)
In rust-lang#90877 (comment)
T-lang decided they did not wish to remove intrinsics::pref_align_of
.
However, the intrinsic and its supporting code
- is a nightly feature, so can be removed at compiler/libs discretion
- requires considerable effort in the compiler to support, as it necessarily complicates every single site reasoning about alignment
- has been justified based on relevance to codegen, but it is only a requirement for C++ (not C, not Rust) stack frame layout for AIX[^1], in ways Rust would not consider even with increased C++ interop
- is only used by rustc to overalign some globals[^3], not correctness
- can be adequately replaced by other rules for globals, as it mostly affects alignments for a few types under 16 bytes of alignment
- has only one clear benefactor: automating C -> Rust translation
for GNU extensions[^4] like
__alignof
- was likely intended to be
alignof
,_Alignof
, AKAmem::align_of
, because the GNU extension is a "false friend" of the C keyword, which makes the choice to support such a mapping very questionable - makes it easy to do incorrect codegen with the compiler by its mere presence, as usual Rust rules of alignment (e.g. size == align * N) do not hold with preferred alignment[^5]
The implementation is clearly damaging the code quality of the compiler. Thus it is within the compiler team's purview to simply rip it out. If T-lang wishes to have this intrinsic restored for c2rust's benefit, it would have to use a radically different implementation that somehow does not cause internal incorrectness. Good luck in implementing that. Until then, remove the intrinsic and its supporting code, as one tool and an ill-considered GCC extension cannot justify risking correctness.
Because we touch a fair amount of the compiler to change this at all, and unfortunately the duplication of AbiAndPrefAlign is deep-rooted, we keep an "AbiAlign" type which we can wean code off later.
[^1]: rust-lang#91971 (comment) [^2]: rust-lang#135552 [^3]: as viewable in the code altered by this PR [^4]: c2rust: https://github.com/immunant/c2rust/blame/3b1ec86b9b0cf363adfd3178cc45a891a970eef2/c2rust-transpile/src/translator/mod.rs#L3175 [^5]: rust-lang/rustc_codegen_cranelift#1560