aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-05-08 14:52:05 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-05-08 14:53:18 +0000
commitaf58bf3dd274f03235f934dc9d714d1901e66eb5 (patch)
tree153cfb5b637a416b1e6046b9632fe2533cbc4496
parentea597e73da52a4292986b5267fc535006ae4c343 (diff)
downloadgcc-af58bf3dd274f03235f934dc9d714d1901e66eb5.zip
gcc-af58bf3dd274f03235f934dc9d714d1901e66eb5.tar.gz
gcc-af58bf3dd274f03235f934dc9d714d1901e66eb5.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>
-rw-r--r--gcc/rust/backend/rust-compile-type.cc19
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 7eadb38..655f6e6 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 &param_pair : type.get_params ())
{