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>
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 (),
--- /dev/null
+// 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