[clang] [CIR] Upstream __builtin_va_start and __builtin_va_end (PR #153819)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 15 15:03:03 PDT 2025


================
@@ -3415,4 +3415,81 @@ def CIR_FAbsOp : CIR_UnaryFPToFPBuiltinOp<"fabs", "FAbsOp"> {
   }];
 }
 
+//===----------------------------------------------------------------------===//
+// Variadic Operations
+//===----------------------------------------------------------------------===//
+
+def CIR_VAStartOp : CIR_Op<"va.start"> {
+  let summary = "Starts a variable argument list";
+  let description = [{
+    The cir.va.start operation models the C/C++ va_start macro by
+    initializing a variable argument list at the given va_list storage
+    location.
+
+    The operand must be a pointer to the target's `va_list` representation.
+    This operation has no results and produces its effect by mutating the
+    storage referenced by the pointer operand.
+
+    Each `cir.va.start` must be paired with a corresponding `cir.va.end`
+    on the same logical `va_list` object along all control-flow paths. After
+    `cir.va.end`, the `va_list` must not be accessed unless reinitialized
+    with another `cir.va.start`.
+
+    Lowering typically maps this to the LLVM intrinsic `llvm.va_start`,
+    passing the appropriately decayed pointer to the underlying `va_list`
+    storage.
+
+    Example:
+
+    ```mlir
+    // %args : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>
+    %p = cir.cast(array_to_ptrdecay, %args
+          : !cir.ptr<!cir.array<!rec___va_list_tag x 1>>),
+        !cir.ptr<!rec___va_list_tag>
+    cir.va.start %p : !cir.ptr<!rec___va_list_tag>
+    ```
+  }];
+  let arguments = (ins CIR_PointerType:$arg_list);
----------------
bcardosolopes wrote:

I'm down for retaining it!

https://github.com/llvm/llvm-project/pull/153819


More information about the cfe-commits mailing list