On 8 Jul 2012, at 5:15, Alex Rønne Petersen wrote:
> I would seriously appreciate it if someone could think of a clever way
> that this could be done, because reimplementing va_arg by hand for
> every target is not feasible.
Unfortunately, that's pretty much the only option right now, and what
Clang does – LLVM's va_arg instruction does not work with aggregate
types (see the Language Reference). Why? I'm not sure…
We also can't just borrow Clang's implementation, because behind the
scenes it recognizes __builtin_va_arg calls are lowers them into a
series of LLVM instructions. The code depends on Clang data structures
to get the necessary type information (as opposed to the "lowered" LLVM
types). Thus, the code would need to be adapted quite a bit anyway, and
as actual code in D form, it's much more readable than code for
synthesizing LLVM instructions, at least for complex ABIs like System V
x86_64. This is an option which simply isn't feasible in C/C++ due to
the lack of expressive enough metaprogramming features…
I have a rewrite of varargs on x86 in the pipe (so that they actually
work and conform to the C ABI), but I can't see a way how this could be
changed.
David