[LLVMdev] Question about returning a large struct

Rodney M. Bates rodney_bates at lcwb.coop
Tue Jan 20 09:10:50 PST 2015


In working on generating llvm IR from a different language frontend,
I am looking at clang-produced IR.  When a C function returns a
large struct, I see it gets encoded as a function returning void,
with an added, leftmost parameter, which is the address of a result
area, passed by the caller.

The clang-generated code for the return statement in the function
copies the result twice, once from an alloca for an explicitly
declared (in the C code) local variable to an internally generated
alloca, then again to the result area passed by the caller.

Is this necessary? optional? optimized out later?  It would be
easier for me to leave out the extra alloca and copy, if that
is workable IR code.

---
Rodney Bates
rodney.m.bates at acm.org



More information about the llvm-dev mailing list