3 ms·
That seems to match the logic clang-trunk is using: If the assignment is in the initializer then its using the simple C++ RVO-style call to blah(): void z
by josephg 8y ago
That seems to match the logic clang-trunk is using:
If the assignment is in the initializer then its using the simple C++ RVO-style call to blah():
void zot() {
foo f = blah();
}
zot:
push rbp
mov rbp, rsp
sub rsp, 1040
lea rdi, [rbp - 1040]
call blah
add rsp, 1040
pop rbp
ret
But if the variable has the opportunity to leak then it adds a memcpy in the caller:
void zot() {
foo f;
leak(&f);
f = blah();
}
zot:
push rbp
mov rbp, rsp
sub rsp, 2080
lea rdi, [rbp - 1040]
call leak
lea rdi, [rbp - 2080]
call blah
mov eax, 1036
mov edx, eax
lea rdi, [rbp - 1040]
lea rcx, [rbp - 2080]
mov rsi, rcx
call memcpy
add rsp, 2080
pop rbp
ret
Although weirdly the memcpy is removed when optimizations are turned on. This may be a bug.