diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-04-25 14:54:23 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-05-17 15:28:30 +0000 |
commit | dcd38375635ff023a11e695fb2d88bdfb9665feb (patch) | |
tree | 8097ca81dee2ac48eeb7cb862b4c6a801a367c55 /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | 69e1835807dac79b426eb357e87191502d979657 (diff) | |
download | gcc-dcd38375635ff023a11e695fb2d88bdfb9665feb.zip gcc-dcd38375635ff023a11e695fb2d88bdfb9665feb.tar.gz gcc-dcd38375635ff023a11e695fb2d88bdfb9665feb.tar.bz2 |
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 <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index baef4d6..6ca4d62 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<HIR::TraitItem *> 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 |