Closed ErikMcClure closed 4 years ago
I don't like needing to use va_start and va_end like this is C. Terra is a higher level language, it should be able to use ...
to access varargs.
Having a function in terralib that turns varargs into an iterable list for consuming in a for loop would be nice, and we should be able to just use ...
to forward varargs to another function.
@aiverson I think these are good points and a starting point for future discussion on what a truly "Terra native" varargs support would look like. On the other hand, being able to support C ABI compatibility is also useful, so I think this patch is worthwhile.
@ErikMcClure could you add a test like what you have in the issue description? I want to make sure we actually test this behavior, if we want to support it.
@elliottslaughter I've added a test that uses a C function to iterate through and validate each example argument using va_arg
. This only tests passing through the va_list
parameter.
Looks like llvm.org must have been down, but I plan to merge this. (Will try to restart the tests first, but if it's still down I'll just merge.)
Ok, whatever. llvm.org is still down. I'm just going to merge this.
It turns out that Terra can actually forward varargs if you allow vararg function definitions, by using LLVM's built-in
va_list
intrinsics. Here is an example of a logging function:It may be possible to extract individual arguments out, but I haven't attempted to use LLVM's
va_arg
intrinsic, and Terra might not like it. This change simply forwards the varargs state to the function definition.