* Go patch committed: unalias types for hash/equality functions
@ 2022-06-23 19:22 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-06-23 19:22 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 276 bytes --]
This patch to the Go frontend makes sure to unalias types when
creating hash/equality functions. This fixes
https://go.dev/issue/52846. There is a test case at
https://go.dev/cl/413694. Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu. Committed to mainline.
Ian
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3282 bytes --]
3e134d9c6716f6acaf3e17458c603c3786003fb2
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 737bc483274..629bc666dc0 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 d35c6baf582..e13df0da22b 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 eb3afd94682..39aea769eb2 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),
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-23 19:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-23 19:22 Go patch committed: unalias types for hash/equality functions Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).