From 9b297949628f17f7620032e035154225b2d238aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Dumont?= Date: Fri, 21 Sep 2018 20:39:07 +0000 Subject: [PATCH] re PR libstdc++/87135 ([C++17] unordered containers violate iterator validity requirements) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 2018-09-21 François Dumont PR libstdc++/87135 * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt): Use __builtin_floor to compute _M_next_resize. * testsuite/23_containers/unordered_set/hash_policy/71181.cc: Adapt. * testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc: Adapt. From-SVN: r264494 --- libstdc++-v3/ChangeLog | 9 +++++++++ libstdc++-v3/src/c++11/hashtable_c++0x.cc | 4 ++-- .../23_containers/unordered_set/hash_policy/71181.cc | 2 +- .../unordered_set/hash_policy/prime_rehash.cc | 12 +++++++----- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 161ea11a617..e64f11c1b14 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2018-09-21 François Dumont + + PR libstdc++/87135 + * src/c++11/hashtable_c++0x.cc (_Prime_rehash_policy::_M_next_bkt): + Use __builtin_floor to compute _M_next_resize. + * testsuite/23_containers/unordered_set/hash_policy/71181.cc: Adapt. + * testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc: + Adapt. + 2018-09-21 Jonathan Wakely * testsuite/26_numerics/headers/cmath/hypot-long-double.cc: Remove. diff --git a/libstdc++-v3/src/c++11/hashtable_c++0x.cc b/libstdc++-v3/src/c++11/hashtable_c++0x.cc index 462767612f0..b9b11ff4385 100644 --- a/libstdc++-v3/src/c++11/hashtable_c++0x.cc +++ b/libstdc++-v3/src/c++11/hashtable_c++0x.cc @@ -52,7 +52,7 @@ namespace __detail if (__n < sizeof(__fast_bkt)) { _M_next_resize = - __builtin_ceil(__fast_bkt[__n] * (long double)_M_max_load_factor); + __builtin_floor(__fast_bkt[__n] * (long double)_M_max_load_factor); return __fast_bkt[__n]; } @@ -75,7 +75,7 @@ namespace __detail _M_next_resize = std::size_t(-1); else _M_next_resize = - __builtin_ceil(*__next_bkt * (long double)_M_max_load_factor); + __builtin_floor(*__next_bkt * (long double)_M_max_load_factor); return *__next_bkt; } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc index 0270ea52b9c..ba783d26847 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc @@ -30,7 +30,7 @@ template auto bkts = us.bucket_count(); for (int i = 0; i != threshold; ++i) { - if (i == nb_reserved) + if (i >= nb_reserved) { nb_reserved = bkts; us.reserve(nb_reserved); diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc index 7110a3afb39..916c5ad702c 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/prime_rehash.cc @@ -26,20 +26,22 @@ void test01() { std::__detail::_Prime_rehash_policy policy; - for (std::size_t i = 1;;) + // Starts at 4 because 2 & 3 are two consecutives primes that make this test + // fail. + for (std::size_t i = 4;;) { auto nxt = policy._M_next_bkt(i); - if (nxt == i) + if (nxt <= i) { - // Equals only when reaching max. - constexpr auto mx = std::numeric_limits::max() - 1; + // Lower or equals only when reaching max prime. + constexpr auto mx = std::numeric_limits::max(); VERIFY( nxt == policy._M_next_bkt(mx) ); break; } VERIFY( nxt > i ); - i = nxt; + i = nxt + 1; } } -- 2.30.2