[llvm-dev] calling va_arg functions on win32 seems to require explicit stack alignment?

Nikodemus Siivola via llvm-dev llvm-dev at lists.llvm.org
Sun Nov 5 08:58:54 PST 2017


target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-pc-windows-msvc"

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

define i64 @foo(...) {
    %va = alloca i8*, i32 16 ; 4 words should be enough?
    call void @llvm.va_start(i8** %va)
    %x = va_arg i8** %va, i64
    call void @llvm.va_end(i8** %va)
    ret i64 %x
}

;; should return 123
define i32 @main() {
    %val0 = call i64(...) @foo(i64 123)
    %res = trunc i64 %val0 to i32
    ret i32 %res
}

Running this returns  mostly 0, but sometimes 123.

$ while sleep 1; do lli bug.ll; echo $?; done
123
0
0
0
123
0
0

Adding { alignstack=8 } to main makes it always return 123.

Is this a bug or just a missing piece of documentation?

Cheers,

  -- nikodemus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171105/a4fd8c46/attachment.html>


More information about the llvm-dev mailing list