How to use `byval` with C API

Following my other post about passing arrays as parameters I wanted to actually experiment with the byval parameters but I don’t see anyway to add them via the C API. Can anyone show an example of how this works? I think it’s part of the attribute functions but it’s it’s not clear how that may work. I’m using LLVM 16. thanks again.

I think you want LLVMCreateTypeAttribute?

I thought so too but what is the parameter to pass? There is a KindID and I don’t see what value is supposed to be used (it’s just an int).

You can use LLVMGetEnumAttributeKindForName().

Ok I see now there is a list of names at LLVM Language Reference Manual — LLVM 17.0.0git documentation.

So we can create the attribute by using LLVMCreateTypeAttribute and then use LLVMAddAttributeAtIndex to assign the attribute to the function? It looks like the “F” parameter is the function returned from LLVMAddFunction, but that doesn’t quite make sense though because then how do you specify the parameter index which the attributed is being added to?