]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: we can only return unit-type when the ABI is non C
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 8 May 2023 13:52:05 +0000 (14:52 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:15 +0000 (18:37 +0100)
gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): add filter

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-type.cc

index fc58be94df41cb23b1c18568f34c33ca7d31449d..29f7cca2e40e7a370885fa3efcd3dd69a5db8b6a 100644 (file)
@@ -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 ())
     {