]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Give the builtin unit struct an actual locus
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 27 Mar 2025 15:15:08 +0000 (15:15 +0000)
committerPhilip Herron <philip.herron@embecosm.com>
Thu, 27 Mar 2025 16:35:26 +0000 (16:35 +0000)
This has been a pet peeve of mine for a while because the gimple never
emitted the struct () name properly it was always empty which for record
types they always require a real locus or they dont get a proper name.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::unit_expression): pass ctx
* backend/rust-compile-base.h: cant be static
* backend/rust-compile-intrinsic.cc (try_handler_inner): pass ctx
* backend/rust-compile-type.cc
(TyTyResolveCompile::get_unit_type): update to grab the first locus
(TyTyResolveCompile::visit): pass ctx
* backend/rust-compile-type.h: likewise

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

index c71417da41eb9fbe979238aa44da21097eabe43d..d8a71f5d7eb666f61011981a27ba5887d560433c 100644 (file)
@@ -1023,7 +1023,7 @@ HIRCompileBase::resolve_method_address (TyTy::FnType *fntype,
 tree
 HIRCompileBase::unit_expression (location_t locus)
 {
-  tree unit_type = TyTyResolveCompile::get_unit_type ();
+  tree unit_type = TyTyResolveCompile::get_unit_type (ctx);
   return Backend::constructor_expression (unit_type, false, {}, -1, locus);
 }
 
index 4d55407ca3b9a33cca7c0123c3ed785013ddb43b..323b1a025226f5139191a5dbb3cb9ba08c00d0cb 100644 (file)
@@ -110,7 +110,7 @@ protected:
                         const Resolver::CanonicalPath &canonical_path,
                         TyTy::FnType *fntype);
 
-  static tree unit_expression (location_t locus);
+  tree unit_expression (location_t locus);
 
   void setup_fndecl (tree fndecl, bool is_main_entry_point, bool is_generic_fn,
                     HIR::Visibility &visibility,
index 31c5d49b0ab25ca38d53fe31b89c408c3a0da071..cd79a7bd0b9aa704edd609bf6f7b957795d32906 100644 (file)
@@ -1322,7 +1322,7 @@ try_handler_inner (Context *ctx, TyTy::FnType *fntype, bool is_new_api)
 
   if (is_new_api)
     {
-      auto ret_type = TyTyResolveCompile::get_unit_type ();
+      auto ret_type = TyTyResolveCompile::get_unit_type (ctx);
       auto ret_expr = Backend::constructor_expression (ret_type, false, {}, -1,
                                                       UNDEF_LOCATION);
       normal_return_stmt
index 58a0d9aaf58630dc5dcb106fab38f4ba16326778..0ab9e420b5dd4ab48820d292a8de039148fb1938 100644 (file)
@@ -81,13 +81,22 @@ TyTyResolveCompile::get_implicit_enumeral_node_type (TyTy::BaseType *repr)
 }
 
 tree
-TyTyResolveCompile::get_unit_type ()
+TyTyResolveCompile::get_unit_type (Context *ctx)
 {
   static tree unit_type;
   if (unit_type == nullptr)
     {
+      auto cn = ctx->get_mappings ().get_current_crate ();
+      auto &c = ctx->get_mappings ().get_ast_crate (cn);
+      location_t locus = BUILTINS_LOCATION;
+      if (c.items.size () > 0)
+       {
+         auto &item = c.items[0];
+         locus = item->get_locus ();
+       }
+
       auto unit_type_node = Backend::struct_type ({});
-      unit_type = Backend::named_type ("()", unit_type_node, BUILTINS_LOCATION);
+      unit_type = Backend::named_type ("()", unit_type_node, locus);
     }
   return unit_type;
 }
@@ -421,7 +430,7 @@ TyTyResolveCompile::visit (const TyTy::TupleType &type)
 {
   if (type.num_fields () == 0)
     {
-      translated = get_unit_type ();
+      translated = get_unit_type (ctx);
       return;
     }
 
@@ -724,7 +733,7 @@ TyTyResolveCompile::visit (const TyTy::StrType &type)
 void
 TyTyResolveCompile::visit (const TyTy::NeverType &)
 {
-  translated = get_unit_type ();
+  translated = get_unit_type (ctx);
 }
 
 void
index b8976e97ac53178d7a49124366fc2c1d695f3f3c..aa20067fc47752d5ac473fc3eda3e947b5bde336 100644 (file)
@@ -30,7 +30,7 @@ public:
   static tree compile (Context *ctx, const TyTy::BaseType *ty,
                       bool trait_object_mode = false);
 
-  static tree get_unit_type ();
+  static tree get_unit_type (Context *ctx);
 
   void visit (const TyTy::InferType &) override;
   void visit (const TyTy::ADTType &) override;