Open
Description
This is similar to #56356 except this time with more fields:
use std::mem;
struct SV {
capacity: usize,
disc: usize,
data: [usize; 40],
}
impl SV {
fn new() -> SV {
SV { data: unsafe { mem::uninitialized() },
disc: 0,
capacity: 0 }
}
}
pub struct L {
a: SV,
b: SV
}
pub struct Allocation<T> {
f: *mut T,
}
impl<T> Allocation<T> {
pub fn init(self, value: T) {
use std::ptr;
unsafe {
ptr::write(self.f, value);
}
}
}
#[inline(never)]
pub fn foo(a: Allocation<L>) {
a.init(L {
a: SV::new(),
b: SV::new()
});
}
gives:
example::foo:
sub rsp, 680
xorps xmm0, xmm0
movaps xmmword ptr [rsp], xmm0
movaps xmmword ptr [rsp + 336], xmm0
mov rsi, rsp
mov edx, 672
call qword ptr [rip + memcpy@GOTPCREL]
add rsp, 680
ret
vs moving capacity to the end of the struct:
example::foo:
mov qword ptr [rdi], 0
xorps xmm0, xmm0
movups xmmword ptr [rdi + 328], xmm0
mov qword ptr [rdi + 664], 0
ret
The problem is reproducible with C++ so I'll file a new llvm bug too.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: MIR optimizationsFixed by the Named Return Value Opt. (NRVO)Category: An issue proposing an enhancement or a PR with one.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.