public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-3001] Make 'gcc/hash-map-tests.c:test_map_of_type_with_ctor_and_dtor_expand' work on 32-bit architectures
Date: Wed, 18 Aug 2021 16:34:54 +0000 (GMT)	[thread overview]
Message-ID: <20210818163454.165D8388CC18@sourceware.org> (raw)

https://gcc.gnu.org/g:bb04a03c6f9bacc890118b9e12b657503093c2f8

commit r12-3001-gbb04a03c6f9bacc890118b9e12b657503093c2f8
Author: Thomas Schwinge <thomas@codesourcery.com>
Date:   Wed Aug 18 17:20:40 2021 +0200

    Make 'gcc/hash-map-tests.c:test_map_of_type_with_ctor_and_dtor_expand' work on 32-bit architectures [PR101959]
    
    Bug fix for recent commit e4f16e9f357a38ec702fb69a0ffab9d292a6af9b
    "Add more self-tests for 'hash_map' with Value type with non-trivial
    constructor/destructor".
    
            gcc/
            PR bootstrap/101959
            * hash-map-tests.c (test_map_of_type_with_ctor_and_dtor_expand):
            Use an 'int_hash'.

Diff:
---
 gcc/hash-map-tests.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c
index 257f2be0c26..6acc0d4337e 100644
--- a/gcc/hash-map-tests.c
+++ b/gcc/hash-map-tests.c
@@ -328,11 +328,22 @@ test_map_of_type_with_ctor_and_dtor_expand (bool remove_some_inline)
   size_t expand_c_expected = 4;
   size_t expand_c = 0;
 
-  void *a[N_elem];
+  /* For stability of this testing, we need all Key values 'k' to produce
+     unique hash values 'Traits::hash (k)', as otherwise the dynamic
+     insert/remove behavior may diverge across different architectures.  This
+     is, for example, a problem when using the standard 'pointer_hash::hash',
+     which is simply doing a 'k >> 3' operation, which is fine on 64-bit
+     architectures, but on 32-bit architectures produces the same hash value
+     for subsequent 'a[i] = &a[i]' array elements.  Therefore, use an
+     'int_hash'.  */
+
+  int a[N_elem];
   for (size_t i = 0; i < N_elem; ++i)
-    a[i] = &a[i];
+    a[i] = i;
 
-  typedef hash_map <void *, val_t> Map;
+  const int EMPTY = -1;
+  const int DELETED = -2;
+  typedef hash_map<int_hash<int, EMPTY, DELETED>, val_t> Map;
 
   /* Note that we are starting with a fresh 'Map'.  Even if an existing one has
      been cleared out completely, there remain 'deleted' elements, and these


                 reply	other threads:[~2021-08-18 16:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210818163454.165D8388CC18@sourceware.org \
    --to=tschwinge@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).