about summary refs log tree commit diff
path: root/tests/codegen-llvm
diff options
context:
space:
mode:
authorFolkert de Vries <folkert@folkertdev.nl>2025-09-03 00:05:50 +0200
committerFolkert de Vries <folkert@folkertdev.nl>2025-09-03 00:19:18 +0200
commit418900562cb189e68b21acd49116ed8235646578 (patch)
treeccdcd00101fcde3d185ab9820797125fae3b4e5f /tests/codegen-llvm
parent05abce5d058db0de3abd10f32f1a442d0f699b30 (diff)
downloadrust-418900562cb189e68b21acd49116ed8235646578.tar.gz
rust-418900562cb189e68b21acd49116ed8235646578.zip
explicitly start `va_list` lifetime
Diffstat (limited to 'tests/codegen-llvm')
-rw-r--r--tests/codegen-llvm/c-variadic-lifetime.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/codegen-llvm/c-variadic-lifetime.rs b/tests/codegen-llvm/c-variadic-lifetime.rs
new file mode 100644
index 00000000000..5b2f8af18c8
--- /dev/null
+++ b/tests/codegen-llvm/c-variadic-lifetime.rs
@@ -0,0 +1,21 @@
+//@ add-core-stubs
+//@ compile-flags: -Copt-level=3
+#![feature(c_variadic)]
+#![crate_type = "lib"]
+
+// Check that `%args` explicitly has its lifetime start and end. Being explicit can improve
+// instruction and register selection, see e.g. https://github.com/rust-lang/rust/pull/144549
+
+#[unsafe(no_mangle)]
+unsafe extern "C" fn variadic(a: f64, mut args: ...) -> f64 {
+    // CHECK: call void @llvm.lifetime.start.p0(i64 {{[0-9]+}}, ptr nonnull %args)
+    // CHECK: call void @llvm.va_start.p0(ptr nonnull %args)
+
+    let b = args.arg::<f64>();
+    let c = args.arg::<f64>();
+
+    a + b + c
+
+    // CHECK: call void @llvm.va_end.p0(ptr nonnull %args)
+    // CHECK: call void @llvm.lifetime.end.p0(i64 {{[0-9]+}}, ptr nonnull %args)
+}