]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/hash-table.c
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / hash-table.c
index 012b241906de7598ac61105acd8994c913702619..a1603ee017044e6696552152ed65bd64456a54e9 100644 (file)
@@ -1,5 +1,5 @@
 /* A type-safe hash table template.
-   Copyright (C) 2012-2015 Free Software Foundation, Inc.
+   Copyright (C) 2012-2021 Free Software Foundation, Inc.
    Contributed by Lawrence Crowl <crowl@google.com>
 
 This file is part of GCC.
@@ -74,8 +74,11 @@ struct prime_ent const prime_tab[] = {
   { 0xfffffffb, 0x00000006, 0x00000008, 31 }
 };
 
+/* Limit number of comparisons when calling hash_table<>::verify.  */
+unsigned int hash_table_sanitize_eq_limit;
+
 /* The following function returns an index into the above table of the
-   nearest prime number which is greater than N, and near a power of two. */
+   nearest prime number which is at least N, and near a power of two. */
 
 unsigned int
 hash_table_higher_prime_index (unsigned long n)
@@ -98,15 +101,38 @@ hash_table_higher_prime_index (unsigned long n)
   return low;
 }
 
-mem_alloc_description<mem_usage> hash_table_usage;
+/* Return a reference to the lazily initialized hash-table usage description.
+   This needs to be a function rather than a simple global variable so that it
+   is reliably initialized before hash table variables in other files such as
+   sem_item::m_type_hash_cache.  */
+mem_alloc_description<mem_usage>&
+hash_table_usage ()
+{
+  static mem_alloc_description<mem_usage> usage;
+  return usage;
+}
 
 /* Support function for statistics.  */
 void dump_hash_table_loc_statistics (void)
 {
-  for (unsigned i = HASH_TABLE; i <= HASH_SET; i++)
+  if (!GATHER_STATISTICS)
+    return;
+
+  for (unsigned i = HASH_TABLE_ORIGIN; i <= HASH_SET_ORIGIN; i++)
     {
       mem_alloc_origin origin = (mem_alloc_origin) i;
-      hash_table_usage.dump (origin);
+      hash_table_usage ().dump (origin);
     }
 }
 
+/* Report a hash table checking error.  */
+
+ATTRIBUTE_NORETURN ATTRIBUTE_COLD
+void
+hashtab_chk_error ()
+{
+  fprintf (stderr, "hash table checking failed: "
+          "equal operator returns true for a pair "
+          "of values with a different hash value\n");
+  gcc_unreachable ();
+}