On Tuesday, 7 December 2021 08:43:56 CET Richard Biener wrote: > On Mon, Dec 6, 2021 at 11:47 AM Matthias Kretz <m.kr...@gsi.de> wrote: > > While reading the hash_map code I noticed this inconsistency. Bootstrapped > > and regtested on x86_64. OK for trunk? > > I've inspected two users of said overload and they return true. Did you > look at the rest? I assume that bootstrapping and testing with asserting > that the callback never returns false in that overload should succeed? > That said, the inconsistency is bad - but how can we be sure we're not > relying on that? I mean more than just bootstrapping and regtesting ;)
I've checked all users now; and added more documentation. OK for trunk now? ---- 8< ---- The hash_map::traverse overload taking a non-const Value pointer breaks if the callback returns false. The other overload should behave the same. Signed-off-by: Matthias Kretz <m.kr...@gsi.de> gcc/ChangeLog: * hash-map.h (hash_map::traverse): Let both overloads behave the same. * predict.c (assert_is_empty): Return true, thus not changing behavior. --- gcc/hash-map.h | 6 ++++-- gcc/predict.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) -- ────────────────────────────────────────────────────────────────────────── Dr. Matthias Kretz https://mattkretz.github.io GSI Helmholtz Centre for Heavy Ion Research https://gsi.de stdₓ::simd ──────────────────────────────────────────────────────────────────────────
diff --git a/gcc/hash-map.h b/gcc/hash-map.h index dd039f10343..c4fe26cf5d1 100644 --- a/gcc/hash-map.h +++ b/gcc/hash-map.h @@ -217,7 +217,8 @@ public: } /* Call the call back on each pair of key and value with the passed in - arg. */ + arg until either the call back returns false or all pairs have been seen. + The traversal is unordered. */ template<typename Arg, bool (*f)(const typename Traits::key_type &, const Value &, Arg)> @@ -225,7 +226,8 @@ public: { for (typename hash_table<hash_entry>::iterator iter = m_table.begin (); iter != m_table.end (); ++iter) - f ((*iter).m_key, (*iter).m_value, a); + if (!f ((*iter).m_key, (*iter).m_value, a)) + break; } template<typename Arg, bool (*f)(const typename Traits::key_type &, diff --git a/gcc/predict.c b/gcc/predict.c index 3cb4e3c0eb5..1a1da7e8360 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -3044,7 +3044,7 @@ assert_is_empty (const_basic_block const &, edge_prediction *const &value, void *) { gcc_assert (!value); - return false; + return true; } /* Predict branch probabilities and estimate profile for basic block BB.