It looks like hash table sanitization is now safe to enable for the
decl_specializations and type_specializations tables, probably ever
since PR94454 was fixed.
Bootstrapped and regtested on x86_64-pc-linux-gnu with the attached
debugging patch that makes all entries hash to 0, and also successfully
built the range-v3 testsuite and a number of other libraries with this
debugging patch. Does this look OK to commit?
gcc/cp/ChangeLog:
PR c++/87847
* pt.c (init_template_processing): Enable sanitization for
decl_specializations and type_specializations.
---
gcc/cp/pt.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c6091127225..2d1869816c5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -29441,9 +29441,8 @@ declare_integer_pack (void)
void
init_template_processing (void)
{
- /* FIXME: enable sanitization (PR87847) */
- decl_specializations = hash_table<spec_hasher>::create_ggc (37, false);
- type_specializations = hash_table<spec_hasher>::create_ggc (37, false);
+ decl_specializations = hash_table<spec_hasher>::create_ggc (37);
+ type_specializations = hash_table<spec_hasher>::create_ggc (37);
if (cxx_dialect >= cxx11)
declare_integer_pack ();
--
2.26.2.561.g07d8ea56f2
From c807f9ae8871d6797fc06c229b2cc5b44e364d31 Mon Sep 17 00:00:00 2001
From: Patrick Palka <ppa...@redhat.com>
Date: Fri, 8 May 2020 14:04:34 -0400
Subject: [PATCH] Verify equal spec_hasher entries have equal hashes
---
gcc/cp/pt.c | 41 ++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index c6091127225..c9b39f126ba 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -1291,7 +1291,7 @@ retrieve_specialization (tree tmpl, tree args, hashval_t hash)
if (hash == 0)
hash = spec_hasher::hash (&elt);
- found = specializations->find_with_hash (&elt, hash);
+ found = specializations->find_with_hash (&elt, 0);
if (found)
return found->spec;
}
@@ -1574,7 +1574,7 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend,
hash = spec_hasher::hash (&elt);
slot =
- decl_specializations->find_slot_with_hash (&elt, hash, INSERT);
+ decl_specializations->find_slot_with_hash (&elt, 0, INSERT);
if (*slot)
fn = ((spec_entry *) *slot)->spec;
else
@@ -1704,6 +1704,15 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend,
int comparing_specializations;
+/* Returns a hash for a template TMPL and template arguments ARGS. */
+
+static hashval_t
+hash_tmpl_and_args (tree tmpl, tree args)
+{
+ hashval_t val = iterative_hash_object (DECL_UID (tmpl), 0);
+ return iterative_hash_template_arg (args, val);
+}
+
bool
spec_hasher::equal (spec_entry *e1, spec_entry *e2)
{
@@ -1726,25 +1735,19 @@ spec_hasher::equal (spec_entry *e1, spec_entry *e2)
}
--comparing_specializations;
+ if (equal)
+ gcc_assert (hash_tmpl_and_args (e1->tmpl, e1->args)
+ == hash_tmpl_and_args (e2->tmpl, e2->args));
return equal;
}
-/* Returns a hash for a template TMPL and template arguments ARGS. */
-
-static hashval_t
-hash_tmpl_and_args (tree tmpl, tree args)
-{
- hashval_t val = iterative_hash_object (DECL_UID (tmpl), 0);
- return iterative_hash_template_arg (args, val);
-}
-
/* Returns a hash for a spec_entry node based on the TMPL and ARGS members,
ignoring SPEC. */
hashval_t
-spec_hasher::hash (spec_entry *e)
+spec_hasher::hash (spec_entry *)
{
- return hash_tmpl_and_args (e->tmpl, e->args);
+ return 0;
}
/* Recursively calculate a hash value for a template argument ARG, for use
@@ -9593,7 +9596,6 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
spec_entry **slot;
spec_entry *entry;
spec_entry elt;
- hashval_t hash;
if (identifier_p (d1))
{
@@ -9770,8 +9772,7 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
elt.tmpl = gen_tmpl;
elt.args = arglist;
elt.spec = NULL_TREE;
- hash = spec_hasher::hash (&elt);
- entry = type_specializations->find_with_hash (&elt, hash);
+ entry = type_specializations->find_with_hash (&elt, 0);
if (entry)
return entry->spec;
@@ -10057,7 +10058,6 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
use it for hash table lookup. */
elt.tmpl = found;
elt.args = arglist = INNERMOST_TEMPLATE_ARGS (arglist);
- hash = spec_hasher::hash (&elt);
}
}
@@ -10065,7 +10065,7 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context,
SET_TYPE_TEMPLATE_INFO (t, build_template_info (found, arglist));
elt.spec = t;
- slot = type_specializations->find_slot_with_hash (&elt, hash, INSERT);
+ slot = type_specializations->find_slot_with_hash (&elt, 0, INSERT);
gcc_checking_assert (*slot == NULL);
entry = ggc_alloc<spec_entry> ();
*entry = elt;
@@ -29441,9 +29441,8 @@ declare_integer_pack (void)
void
init_template_processing (void)
{
- /* FIXME: enable sanitization (PR87847) */
- decl_specializations = hash_table<spec_hasher>::create_ggc (37, false);
- type_specializations = hash_table<spec_hasher>::create_ggc (37, false);
+ decl_specializations = hash_table<spec_hasher>::create_ggc (37);
+ type_specializations = hash_table<spec_hasher>::create_ggc (37);
if (cxx_dialect >= cxx11)
declare_integer_pack ();
--
2.26.2.561.g07d8ea56f2