public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
From: arthur.cohen@embecosm.com
To: gcc-patches@gcc.gnu.org
Cc: gcc-rust@gcc.gnu.org, 0xn4utilus <gyanendrabanjare8@gmail.com>
Subject: [COMMITTED 8/9] gccrs: Add variadic check on function params
Date: Wed, 21 Feb 2024 14:15:26 +0100	[thread overview]
Message-ID: <20240221131636.3336103-11-arthur.cohen@embecosm.com> (raw)
In-Reply-To: <20240221131636.3336103-2-arthur.cohen@embecosm.com>

From: 0xn4utilus <gyanendrabanjare8@gmail.com>

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 <gyanendrabanjare8@gmail.com>
---
 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 d57b7cb70fe..fcba57d0a92 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 %<unsafe extern \"C\"%> 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 %<unsafe extern \"C\"%> 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 00000000000..62cbe0f6524
--- /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
-- 
2.42.1


  parent reply	other threads:[~2024-02-21 13:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-21 13:15 [PATCHSET] Update Rust frontend 21/02/2024 arthur.cohen
2024-02-21 13:15 ` [COMMITTED 1/9] gccrs: Fix typo in RegionConstraints instance arthur.cohen
2024-02-21 13:15 ` [COMMITTED 2/9] gccrs: Add testcase for matches!() macro arthur.cohen
2024-02-21 13:15 ` [COMMITTED 3/9] gccrs: Fix rebinding imports arthur.cohen
2024-02-21 13:15 ` [COMMITTED 4/9] gccrs: expand: Fix formatting for "macro not found" error arthur.cohen
2024-02-21 13:15 ` [COMMITTED 5/9] gccrs: Add testcase for #[rustc_const_stable] arthur.cohen
2024-02-21 13:15 ` [COMMITTED 6/9] gccrs: add powi intrinsics arthur.cohen
2024-02-21 13:15 ` [COMMITTED 7/9] gccrs: Fix lookup of TuplePattern sub-pattern types arthur.cohen
2024-02-21 13:15 ` arthur.cohen [this message]
2024-02-21 13:15 ` [COMMITTED 9/9] Update copyright years arthur.cohen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240221131636.3336103-11-arthur.cohen@embecosm.com \
    --to=arthur.cohen@embecosm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc-rust@gcc.gnu.org \
    --cc=gyanendrabanjare8@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).