From 62de703f1990d2c4dd7ee0c41bfa886b5c589793 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 14 Mar 2019 18:47:01 -0400 Subject: [PATCH] hash-table.h (remove_elt_with_hash): Return if slot is NULL rather than if is_empty (*slot). * 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. Co-Authored-By: Jakub Jelinek From-SVN: r269695 --- gcc/ChangeLog | 10 ++++++++++ gcc/hash-map-tests.c | 4 ++++ gcc/hash-set-tests.c | 15 +++++++++++++++ gcc/hash-table.h | 2 +- libiberty/ChangeLog | 6 ++++++ libiberty/hashtab.c | 2 +- 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4890c75c94b6..394271f8bc26 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2019-03-14 Jason Merrill + Jakub Jelinek + + * 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. + 2019-03-15 H.J. Lu PR target/89650 diff --git a/gcc/hash-map-tests.c b/gcc/hash-map-tests.c index 2137464e6937..acbfdb9e9ab2 100644 --- a/gcc/hash-map-tests.c +++ b/gcc/hash-map-tests.c @@ -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 (xcalloc (4, 1)); diff --git a/gcc/hash-set-tests.c b/gcc/hash-set-tests.c index 5ca1e4eea8c6..f75d41aed39d 100644 --- a/gcc/hash-set-tests.c +++ b/gcc/hash-set-tests.c @@ -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. */ diff --git a/gcc/hash-table.h b/gcc/hash-table.h index 1fd36946a535..9e09fa487f8f 100644 --- a/gcc/hash-table.h +++ b/gcc/hash-table.h @@ -940,7 +940,7 @@ hash_table ::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); diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index f63255899277..cc44e4213d13 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,3 +1,9 @@ +2019-03-14 Jason Merrill + Jakub Jelinek + + * hashtab.c (htab_remove_elt_with_hash): Return if slot is NULL rather + than if *slot is HTAB_EMPTY_ENTRY. + 2019-02-11 Philippe Waroquiers * splay-tree.c (splay_tree_insert): Also release old KEY in case diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c index 880c87877165..9f917c3571d9 100644 --- a/libiberty/hashtab.c +++ b/libiberty/hashtab.c @@ -725,7 +725,7 @@ htab_remove_elt_with_hash (htab_t htab, PTR element, hashval_t hash) 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) -- 2.39.2