[LLVMdev] X86 gcc and clang have incompatible calling conventions for returning some small structs?
eli.friedman at gmail.com
Thu Jul 8 10:32:58 PDT 2010
On Thu, Jul 8, 2010 at 5:58 AM, Kees van Reeuwijk <reeuwijk at few.vu.nl> wrote:
> For the function new_s() both the current Ubuntu gcc and the current Ubuntu clang generate code to return struct s in registers.
> However for the function new_s3() the gcc compiler uses the stack, whereas clang uses registers, so the generated code is not
movl %edi, %edx
movl %edx, %eax
shlq $32, %rax
addq %rdx, %rax
shll $2, %edx
movl %edi, %eax
leal 0(,%rdi,4), %edx
movl %edi, -24(%rsp)
movl %eax, -20(%rsp)
movq -24(%rsp), %rax
Both compilers are in fact returning the struct in RAX and RDX. gcc
is just preferring to compute the value of RAX using the stack;
-24(%rsp) is scratch space.
The relevant specification is http://www.x86-64.org/documentation/abi.pdf .
More information about the llvm-dev