[llvm-dev] calling va_arg functions on win32 seems to require explicit stack alignment?
Reid Kleckner via llvm-dev
llvm-dev at lists.llvm.org
Mon Nov 6 08:58:14 PST 2017
Looks like the LLVM va_arg instruction is broken on 32-bit Windows,
probably because we think i64 is aligned on the stack, when it is not.
On Sun, Nov 5, 2017 at 8:58 AM, Nikodemus Siivola via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> 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
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171106/3139311c/attachment.html>
More information about the llvm-dev
mailing list