[LLVMdev] va_arg on x86-64

Tomas Lindquist Olsen tomas.l.olsen at gmail.com
Tue Oct 23 22:36:21 PDT 2007


Hi everybody.

I'm developing a D compiler using LLVM as backend (LLVMC [1]). Tonight
I had a look at variadic functions, the thing is though, that I'm on
x86-64, and the va_arg instruction is not working.

I've posted a bug report: http://llvm.org/bugs/show_bug.cgi?id=1740

In there I posted the .ll test case:

define i32 @test(i32 %X, ...) {
  %ap = alloca i8*, i32 1024
  %ap2 = bitcast i8** %ap to i8*
  call void @llvm.va_start(i8* %ap2)
  %tmp = va_arg i8** %ap, i32
  call void @llvm.va_end(i8* %ap2)
  ret i32 %tmp
}

declare void @llvm.va_start(i8*)
declare void @llvm.va_end(i8*)

define i32 @main(i32, i8**, i8**) {
  %ret = call i32(i32, ...)* @test(i32 0, i32 0)
  ret i32 %ret
}

This is based on the code in the language reference. If compiled and
run on x86-64, it segfaults.

After some talking to Chris on IRC, it seems as if fixing this is not
a very high priority, and will not be for quite a long time.
Now, I'm a hobbyist coder doing LLVMDC in my spare time. It's my first
compiler projects and I had no knowledge whatsoever about compiler
writing, the frontend I'm using or LLVM. That is I don't know very
much about architecture intricacies, codegen parts of LLVM etc. This
makes it a daunting task to try and fix LLVM va_arg myself.

Chris suggested that I posted something about all this on this mailing
list. So here it is :) I hope I'm not the only one with an interest in
getting this to work. Or at least that some people are willing to
discuss it further (or help me out if I end up reading up on things to
eventually do it myself)

Thanx
- Tomas Lindquist Olsen

[1] http://www.dsource.org/projects/llvmdc



More information about the llvm-dev mailing list