Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f75595d
add codegen test for variadics (also replacing some existing does-thi…
RalfJung Jul 23, 2025
1de927c
library/windows_targets: Fix macro expansion error in 'link' macro
itf Jul 24, 2025
546885c
tests: aarch64-outline-atomics: Remove hardcoded target
Gelbpunkt Jul 25, 2025
73e534b
Revert "Move `shared_helpers` test to a dedicated module"
jieyouxu Jul 25, 2025
430f4f5
Check `./x check bootstrap` in `pr-check-1`
jieyouxu Jul 25, 2025
25036f5
canonicalize build root in `tests/run-make/linker-warning`
WaffleLapkin Jul 25, 2025
3dac888
Only run bootstrap tests in `x test` on CI
Kobzol Jul 25, 2025
96340f6
Stop compilation if macro expansion failed
GuillaumeGomez Jul 24, 2025
5dddba5
Add missing `NOTE` annotations in `tests/ui/macros/trace-macro.rs`
GuillaumeGomez Jul 24, 2025
2725138
Update ui tests with new macro early erroring
GuillaumeGomez Jul 24, 2025
11b3f16
bump cargo_metadata
klensy Jul 26, 2025
bd7b023
move uefi test to run-make
folkertdev Jul 25, 2025
3cf03ec
Rollup merge of #144359 - RalfJung:vararg-codegen, r=compiler-errors
matthiaskrgr Jul 26, 2025
6cbddf4
Rollup merge of #144409 - GuillaumeGomez:macro-expansion-early-abort,…
matthiaskrgr Jul 26, 2025
471f604
Rollup merge of #144422 - itf:itf-patch-2-1, r=ChrisDenton
matthiaskrgr Jul 26, 2025
166dfcb
Rollup merge of #144430 - Gelbpunkt:aarch64-outline-atomics-target, r…
matthiaskrgr Jul 26, 2025
d3fd616
Rollup merge of #144445 - jieyouxu:revert-shared_helpers_tests, r=Kobzol
matthiaskrgr Jul 26, 2025
ca79026
Rollup merge of #144453 - WaffleLapkin:canonical-build-root, r=jieyouxu
matthiaskrgr Jul 26, 2025
debedb3
Rollup merge of #144454 - folkertdev:uefi-tests, r=jieyouxu
matthiaskrgr Jul 26, 2025
5b8aa67
Rollup merge of #144464 - Kobzol:x-test-default, r=jieyouxu
matthiaskrgr Jul 26, 2025
b19b5bd
Rollup merge of #144495 - klensy:cargo_metadata, r=lqd
matthiaskrgr Jul 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add codegen test for variadics (also replacing some existing does-thi…
…s-build tests)
  • Loading branch information
RalfJung committed Jul 23, 2025
commit f75595d2cd38e8a0a36ffc18a90fc5b05e290ee3
86 changes: 86 additions & 0 deletions tests/codegen-llvm/cffi/c-variadic-ffi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//! Test calling variadic functions with various ABIs.
//@ add-core-stubs
//@ compile-flags: -Z merge-functions=disabled
//@ revisions: x86_32 x86_32_win x86_64 aarch64 arm32
//@[x86_64] compile-flags: --target x86_64-unknown-linux-gnu
//@[x86_64] needs-llvm-components: x86
//@[x86_32_win] compile-flags: --target i686-pc-windows-msvc
//@[x86_32_win] needs-llvm-components: x86
//@[x86_32] compile-flags: --target i686-unknown-linux-gnu
//@[x86_32] needs-llvm-components: x86
//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
//@[aarch64] needs-llvm-components: aarch64
//@[arm32] compile-flags: --target armv7-unknown-linux-gnueabihf
//@[arm32] needs-llvm-components: arm
#![crate_type = "lib"]
#![feature(no_core)]
#![feature(extended_varargs_abi_support, extern_system_varargs)]
#![no_core]

extern crate minicore;

// CHECK-LABEL: @c
#[unsafe(no_mangle)]
fn c(f: extern "C" fn(i32, ...)) {
// CHECK: call void (i32, ...)
f(22, 44);
}

// CHECK-LABEL: @system
#[unsafe(no_mangle)]
fn system(f: extern "system" fn(i32, ...)) {
// Crucially, this is *always* the C calling convention, even on Windows.
// CHECK: call void (i32, ...)
f(22, 44);
}

// x86_32-LABEL: @cdecl
#[unsafe(no_mangle)]
#[cfg(target_arch = "x86")]
fn cdecl(f: extern "cdecl" fn(i32, ...)) {
// x86_32: call void (i32, ...)
f(22, 44);
}

// x86_64-LABEL: @sysv
#[unsafe(no_mangle)]
#[cfg(target_arch = "x86_64")]
fn sysv(f: extern "sysv64" fn(i32, ...)) {
// x86_64: call x86_64_sysvcc void (i32, ...)
f(22, 44);
}

// x86_64-LABEL: @win
#[unsafe(no_mangle)]
#[cfg(target_arch = "x86_64")]
fn win(f: extern "win64" fn(i32, ...)) {
// x86_64: call win64cc void (i32, ...)
f(22, 44);
}

// CHECK-LABEL: @efiapi
#[unsafe(no_mangle)]
#[cfg(any(
target_arch = "arm",
target_arch = "aarch64",
target_arch = "riscv32",
target_arch = "riscv64",
target_arch = "x86",
target_arch = "x86_64"
))]
fn efiapi(f: extern "efiapi" fn(i32, ...)) {
// x86_32: call void (i32, ...)
// x86_32_win: call void (i32, ...)
// x86_64: call win64cc void (i32, ...)
// aarch64: call void (i32, ...)
// arm32: call arm_aapcscc void (i32, ...)
f(22, 44);
}

// arm32-LABEL: @aapcs
#[unsafe(no_mangle)]
#[cfg(target_arch = "arm")]
fn aapcs(f: extern "aapcs" fn(i32, ...)) {
// arm32: call arm_aapcscc void (i32, ...)
f(22, 44);
}
5 changes: 5 additions & 0 deletions tests/ui/c-variadic/variadic-ffi-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ extern "stdcall" {
//~^ ERROR: C-variadic functions with the "stdcall" calling convention are not supported
}

fn baz(f: extern "Rust" fn(usize, ...)) {
//~^ ERROR: C-variadic functions with the "Rust" calling convention are not supported
f(22, 44);
}

extern "C" {
fn foo(f: isize, x: u8, ...);
}
Expand Down
32 changes: 19 additions & 13 deletions tests/ui/c-variadic/variadic-ffi-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ error[E0045]: C-variadic functions with the "stdcall" calling convention are not
LL | fn printf(_: *const u8, ...);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention

error[E0045]: C-variadic functions with the "Rust" calling convention are not supported
--> $DIR/variadic-ffi-1.rs:15:11
|
LL | fn baz(f: extern "Rust" fn(usize, ...)) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention

error[E0060]: this function takes at least 2 arguments but 0 arguments were supplied
--> $DIR/variadic-ffi-1.rs:23:9
--> $DIR/variadic-ffi-1.rs:28:9
|
LL | foo();
| ^^^-- two arguments of type `isize` and `u8` are missing
|
note: function defined here
--> $DIR/variadic-ffi-1.rs:16:8
--> $DIR/variadic-ffi-1.rs:21:8
|
LL | fn foo(f: isize, x: u8, ...);
| ^^^ - -
Expand All @@ -21,13 +27,13 @@ LL | foo(/* isize */, /* u8 */);
| +++++++++++++++++++++

error[E0060]: this function takes at least 2 arguments but 1 argument was supplied
--> $DIR/variadic-ffi-1.rs:24:9
--> $DIR/variadic-ffi-1.rs:29:9
|
LL | foo(1);
| ^^^--- argument #2 of type `u8` is missing
|
note: function defined here
--> $DIR/variadic-ffi-1.rs:16:8
--> $DIR/variadic-ffi-1.rs:21:8
|
LL | fn foo(f: isize, x: u8, ...);
| ^^^ -
Expand All @@ -37,7 +43,7 @@ LL | foo(1, /* u8 */);
| ++++++++++

error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:26:56
--> $DIR/variadic-ffi-1.rs:31:56
|
LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
| ------------------------------------- ^^^ expected non-variadic fn, found variadic function
Expand All @@ -48,7 +54,7 @@ LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
found fn item `unsafe extern "C" fn(_, _, ...) {foo}`

error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:27:54
--> $DIR/variadic-ffi-1.rs:32:54
|
LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
| ----------------------------------- ^^^ expected variadic fn, found non-variadic function
Expand All @@ -59,7 +65,7 @@ LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
found fn item `extern "C" fn(_, _) {bar}`

error[E0617]: can't pass `f32` to variadic function
--> $DIR/variadic-ffi-1.rs:29:19
--> $DIR/variadic-ffi-1.rs:34:19
|
LL | foo(1, 2, 3f32);
| ^^^^
Expand All @@ -70,7 +76,7 @@ LL | foo(1, 2, 3f32 as c_double);
| +++++++++++

error[E0617]: can't pass `bool` to variadic function
--> $DIR/variadic-ffi-1.rs:30:19
--> $DIR/variadic-ffi-1.rs:35:19
|
LL | foo(1, 2, true);
| ^^^^
Expand All @@ -81,7 +87,7 @@ LL | foo(1, 2, true as c_int);
| ++++++++

error[E0617]: can't pass `i8` to variadic function
--> $DIR/variadic-ffi-1.rs:31:19
--> $DIR/variadic-ffi-1.rs:36:19
|
LL | foo(1, 2, 1i8);
| ^^^
Expand All @@ -92,7 +98,7 @@ LL | foo(1, 2, 1i8 as c_int);
| ++++++++

error[E0617]: can't pass `u8` to variadic function
--> $DIR/variadic-ffi-1.rs:32:19
--> $DIR/variadic-ffi-1.rs:37:19
|
LL | foo(1, 2, 1u8);
| ^^^
Expand All @@ -103,7 +109,7 @@ LL | foo(1, 2, 1u8 as c_uint);
| +++++++++

error[E0617]: can't pass `i16` to variadic function
--> $DIR/variadic-ffi-1.rs:33:19
--> $DIR/variadic-ffi-1.rs:38:19
|
LL | foo(1, 2, 1i16);
| ^^^^
Expand All @@ -114,7 +120,7 @@ LL | foo(1, 2, 1i16 as c_int);
| ++++++++

error[E0617]: can't pass `u16` to variadic function
--> $DIR/variadic-ffi-1.rs:34:19
--> $DIR/variadic-ffi-1.rs:39:19
|
LL | foo(1, 2, 1u16);
| ^^^^
Expand All @@ -124,7 +130,7 @@ help: cast the value to `c_uint`
LL | foo(1, 2, 1u16 as c_uint);
| +++++++++

error: aborting due to 11 previous errors
error: aborting due to 12 previous errors

Some errors have detailed explanations: E0045, E0060, E0308, E0617.
For more information about an error, try `rustc --explain E0045`.
9 changes: 0 additions & 9 deletions tests/ui/c-variadic/variadic-ffi-2-arm.rs

This file was deleted.

28 changes: 0 additions & 28 deletions tests/ui/c-variadic/variadic-ffi-2.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/c-variadic/variadic-ffi-2.stderr

This file was deleted.

Loading