]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Use new name resolver to compile constant items
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 6 Feb 2024 16:21:45 +0000 (17:21 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 14:52:27 +0000 (16:52 +0200)
Constant items were handled only by the old resolver, this lead to an
ICE when using the new resolver on some rust code containing a constant
item as the new and the old resolver cannot be used at the same time.

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): Check the resolver
flag and use the new one when required.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/backend/rust-compile-item.cc

index 8feed51efa4fe23d883140c91b5b57eea2c5122c..609528d86308c0d301932bdb7f7a5eb14c2d9d71 100644 (file)
@@ -76,32 +76,48 @@ CompileItem::visit (HIR::StaticItem &var)
 void
 CompileItem::visit (HIR::ConstantItem &constant)
 {
-  if (ctx->lookup_const_decl (constant.get_mappings ().get_hirid (),
-                             &reference))
+  auto &mappings = constant.get_mappings ();
+
+  if (ctx->lookup_const_decl (mappings.get_hirid (), &reference))
     return;
 
   // resolve the type
   TyTy::BaseType *resolved_type = nullptr;
+
   bool ok
-    = ctx->get_tyctx ()->lookup_type (constant.get_mappings ().get_hirid (),
-                                     &resolved_type);
+    = ctx->get_tyctx ()->lookup_type (mappings.get_hirid (), &resolved_type);
   rust_assert (ok);
 
   // canonical path
-  const Resolver::CanonicalPath *canonical_path = nullptr;
-  ok = ctx->get_mappings ()->lookup_canonical_path (
-    constant.get_mappings ().get_nodeid (), &canonical_path);
-  rust_assert (ok);
+  Resolver::CanonicalPath canonical_path
+    = Resolver::CanonicalPath::create_empty ();
+
+  if (flag_name_resolution_2_0)
+    {
+      auto nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+
+      canonical_path
+       = nr_ctx.values.to_canonical_path (mappings.get_nodeid ()).value ();
+    }
+  else
+    {
+      const Resolver::CanonicalPath *canonical_path_ptr = nullptr;
+      ok = ctx->get_mappings ()->lookup_canonical_path (mappings.get_nodeid (),
+                                                       &canonical_path_ptr);
+      rust_assert (ok);
+      canonical_path = *canonical_path_ptr;
+    }
 
   HIR::Expr *const_value_expr = constant.get_expr ().get ();
   ctx->push_const_context ();
   tree const_expr
-    = compile_constant_item (resolved_type, canonical_path, const_value_expr,
+    = compile_constant_item (resolved_type, &canonical_path, const_value_expr,
                             constant.get_locus ());
   ctx->pop_const_context ();
 
   ctx->push_const (const_expr);
-  ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
+  ctx->insert_const_decl (mappings.get_hirid (), const_expr);
   reference = const_expr;
 }