From: Ian Lance Taylor Date: Wed, 22 Jun 2022 23:40:24 +0000 (-0700) Subject: compiler: unalias types for hash/equality functions X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=038a7150ec07770174907b93bc93caaa1e019f92;p=platform%2Fupstream%2Fgcc.git compiler: unalias types for hash/equality functions Test case is https://go.dev/cl/413694. Fixes golang/go#52846 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413660 --- diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 737bc48..629bc66 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -77821de1a149c2e6ef9c154ae384c16292173039 +6c3752315dc9b82d0f3f3ac646a1e7376818f84a The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index d35c6ba..e13df0d 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -2811,7 +2811,7 @@ Specific_type_functions::type(Type* t) case Type::TYPE_MAP: { - Type* key_type = t->map_type()->key_type(); + Type* key_type = t->map_type()->key_type()->unalias(); if (key_type->needs_specific_type_functions(this->gogo_)) key_type->hash_function(this->gogo_, NULL); } diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index eb3afd9..39aea76 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -1764,6 +1764,9 @@ Type::needs_specific_type_functions(Gogo* gogo) Named_object* Type::hash_function(Gogo* gogo, Function_type* hash_fntype) { + if (this->named_type() != NULL) + go_assert(!this->named_type()->is_alias()); + if (!this->is_comparable()) return NULL; @@ -2067,6 +2070,9 @@ Type::write_identity_hash(Gogo* gogo, int64_t size) Named_object* Type::equal_function(Gogo* gogo, Named_type* name, Function_type* equal_fntype) { + if (this->named_type() != NULL) + go_assert(!this->named_type()->is_alias()); + // If the unaliased type is not a named type, then the type does not // have a name after all. if (name != NULL) @@ -6700,7 +6706,8 @@ Struct_type::write_hash_function(Gogo* gogo, Function_type* hash_fntype) subkey = Expression::make_cast(key_arg_type, subkey, bloc); // Get the hash function to use for the type of this field. - Named_object* hash_fn = pf->type()->hash_function(gogo, hash_fntype); + Named_object* hash_fn = + pf->type()->unalias()->hash_function(gogo, hash_fntype); // Call the hash function for the field, passing retval as the seed. ref = Expression::make_temporary_reference(retval, bloc); @@ -7553,8 +7560,8 @@ Array_type::write_hash_function(Gogo* gogo, Function_type* hash_fntype) gogo->start_block(bloc); // Get the hash function for the element type. - Named_object* hash_fn = this->element_type_->hash_function(gogo, - hash_fntype); + Named_object* hash_fn = + this->element_type_->unalias()->hash_function(gogo, hash_fntype); // Get a pointer to this element in the loop. Expression* subkey = Expression::make_temporary_reference(key, bloc); @@ -8441,8 +8448,8 @@ Map_type::do_type_descriptor(Gogo* gogo, Named_type* name) ++p; go_assert(p->is_field_name("hasher")); Function_type* hasher_fntype = p->type()->function_type(); - Named_object* hasher_fn = this->key_type_->hash_function(gogo, - hasher_fntype); + Named_object* hasher_fn = + this->key_type_->unalias()->hash_function(gogo, hasher_fntype); if (hasher_fn == NULL) vals->push_back(Expression::make_cast(hasher_fntype, Expression::make_nil(bloc),