From 7b90f5e5212b056dfac763b6a4e79b533dbe4f2b Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Thu, 25 Apr 2024 14:54:23 +0200 Subject: gccrs: Change return type of lookup_hir_trait_item Change the return type to an optional instead of returning a null pointer. This allows easier tracking of rogue null pointers in the map. This commit also fixes a bug in trait associated function mangling, the function was using an already invalidated pointer. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt return type to new optional. * backend/rust-mangle-v0.cc (v0_function_path): Change prototype to use the generic arguments vector instead of the whole HIR function. (v0_path): Fix a bug with a null pointer being used to create the trait function mangling. * util/rust-hir-map.cc (Mappings::insert_hir_trait_item): Adapt code to new return type. (Mappings::lookup_hir_trait_item): Change the return type of the function to an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/backend/rust-compile-resolve-path.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc') diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 1f7dc7d..bf294e4 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -256,10 +256,11 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, else { // it might be resolved to a trait item - HIR::TraitItem *trait_item + tl::optional trait_item = ctx->get_mappings ().lookup_hir_trait_item (ref); + HIR::Trait *trait = ctx->get_mappings ().lookup_trait_item_mapping ( - trait_item->get_mappings ().get_hirid ()); + trait_item.value ()->get_mappings ().get_hirid ()); Resolver::TraitReference *trait_ref = &Resolver::TraitReference::error_node (); @@ -285,7 +286,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup, // this means we are defaulting back to the trait_item if // possible Resolver::TraitItemReference *trait_item_ref = nullptr; - bool ok = trait_ref->lookup_hir_trait_item (*trait_item, + bool ok = trait_ref->lookup_hir_trait_item (*trait_item.value (), &trait_item_ref); rust_assert (ok); // found rust_assert (trait_item_ref->is_optional ()); // has definition -- cgit v1.1