Is it possible to pass structure by parameter ?
Is it compatible with the C abi ?
[edit]
Basically, I would like to have a C++ POD which would contain two members (the structure would be a fat pointer, with a pointer and an integer), and be able to pass this structure as function parameter in call instructions (even when calling C code).
I’m not using fat pointer now (the pointer and the integer are each in a different function parameter), and I would like to know if it’s possible before starting a pretty big refactoring !
You can do this.
You can figure out what the LLVM code is for sample C by copying and pasting the C code into LLVM’s online demo at http://llvm.org/demo/index.cgi.
If you copy and paste the code at codepad.org in, you’ll see that LLVM generates the following for myFunction:
Of course, if you look at the call you’ll notice that no copy is being made. It’s up to the calling function to do that. If we write a small C function:
We can see that the LLVM bitcode generated for myCallingFunction is:
The calling function makes a copy of the struct, and then passes in the address of the copy.