[llvm-dev] C returning struct by value

Michael Nicolella via llvm-dev llvm-dev at lists.llvm.org
Sun Mar 27 21:48:05 PDT 2016


I'm new to using LLVM and I've started work on a compiler for a language that can interface with C. One thing that caught me off guard was returning a struct from a function by value. It seems that when calling a C function I need to emit llvm ir that, in the caller, emits an alloca for the returned structure, and the C function signature should return void and take a first argument with the pointer annotated with the "sret" attribute.

Can someone help me understand why this detail needs to be understood by the frontend, and isn't handled by maybe annotating the C function with some attribute that says it should conform to a certain calling convention - then just having the signature be to naturally return the struct by value, but the backend knows how to transform it to what it should be?

Cheers
-Mike


More information about the llvm-dev mailing list