public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Arthur Cohen <cohenarthur@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-9113] gccrs: Add variadic check on function params
Date: Wed, 21 Feb 2024 12:52:07 +0000 (GMT)	[thread overview]
Message-ID: <20240221125207.D9E3C3858D20@sourceware.org> (raw)

https://gcc.gnu.org/g:e7c1948fbccfff72fe2c25e962528b398123bfb3

commit r14-9113-ge7c1948fbccfff72fe2c25e962528b398123bfb3
Author: 0xn4utilus <gyanendrabanjare8@gmail.com>
Date:   Wed Feb 14 22:19:15 2024 +0530

    gccrs: 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 <gyanendrabanjare8@gmail.com>

Diff:
---
 gcc/rust/checks/errors/rust-ast-validation.cc | 12 ++++++++----
 gcc/testsuite/rust/compile/issue-2850.rs      | 17 +++++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

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 %<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 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

                 reply	other threads:[~2024-02-21 12:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240221125207.D9E3C3858D20@sourceware.org \
    --to=cohenarthur@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).