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 e4f16e9f35
"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'.
This commit is contained in:
Thomas Schwinge 2021-08-18 17:20:40 +02:00
parent 640df4ef81
commit bb04a03c6f

View File

@ -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_expected = 4;
size_t expand_c = 0; size_t expand_c = 0;
void *a[N_elem]; /* For stability of this testing, we need all Key values 'k' to produce
for (size_t i = 0; i < N_elem; ++i) unique hash values 'Traits::hash (k)', as otherwise the dynamic
a[i] = &a[i]; 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'. */
typedef hash_map <void *, val_t> Map; int a[N_elem];
for (size_t i = 0; i < N_elem; ++i)
a[i] = i;
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 /* 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 been cleared out completely, there remain 'deleted' elements, and these