Open RyanGlScott opened 3 years ago
Looks like varargs functions are used extensively (and exclusively?) in the Juliet benchmarks.
In addition to the intrinsics mentioned above, we would need to add support for the VaArg
instruction as well, which actually extracts an argument from the arglist.
It might be worth noting that Clang doesn't always seem to access va_list
s through the va_arg
instruction:
https://godbolt.org/z/Wq4Gb7bKa
EDIT: In case anyone is curious about what's in that struct, this blog post discusses it. The post contains some outdated information about how LLVM handles va_arg
though. https://blog.nelhage.com/2010/10/amd64-and-va_arg/
Oh, great. Looks like we'll have to reverse-engineer a bunch of ABI details to do this correctly.
In fact, I just double-checked on a bunch of open-source programs and it seems that at least some versions of Clang on some platforms never use va_arg
.
I wonder if this is related to this note in the documentation:
Note that the code generator does not yet fully support va_arg on many targets.
A large number of SV-COMP bechmarks make use of functions defined with varargs in C. In terms of LLVM, supporting varargs would be tantamount to adding overrides for the following three intrinsics:
void @llvm.va_start(i8* <arglist>)
, which initializesarglist
with the varargs of the calling function.void @llvm.va_copy(i8* <destarglist>, i8* <srcarglist>)
, which copiessrcarglist
todestarglist
.void @llvm.va_end(i8* <arglist>)
, which destroys anarglist
that was initialized by@llvm.va_start
or@llvm.va_copy
.@llvm.va_start
seems like the trickiest one to add, since it requires figuring out information about the calling function somehow.