aboutsummaryrefslogtreecommitdiff
path: root/gcc/hash-table.h
diff options
context:
space:
mode:
authorPatrick Palka <ppalka@redhat.com>2020-05-20 09:15:48 -0400
committerPatrick Palka <ppalka@redhat.com>2020-05-20 09:15:48 -0400
commit610ae2dbbf98a291782cb05c0fb31e056193e5e2 (patch)
treef5edf193aa25d5def8c3a2ab87a7ac47912ca9dd /gcc/hash-table.h
parent053dc901e0227bb62b65f3a8d7a9deccb61dffa1 (diff)
downloadgcc-610ae2dbbf98a291782cb05c0fb31e056193e5e2.zip
gcc-610ae2dbbf98a291782cb05c0fb31e056193e5e2.tar.gz
gcc-610ae2dbbf98a291782cb05c0fb31e056193e5e2.tar.bz2
c++: spec_hasher and TYPENAME_TYPE resolution [PR95223]
After enabling sanitization of the specialization tables, we are triggering one of the hash table sanity checks in the below testcase. The reason is that when looking up the specialization j<int> in the type_specializations table, the sanity check finds that the existing entry j<n<t>::m> compares equal to j<int> but hashes differently. The discrepancy is due to structural_comptypes looking through TYPENAME_TYPEs (via resolve_typename_type), something which iterative_hash_template_arg doesn't do. So the TYPENAME_TYPE n<t>::m is considered equal to int, but the hashes of these two template arguments are different. It seems wrong for the result of a specialization table lookup to depend on the current scope, so this patch makes structural_comptypes avoid calling resolve_typename_type when comparing_specializations. In order for the below testcase to deterministically trigger the sanitization error without this patch, we also need to fix the location of the call to hash_table::verify within hash_table::find_with_hash. gcc/ChangeLog: PR c++/95223 * hash-table.h (hash_table::find_with_hash): Move up the call to hash_table::verify. gcc/cp/ChangeLog: PR c++/95223 * typeck.c (structural_comptypes): Don't perform context-dependent resolution of TYPENAME_TYPEs when comparing_specializations. gcc/testsuite/ChangeLog: PR c++/95223 * g++.dg/template/typename23.C: New test.
Diffstat (limited to 'gcc/hash-table.h')
-rw-r--r--gcc/hash-table.h14
1 files changed, 7 insertions, 7 deletions
diff --git a/gcc/hash-table.h b/gcc/hash-table.h
index a1423c7..32f3a63 100644
--- a/gcc/hash-table.h
+++ b/gcc/hash-table.h
@@ -912,6 +912,12 @@ hash_table<Descriptor, Lazy, Allocator>
if (Lazy && m_entries == NULL)
m_entries = alloc_entries (size);
+
+#if CHECKING_P
+ if (m_sanitize_eq_and_hash)
+ verify (comparable, hash);
+#endif
+
value_type *entry = &m_entries[index];
if (is_empty (*entry)
|| (!is_deleted (*entry) && Descriptor::equal (*entry, comparable)))
@@ -928,13 +934,7 @@ hash_table<Descriptor, Lazy, Allocator>
entry = &m_entries[index];
if (is_empty (*entry)
|| (!is_deleted (*entry) && Descriptor::equal (*entry, comparable)))
- {
-#if CHECKING_P
- if (m_sanitize_eq_and_hash)
- verify (comparable, hash);
-#endif
- return *entry;
- }
+ return *entry;
}
}