<div dir="ltr">The problem is that the type of the va_list is platform-specific. No IR example will work on all platforms, unless you overallocate. The LangRef should probably be updated to use the SysV x86_64 va_list as that is the most common and mention in an IR comment that the type depends on the platform.</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 26, 2014 at 12:37 PM, Ramkumar Ramachandra <span dir="ltr"><<a href="mailto:artagnon@gmail.com" target="_blank">artagnon@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
So the Variable Argument Handling Intrinsics section of the LangRef<br>
(<a href="http://llvm.org/docs/LangRef.html#variable-argument-handling-intrinsics" target="_blank">http://llvm.org/docs/LangRef.html#variable-argument-handling-intrinsics</a>)<br>
lists an example that segfaults. Try the following on x86_64:<br>
<br>
-- 8< --<br>
define i32 @test(i32 %X, ...) {<br>
; Initialize variable argument processing<br>
%ap = alloca i8*<br>
%ap2 = bitcast i8** %ap to i8*<br>
call void @llvm.va_start(i8* %ap2)<br>
<br>
; Read a single integer argument<br>
%tmp = va_arg i8** %ap, i32<br>
<br>
; Demonstrate usage of llvm.va_copy and llvm.va_end<br>
%aq = alloca i8*<br>
%aq2 = bitcast i8** %aq to i8*<br>
call void @llvm.va_copy(i8* %aq2, i8* %ap2)<br>
call void @llvm.va_end(i8* %aq2)<br>
<br>
; Stop processing of arguments.<br>
call void @llvm.va_end(i8* %ap2)<br>
ret i32 %tmp<br>
}<br>
<br>
define i32 @main() {<br>
%call = call i32 (i32, ...)* @test(i32 1, i32 3)<br>
ret i32 %call<br>
}<br>
<br>
declare void @llvm.va_start(i8*)<br>
declare void @llvm.va_copy(i8*, i8*)<br>
declare void @llvm.va_end(i8*)<br>
-- 8< --<br>
<br>
It happens because va_arg is apparently not implemented properly on<br>
X86 (I saw tests/Codegen/X86/vaargs.ll). What should be done about the<br>
situation?<br>
1. Update the LangRef.<br>
2. Fix va_arg for x86.<br>
<br>
If (2) is the way to go, I'll take a stab at it.<br>
<br>
Thanks.<br>
<br>
Ram<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>