]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0045] Variadic Parameters Used on Non-C ABI Function
authorMuhammad Mahad <mahadtxt@gmail.com>
Wed, 19 Jul 2023 10:49:25 +0000 (15:49 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:56:00 +0000 (18:56 +0100)
Added error code support for using variadic parameters used
on Non-C ABI function. Fixes #2382

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
Added check for error code support.

gcc/testsuite/ChangeLog:

* rust/compile/abi-vardaic.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-implitem.cc
gcc/testsuite/rust/compile/abi-vardaic.rs [new file with mode: 0644]

index 189dd8797d112711353876753b4e4fb1327638df..92868b9e343aee63d3d4f946f832341844424349 100644 (file)
@@ -138,7 +138,15 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
 
   uint8_t flags = TyTy::FnType::FNTYPE_IS_EXTERN_FLAG;
   if (function.is_variadic ())
-    flags |= TyTy::FnType::FNTYPE_IS_VARADIC_FLAG;
+    {
+      flags |= TyTy::FnType::FNTYPE_IS_VARADIC_FLAG;
+      if (parent.get_abi () != Rust::ABI::C)
+       {
+         rust_error_at (
+           function.get_locus (), ErrorCode ("E0045"),
+           "C-variadic function must have C or cdecl calling convention");
+       }
+    }
 
   RustIdent ident{
     CanonicalPath::new_seg (function.get_mappings ().get_nodeid (),
diff --git a/gcc/testsuite/rust/compile/abi-vardaic.rs b/gcc/testsuite/rust/compile/abi-vardaic.rs
new file mode 100644 (file)
index 0000000..b5e0c9a
--- /dev/null
@@ -0,0 +1,7 @@
+// https://doc.rust-lang.org/error_codes/E0045.html
+#![allow(unused)]
+fn main() {
+    extern "Rust" {
+        fn foo(x: u8, ...); // { dg-error "C-variadic function must have C or cdecl calling convention" }
+    }
+}
\ No newline at end of file