https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105932
Bug ID: 105932 Summary: Small structures returned incorrectly in i386 Microsoft ABI Product: gcc Version: 12.1.0 Status: UNCONFIRMED Keywords: ABI, wrong-code Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: josephcsible at gmail dot com Target Milestone: --- Consider this C code: struct foo { int x, y; }; extern int x, y; struct foo f(void) { struct foo rv; rv.x = x; rv.y = y; return rv; } When compiled with "-O2 -m32 -mabi=ms", it compiles to this: f: movd x, %xmm0 movl 4(%esp), %eax movd y, %xmm1 punpckldq %xmm1, %xmm0 movq %xmm0, (%eax) ret Which expects to be passed a hidden parameter to hold the address of the return value. But in the i386 Microsoft ABI, that's not how returns work for POD types that are 64 bits or smaller. Here's what it should compile to instead: f: movd x, %eax movd y, %edx ret