diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-05-08 14:52:05 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:37:15 +0100 |
commit | e857a3b67905628c97360df77f8f2c8456e4e7b9 (patch) | |
tree | 86d6ff368a5d3a6071ee1d358f4f3e2245989b72 /gcc | |
parent | cf046027a23df64ed46ade5ae4a5c9d77ea191ab (diff) | |
download | gcc-e857a3b67905628c97360df77f8f2c8456e4e7b9.zip gcc-e857a3b67905628c97360df77f8f2c8456e4e7b9.tar.gz gcc-e857a3b67905628c97360df77f8f2c8456e4e7b9.tar.bz2 |
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 <herron.philip@googlemail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index fc58be9..29f7cca 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<Backend::typed_identifier> parameters; std::vector<Backend::typed_identifier> 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 ()) { |