https://github.com/kumarak updated 
https://github.com/llvm/llvm-project/pull/208741

>From b20cd8e7c8a8d2d0038c476f8ec2660398b7b466 Mon Sep 17 00:00:00 2001
From: AkshayK <[email protected]>
Date: Fri, 10 Jul 2026 10:30:16 -0400
Subject: [PATCH] [CIR] Handle __builtin_c23_va_start

C23 va_start expands to __builtin_c23_va_start, which was hitting the
unimplemented-builtin NYI path, so all variadic code failed to compile
with -fclangir in -std=c23 mode. Lower it exactly like
__builtin_va_start: the va_list is always arg 0.
---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp |  1 +
 clang/test/CIR/CodeGen/var_arg-c23.c    | 41 +++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 clang/test/CIR/CodeGen/var_arg-c23.c

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index 3c48b8b67d9ee..84bb33663de05 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -1059,6 +1059,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
   // C stdarg builtins.
   case Builtin::BI__builtin_stdarg_start:
   case Builtin::BI__builtin_va_start:
+  case Builtin::BI__builtin_c23_va_start:
   case Builtin::BI__va_start: {
     mlir::Value vaList = builtinID == Builtin::BI__va_start
                              ? emitScalarExpr(e->getArg(0))
diff --git a/clang/test/CIR/CodeGen/var_arg-c23.c 
b/clang/test/CIR/CodeGen/var_arg-c23.c
new file mode 100644
index 0000000000000..1bb0b7099b5fe
--- /dev/null
+++ b/clang/test/CIR/CodeGen/var_arg-c23.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
+// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
+// RUN: %clang_cc1 -std=c23 -triple x86_64-unknown-linux-gnu -Wno-unused-value 
-emit-llvm %s -o %t.ll
+// RUN: FileCheck --input-file=%t.ll %s -check-prefix=LLVM
+
+void noargs(...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, 0);
+  __builtin_c23_va_start(list);
+  __builtin_va_end(list);
+}
+
+// CIR-LABEL: cir.func {{.*}} @noargs(
+// CIR:   %[[VAAREA:.+]] = cir.alloca "list" {{.*}} : 
!cir.ptr<!cir.array<!rec___va_list_tag x 1>>
+// CIR:   %[[VA_PTR0:.+]] = cir.cast array_to_ptrdecay %[[VAAREA]]
+// CIR-NEXT:   cir.va_start %[[VA_PTR0]] : !cir.ptr<!rec___va_list_tag>
+// CIR:   %[[VA_PTR1:.+]] = cir.cast array_to_ptrdecay %[[VAAREA]]
+// CIR-NEXT:   cir.va_start %[[VA_PTR1]] : !cir.ptr<!rec___va_list_tag>
+// CIR:   cir.va_end %{{.+}} : !cir.ptr<!rec___va_list_tag>
+
+// LLVM-LABEL: define {{.*}}void @noargs(...)
+// LLVM:   %[[VAAREA:.+]] = alloca [1 x %struct.__va_list_tag]
+// LLVM:   call void @llvm.va_start.p0(ptr %{{.+}})
+// LLVM:   call void @llvm.va_start.p0(ptr %{{.+}})
+// LLVM:   call void @llvm.va_end.p0(ptr %{{.+}})
+
+void with_param(int count, ...) {
+  __builtin_va_list list;
+  __builtin_c23_va_start(list, count);
+  __builtin_va_end(list);
+}
+
+// CIR-LABEL: cir.func {{.*}} @with_param(
+// CIR:   cir.va_start %{{.+}} : !cir.ptr<!rec___va_list_tag>
+// CIR:   cir.va_end %{{.+}} : !cir.ptr<!rec___va_list_tag>
+
+// LLVM-LABEL: define {{.*}}void @with_param(i32 noundef %{{.+}}, ...)
+// LLVM:   call void @llvm.va_start.p0(ptr %{{.+}})
+// LLVM:   call void @llvm.va_end.p0(ptr %{{.+}})

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to