From d0233c620d79cc7a82541dff5e812613cafd0699 Mon Sep 17 00:00:00 2001 From: 0xn4utilus Date: Wed, 14 Feb 2024 22:19:15 +0530 Subject: [PATCH] Add variadic check on function params gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add variadic check on all parameters. gcc/testsuite/ChangeLog: * rust/compile/issue-2850.rs: New test. Signed-off-by: 0xn4utilus --- gcc/rust/checks/errors/rust-ast-validation.cc | 12 ++++++++---- gcc/testsuite/rust/compile/issue-2850.rs | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-2850.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index d57b7cb70fee..fcba57d0a920 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -132,10 +132,14 @@ ASTValidation::visit (AST::Function &function) rust_error_at (function.get_locus (), "free function without a body"); } - if (function.is_variadic ()) - rust_error_at ( - function.get_function_params ().back ()->get_locus (), - "only foreign or % functions may be C-variadic"); + auto &function_params = function.get_function_params (); + for (auto it = function_params.begin (); it != function_params.end (); it++) + { + if (it->get ()->is_variadic ()) + rust_error_at (it->get ()->get_locus (), + "only foreign or % functions may " + "be C-variadic"); + } AST::ContextualASTVisitor::visit (function); } diff --git a/gcc/testsuite/rust/compile/issue-2850.rs b/gcc/testsuite/rust/compile/issue-2850.rs new file mode 100644 index 000000000000..62cbe0f6524b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2850.rs @@ -0,0 +1,17 @@ +fn myfun0(...,_:i32) {} +// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 } + +fn myfun1(a:i32,...,_:i32) {} +// { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 } + +struct z { + x: f64, + y: f64, +} + +impl z { + fn new(x: f64, ..., y: f64) -> z { + // { dg-error "only foreign or .unsafe extern \"C\". functions may be C-variadic" "" { target *-*-* } .-1 } + z { x: x, y: y } + } +} \ No newline at end of file