diff --git a/gcc/hash-table.c b/gcc/hash-table.c index bff9644ae81..d396a368171 100644 --- a/gcc/hash-table.c +++ b/gcc/hash-table.c @@ -121,3 +121,5 @@ void dump_hash_table_loc_statistics (void) hash_table_usage ().dump (origin); } } + +bool hash_table_verify_p = false; diff --git a/gcc/hash-table.h b/gcc/hash-table.h index bd83345c7b8..2d740b42535 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -240,6 +240,10 @@ along with GCC; see the file COPYING3. If not see #include "hash-traits.h" #include "hash-map-traits.h" +#ifndef GENERATOR_FILE +extern bool hash_table_verify_p; +#endif + template class hash_map; template class hash_set; @@ -883,12 +887,31 @@ hash_table expand (); m_searches++; + size_t size = m_size; + +#ifndef GENERATOR_FILE + if (hash_table_verify_p) + if (insert == INSERT) + for (size_t i = 0; i < size; i++) + { + value_type *entry = &m_entries[i]; + if (!is_empty (*entry) && !is_deleted (*entry) + && Descriptor::equal (*entry, comparable) + && hash != Descriptor::hash (*entry)) + { + fprintf (stderr, "hash table checking failed: " + "equal operator returns true for a pair " + "of values with a different hash value"); + gcc_unreachable (); + } + } +#endif +// TODO: enable it also for generated files: there are failures! value_type *first_deleted_slot = NULL; hashval_t index = hash_table_mod1 (hash, m_size_prime_index); hashval_t hash2 = hash_table_mod2 (hash, m_size_prime_index); value_type *entry = &m_entries[index]; - size_t size = m_size; if (is_empty (*entry)) goto empty_entry; else if (is_deleted (*entry)) diff --git a/gcc/toplev.c b/gcc/toplev.c index d7ea11abf53..4cd3aafa2e8 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -2289,6 +2289,9 @@ toplev::main (int argc, char **argv) handle_common_deferred_options (); + if (flag_checking > 2) + hash_table_verify_p = true; + init_local_tick (); initialize_plugins ();