Skip to content

Commit 0897974

Browse files
committed
split out va_list forwarding into its own test
1 parent 376b284 commit 0897974

File tree

2 files changed

+36
-22
lines changed

2 files changed

+36
-22
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ needs-unwind
2+
//@ compile-flags: -Copt-level=3
3+
//@ min-llvm-version: 21
4+
5+
#![crate_type = "lib"]
6+
#![feature(c_variadic)]
7+
#![no_std]
8+
use core::ffi::VaList;
9+
10+
// Ensure that we do not remove the `va_list` passed to the foreign function when
11+
// removing the "spoofed" `VaList` that is used by Rust defined C-variadics.
12+
13+
extern "C" {
14+
fn foreign_c_variadic_1(_: VaList, ...);
15+
}
16+
17+
// CHECK-LABEL: use_foreign_c_variadic_1_0
18+
pub unsafe extern "C" fn use_foreign_c_variadic_1_0(ap: VaList) {
19+
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %ap)
20+
foreign_c_variadic_1(ap);
21+
}
22+
23+
// CHECK-LABEL: use_foreign_c_variadic_1_1
24+
pub unsafe extern "C" fn use_foreign_c_variadic_1_1(ap: VaList) {
25+
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %ap, i32 noundef 42)
26+
foreign_c_variadic_1(ap, 42i32);
27+
}
28+
pub unsafe extern "C" fn use_foreign_c_variadic_1_2(ap: VaList) {
29+
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %ap, i32 noundef 2, i32 noundef 42)
30+
foreign_c_variadic_1(ap, 2i32, 42i32);
31+
}
32+
33+
pub unsafe extern "C" fn use_foreign_c_variadic_1_3(ap: VaList) {
34+
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %ap, i32 noundef 2, i32 noundef 42, i32 noundef 0)
35+
foreign_c_variadic_1(ap, 2i32, 42i32, 0i32);
36+
}

tests/codegen-llvm/cffi/c-variadic.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use core::ffi::VaList;
99

1010
extern "C" {
1111
fn foreign_c_variadic_0(_: i32, ...);
12-
fn foreign_c_variadic_1(_: VaList, ...);
1312
}
1413

1514
pub unsafe extern "C" fn use_foreign_c_variadic_0() {
@@ -24,27 +23,6 @@ pub unsafe extern "C" fn use_foreign_c_variadic_0() {
2423
foreign_c_variadic_0(0, 42i32, 1024i32, 0i32);
2524
}
2625

27-
// Ensure that we do not remove the `va_list` passed to the foreign function when
28-
// removing the "spoofed" `VaList` that is used by Rust defined C-variadics.
29-
pub unsafe extern "C" fn use_foreign_c_variadic_1_0(ap: VaList) {
30-
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %0)
31-
foreign_c_variadic_1(ap);
32-
}
33-
34-
pub unsafe extern "C" fn use_foreign_c_variadic_1_1(ap: VaList) {
35-
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %0, [[PARAM]] 42)
36-
foreign_c_variadic_1(ap, 42i32);
37-
}
38-
pub unsafe extern "C" fn use_foreign_c_variadic_1_2(ap: VaList) {
39-
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %0, [[PARAM]] 2, [[PARAM]] 42)
40-
foreign_c_variadic_1(ap, 2i32, 42i32);
41-
}
42-
43-
pub unsafe extern "C" fn use_foreign_c_variadic_1_3(ap: VaList) {
44-
// CHECK: call void ({{.*}}, ...) @foreign_c_variadic_1({{.*}} %0, [[PARAM]] 2, [[PARAM]] 42, [[PARAM]] 0)
45-
foreign_c_variadic_1(ap, 2i32, 42i32, 0i32);
46-
}
47-
4826
// Ensure that `va_start` and `va_end` are properly injected.
4927
#[no_mangle]
5028
pub unsafe extern "C" fn c_variadic(n: i32, mut ap: ...) -> i32 {

0 commit comments

Comments
 (0)