Skip to content

Commit

Permalink
gccrs: [E0045] Variadic Parameters Used on Non-C ABI Function
Browse files Browse the repository at this point in the history
Added error code support for using variadic parameters used
on Non-C ABI function. Fixes Rust-GCC#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>
  • Loading branch information
MahadMuhammad authored and CohenArthur committed Jan 16, 2024
1 parent 5141707 commit da58dc1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-implitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 (),
Expand Down
7 changes: 7 additions & 0 deletions gcc/testsuite/rust/compile/abi-vardaic.rs
Original file line number Diff line number Diff line change
@@ -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" }
}
}

0 comments on commit da58dc1

Please sign in to comment.