diff options
| author | bors <bors@rust-lang.org> | 2021-08-26 10:49:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-26 10:49:25 +0000 |
| commit | 20997f6ad81721542e9ef97bb2f58190903a34d8 (patch) | |
| tree | de8dfb8c6e55afc212f24c99cdad28fc0cd1f43d /compiler/rustc_codegen_llvm/src/llvm_util.rs | |
| parent | 3b3ce374d203445eb1d0dce50f4211f4aceb7db6 (diff) | |
| parent | adf3b013c8b51e7d6ceea33ef3005896cc2cd030 (diff) | |
| download | rust-20997f6ad81721542e9ef97bb2f58190903a34d8.tar.gz rust-20997f6ad81721542e9ef97bb2f58190903a34d8.zip | |
Auto merge of #83698 - erikdesjardins:undefconst, r=RalfJung,oli-obk
Use undef for uninitialized bytes in constants
Fixes #83657
This generates good code when the const is fully uninit, e.g.
```rust
#[no_mangle]
pub const fn fully_uninit() -> MaybeUninit<[u8; 10]> {
const M: MaybeUninit<[u8; 10]> = MaybeUninit::uninit();
M
}
```
generates
```asm
fully_uninit:
ret
```
as you would expect.
There is no improvement, however, when it's partially uninit, e.g.
```rust
pub struct PartiallyUninit {
x: u64,
y: MaybeUninit<[u8; 10]>
}
#[no_mangle]
pub const fn partially_uninit() -> PartiallyUninit {
const X: PartiallyUninit = PartiallyUninit { x: 0xdeadbeefcafe, y: MaybeUninit::uninit() };
X
}
```
generates
```asm
partially_uninit:
mov rax, rdi
mov rcx, qword ptr [rip + .L__unnamed_1+16]
mov qword ptr [rdi + 16], rcx
movups xmm0, xmmword ptr [rip + .L__unnamed_1]
movups xmmword ptr [rdi], xmm0
ret
.L__unnamed_1:
.asciz "\376\312\357\276\255\336\000"
.zero 16
.size .L__unnamed_1, 24
```
which copies a bunch of zeros in place of the undef bytes, the same as before this change.
Edit: generating partially-undef constants isn't viable at the moment anyways due to #84565, so it's disabled
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/llvm_util.rs')
0 files changed, 0 insertions, 0 deletions
