diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-02 17:47:48 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-02 17:47:48 +0200 |
| commit | 33b02385866ecf5d066a808099f79676d4581a06 (patch) | |
| tree | 9ecdfa4db0113ee8bc8a137a1be2df5c7b98f32d /compiler/rustc_codegen_llvm/src | |
| parent | 836ce13ca9deae0d584aa42f5036ea6a07eb911f (diff) | |
| parent | 2ef82805d52a2f53368a56e8d3c9473f3cd89efc (diff) | |
| download | rust-33b02385866ecf5d066a808099f79676d4581a06.tar.gz rust-33b02385866ecf5d066a808099f79676d4581a06.zip | |
Rollup merge of #127168 - DianQK:cast-size, r=workingjubilee
Use the aligned size for alloca at args/ret when the pass mode is cast
Fixes #75839. Fixes #121028.
The `load` and `store` instructions in LLVM access the aligned size. For example, `load { i64, i32 }` accesses 16 bytes on x86_64: https://alive2.llvm.org/ce/z/n8CHAp.
BTW, this example is expected to be optimized to immediate UB by Alive2: https://rust.godbolt.org/z/b7xK7hv1c and https://alive2.llvm.org/ce/z/vZDtZH.
r? compiler
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/abi.rs | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index a6a3f0f9646..d034f9b5256 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -226,7 +226,8 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> { // when passed by value, making it smaller. // - On some ABIs, the Rust layout { u16, u16, u16 } may be padded up to 8 bytes // when passed by value, making it larger. - let copy_bytes = cmp::min(scratch_size.bytes(), self.layout.size.bytes()); + let copy_bytes = + cmp::min(cast.unaligned_size(bx).bytes(), self.layout.size.bytes()); // Allocate some scratch space... let llscratch = bx.alloca(scratch_size, scratch_align); bx.lifetime_start(llscratch, scratch_size); |
