[LLVMdev] Proposing a new 'alloca' parameter attribute to implement the Microsoft C++ ABI

Duncan Sands baldrick at free.fr
Mon Jul 29 07:59:05 PDT 2013

Hi Reid,

>         struct A {int x; int y;};
>         A foo();
>         void bar(int, A, int);
>         ...
>         bar(0xdead, foo(), 0xbeef);
>         x86_32 pseudo intel asm:
>         push 0xdead
>         sub esp, 8
>         push esp  # sret arg for foo
>         call foo
>         add esp, 4 # clear sret arg
>         push 0xbeef
>         call bar
>     I got confused by your example.  Is the struct passed on the stack, amongst the
>     other parameters, or can it be allocated somewhere else and a pointer to it
>     passed?  Because in your example it isn't clear to me how the return value of
>     foo() is being passed to bar().
> Yes, the struct is passed amongst the other parameters.  LLVM already supports
> passing C structs this way using byval, but it emits a memcpy in the backend,
> which breaks C++ objects.
> foo() is returning an A struct via the usual hidden sret parameter.  The "push
> esp" is taking the address of the struct's outgoing arg slot and passing it to
> foo().

indeed!  This seems perfectly obvious now that you explained it, sorry for being

Ciao, Duncan.

More information about the llvm-dev mailing list