rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.2k stars 12.7k forks source link

Several platforms still have incorrectly aligned `u128`/`i128` #128950

Open beetrees opened 2 months ago

beetrees commented 2 months ago

I tried this code:

fn main() {
    dbg!(std::mem::align_of::<u128>());
}

I expected to see this happen: The printed alignment to match the alignment used for __int128_t by GCC and Clang.

Instead, this happened: On 64-bit PowerPC, 64-bit SPARC and 64-bit MIPS, Rust thinks the alignment is 8 whereas GCC and Clang think the alignment is 16. The PowerPC 64-bit ABI specifications (both ELFv1 and ELFv2) agree with GCC and Clang (I'm not aware of any specification for 128-bit integers on SPARC64 or MIPS64, but GCC/Clang's behaviour seems to be the de-facto standard). This is because the LLVM data layout for the affected platforms doesn't correctly specify the alignment. This is the same as #54341 but on different architectures (cc rust-lang/lang-team#255). I initially discovered this when running abi-cafe on PowerPC64 to test #128643. I've filed an LLVM bug at llvm/llvm-project#102783.

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (ca5d25e2c 2024-08-09)
binary: rustc
commit-hash: ca5d25e2c41f5a6b4ce65c681bf2f94c7ead1f14
commit-date: 2024-08-09
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
beetrees commented 2 months ago

@rustbot label +A-abi +A-ffi +A-llvm +T-compiler

tgross35 commented 2 months ago

For reference: https://godbolt.org/z/jvrxv7jP7