From e857a3b67905628c97360df77f8f2c8456e4e7b9 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 8 May 2023 14:52:05 +0100 Subject: [PATCH] gccrs: we can only return unit-type when the ABI is non C gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): add filter Signed-off-by: Philip Herron --- gcc/rust/backend/rust-compile-type.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index fc58be94df41..29f7cca2e40e 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -177,11 +177,20 @@ TyTyResolveCompile::visit (const TyTy::FnType &type) std::vector parameters; std::vector results; - auto hir_type = type.get_return_type (); - auto ret = TyTyResolveCompile::compile (ctx, hir_type, trait_object_mode); - Location return_type_locus - = ctx->get_mappings ()->lookup_location (hir_type->get_ref ()); - results.push_back (Backend::typed_identifier ("_", ret, return_type_locus)); + // we can only return unit-type if its not the C ABI because it will expect + // void + auto hir_type = type.get_return_type ()->destructure (); + bool return_is_unit = hir_type->is_unit (); + bool is_c_abi = type.get_abi () == ABI::C; + bool should_be_void = is_c_abi && return_is_unit; + if (!should_be_void) + { + auto ret = TyTyResolveCompile::compile (ctx, hir_type, trait_object_mode); + Location return_type_locus + = ctx->get_mappings ()->lookup_location (hir_type->get_ref ()); + results.push_back ( + Backend::typed_identifier ("_", ret, return_type_locus)); + } for (auto ¶m_pair : type.get_params ()) { -- 2.47.2