On Thu, 14 Mar 2019 10:19:17 +0100 Jakub Jelinek <ja...@redhat.com> wrote:
> On Thu, Mar 14, 2019 at 09:57:27AM +0100, Richard Biener wrote: > > I'd say make it work, thus your patch below is OK. > > Ok, here is an updated patch with some self-tests coverage as well that I'll > bootstrap/regtest. I had the simple slot == NULL || is_empty (*slot) hack in remove_elt_with_hash in my aldot/fortran-fe-stringpool stash since a long time now and hence support this change, fwiw. Many thanks! > > 2019-03-14 Jason Merrill <ja...@redhat.com> > Jakub Jelinek <ja...@redhat.com> > > * hash-table.h (remove_elt_with_hash): Return if slot is NULL rather > than if is_empty (*slot). > * hash-set-tests.c (test_set_of_strings): Add tests for addition of > existing elt and for elt removal. > * hash-map-tests.c (test_map_of_strings_to_int): Add test for removal > of already removed elt. > > * hashtab.c (htab_remove_elt_with_hash): Return if slot is NULL rather > than if *slot is HTAB_EMPTY_ENTRY. > > --- gcc/hash-table.h.jj 2019-01-01 12:37:17.446970209 +0100 > +++ gcc/hash-table.h 2019-03-14 08:48:18.861131498 +0100 > @@ -940,7 +940,7 @@ hash_table<Descriptor, Allocator> > ::remove_elt_with_hash (const compare_type &comparable, hashval_t hash) > { > value_type *slot = find_slot_with_hash (comparable, hash, NO_INSERT); > - if (is_empty (*slot)) > + if (slot == NULL) > return; > > Descriptor::remove (*slot); > --- gcc/hash-set-tests.c.jj 2019-01-01 12:37:21.648901265 +0100 > +++ gcc/hash-set-tests.c 2019-03-14 10:06:04.688950764 +0100 > @@ -48,11 +48,26 @@ test_set_of_strings () > ASSERT_EQ (false, s.add (red)); > ASSERT_EQ (false, s.add (green)); > ASSERT_EQ (false, s.add (blue)); > + ASSERT_EQ (true, s.add (green)); > > /* Verify that the values are now within the set. */ > ASSERT_EQ (true, s.contains (red)); > ASSERT_EQ (true, s.contains (green)); > ASSERT_EQ (true, s.contains (blue)); > + ASSERT_EQ (3, s.elements ()); > + > + /* Test removal. */ > + s.remove (red); > + ASSERT_EQ (false, s.contains (red)); > + ASSERT_EQ (true, s.contains (green)); > + ASSERT_EQ (true, s.contains (blue)); > + ASSERT_EQ (2, s.elements ()); > + > + s.remove (red); > + ASSERT_EQ (false, s.contains (red)); > + ASSERT_EQ (true, s.contains (green)); > + ASSERT_EQ (true, s.contains (blue)); > + ASSERT_EQ (2, s.elements ()); > } > > /* Run all of the selftests within this file. */ > --- gcc/hash-map-tests.c.jj 2019-01-21 20:46:21.963092085 +0100 > +++ gcc/hash-map-tests.c 2019-03-14 10:06:56.994105872 +0100 > @@ -78,6 +78,10 @@ test_map_of_strings_to_int () > ASSERT_EQ (5, m.elements ()); > ASSERT_EQ (NULL, m.get (eric)); > > + m.remove (eric); > + ASSERT_EQ (5, m.elements ()); > + ASSERT_EQ (NULL, m.get (eric)); > + > /* A plain char * key is hashed based on its value (address), rather > than the string it points to. */ > char *another_ant = static_cast <char *> (xcalloc (4, 1)); > --- libiberty/hashtab.c.jj 2019-01-01 12:38:46.868503025 +0100 > +++ libiberty/hashtab.c 2019-03-14 08:47:49.172612001 +0100 > @@ -725,7 +725,7 @@ htab_remove_elt_with_hash (htab_t htab, > PTR *slot; > > slot = htab_find_slot_with_hash (htab, element, hash, NO_INSERT); > - if (*slot == HTAB_EMPTY_ENTRY) > + if (slot == NULL) > return; > > if (htab->del_f) > > > Jakub