[llvm] r221077 - Docs: update va_arg example with valid x86_64 va_list type.

Tim Northover tnorthover at apple.com
Sat Nov 1 18:21:52 PDT 2014


Author: tnorthover
Date: Sat Nov  1 20:21:51 2014
New Revision: 221077

URL: http://llvm.org/viewvc/llvm-project?rev=221077&view=rev
Log:
Docs: update va_arg example with valid x86_64 va_list type.

The given example was overflowing its alloca and segfaulting if actually run on
x86, so it's a good idea to provide something that works there too.

Patch by Ramkumar Ramachandra.

Modified:
    llvm/trunk/docs/LangRef.rst

Modified: llvm/trunk/docs/LangRef.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/LangRef.rst?rev=221077&r1=221076&r2=221077&view=diff
==============================================================================
--- llvm/trunk/docs/LangRef.rst (original)
+++ llvm/trunk/docs/LangRef.rst Sat Nov  1 20:21:51 2014
@@ -6884,14 +6884,21 @@ variable argument handling intrinsic fun
 
 .. code-block:: llvm
 
+    ; This struct is different for every platform. For most platforms,
+    ; it is merely an i8*.
+    %struct.va_list = type { i8* }
+
+    ; For Unix x86_64 platforms, va_list is the following struct:
+    ; %struct.va_list = type { i32, i32, i8*, i8* }
+
     define i32 @test(i32 %X, ...) {
       ; Initialize variable argument processing
-      %ap = alloca i8*
-      %ap2 = bitcast i8** %ap to i8*
+      %ap = alloca %struct.va_list
+      %ap2 = bitcast %struct.va_list* %ap to i8*
       call void @llvm.va_start(i8* %ap2)
 
       ; Read a single integer argument
-      %tmp = va_arg i8** %ap, i32
+      %tmp = va_arg i8* %ap2, i32
 
       ; Demonstrate usage of llvm.va_copy and llvm.va_end
       %aq = alloca i8*





More information about the llvm-commits mailing list