[Bug c++/52792] this pointer and return pointer are passed in wrong order when ms_abi is used (x86_64)
ktietz at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Wed Feb 28 10:31:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52792
Kai Tietz <ktietz at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target| |i?86-*-* x86_64-*-*
--- Comment #4 from Kai Tietz <ktietz at gcc dot gnu.org> ---
This issue isn't just about c++. It is for calling conventions using register
as arguments.
For following small sample (using ms_abi by default):
typedef struct agg { long a; long b; long c; } agg;
__declspec(dllexport) struct agg __fastcall c_fastcall(long a, long b, long c)
{
agg r = { a, b, c};
return r;
}
MS' compiler produces:
@c_fastcall@12:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov [eax], ecx
mov ecx, [ebp+0Ch]
mov [eax+4], edx
mov [eax+8], ecx
pop ebp
retn 8
but gcc produces for x86:
@c_fastcall@12:
pushl %ebp
movl %edx, (%ecx)
movl %ecx, %eax
movl %esp, %ebp
movl 8(%ebp), %edx
movl %edx, 4(%ecx)
movl 12(%ebp), %edx
popl %ebp
movl %edx, 8(%ecx)
ret $8
(using -O2 -fno-omit-frame-pointer)
as you can see is the aggregate pointer passed by ms via stack, but by gcc via
first argument register.
More information about the Gcc-bugs
mailing list