aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-02-06 17:21:45 +0100
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-03-26 17:35:02 +0000
commit4d64d55f5a8e2ed4fbeca2d56da7c51d65fe040b (patch)
treed1302f878fe7d8b53fd3e5e36e95b3bf786282c3 /gcc
parentc14e44a53c10a8bcd3fbe87c243ac65ea5aa813b (diff)
downloadgcc-4d64d55f5a8e2ed4fbeca2d56da7c51d65fe040b.zip
gcc-4d64d55f5a8e2ed4fbeca2d56da7c51d65fe040b.tar.gz
gcc-4d64d55f5a8e2ed4fbeca2d56da7c51d65fe040b.tar.bz2
Use new name resolver to compile constant items
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-item.cc36
1 files changed, 26 insertions, 10 deletions
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index 8feed51..609528d 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -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;
}