Skip to content

Commit

Permalink
Add named variadic argument test
Browse files Browse the repository at this point in the history
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 <pierre-emmanuel.patry@embecosm.com>
  • Loading branch information
P-E-P committed Nov 6, 2023
1 parent b9e6943 commit 171e3ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gcc/testsuite/rust/compile/pattern_variadic.rs
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 20 additions & 0 deletions gcc/testsuite/rust/execute/torture/named_variadic.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 171e3ae

Please sign in to comment.