From 171e3ae7071792d3907217a0ad26d02a594c67de Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Mon, 6 Nov 2023 11:37:50 +0100 Subject: [PATCH] Add named variadic argument test Variadic arguments may have a name or a pattern. This commit provides two new tests in order to ensure their correct behavior. gcc/testsuite/ChangeLog: * rust/compile/pattern_variadic.rs: New test. * rust/execute/torture/named_variadic.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- .../rust/compile/pattern_variadic.rs | 14 +++++++++++++ .../rust/execute/torture/named_variadic.rs | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/rust/compile/pattern_variadic.rs create mode 100644 gcc/testsuite/rust/execute/torture/named_variadic.rs diff --git a/gcc/testsuite/rust/compile/pattern_variadic.rs b/gcc/testsuite/rust/compile/pattern_variadic.rs new file mode 100644 index 000000000000..2932b70f5b47 --- /dev/null +++ b/gcc/testsuite/rust/compile/pattern_variadic.rs @@ -0,0 +1,14 @@ +extern "C" { + fn printf(fmt: *const i8, _: ...); +} + +fn main() -> i32 { + unsafe { + printf( + "%s" as *const str as *const i8, + "Message" as *const str as *const i8, + ); + } + + 0 +} diff --git a/gcc/testsuite/rust/execute/torture/named_variadic.rs b/gcc/testsuite/rust/execute/torture/named_variadic.rs new file mode 100644 index 000000000000..d9b59cff41c0 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/named_variadic.rs @@ -0,0 +1,20 @@ +// { dg-output "Named variadic" } + +extern "C" { + fn printf(fmt: *const i8, variadic: ...); +} + +fn print(s: &str) { + unsafe { + printf( + "%s" as *const str as *const i8, + s as *const str as *const i8, + ); + } +} + +fn main() -> i32 { + print("Named variadic"); + + 0 +}