http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54585
Bug #: 54585
Summary: stack space allocated but never used when calling
functions that return structs in registers
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: [email protected]
ReportedBy: [email protected]
Now that bug #44194 is fixed, and a returned structure used as a parameter is
no longer stored unnecessarily, a new bug is visible: a stack frame is being
allocated that is entirely unused. On x86_64 target with the fix for 44194
backported to the 4.7 branch, this code:
#include <stdint.h>
struct blargh { uint32_t a, b, c; } foo();
void bar(uint32_t a, uint32_t b, uint32_t c);
void func() {
struct blargh s = foo();
bar(s.a, s.b, s.c);
}
no longer uses any stack memory at all, but still the function call reserves 24
bytes with "subq $24,%rsp" and promptly returns it with "addq $24,%rsp". The
generated code looks like this:
func:
.cfi_startproc
xorl %eax, %eax
subq $24, %rsp
.cfi_def_cfa_offset 32
call foo
movq %rax, %rsi
movl %eax, %edi
addq $24, %rsp
.cfi_def_cfa_offset 8
shrq $32, %rsi
jmp bar
.cfi_endproc