Skip to content

Commit d1fe30a

Browse files
committed
[Wasm] Fix OpenAddressingHashTables.
The `find()` method incorrectly returned true if the slot at the end of the bucket list is occupied. This commit fixes the issue and additionally adds insists that all slots in a bucket list are occupied in both `find()` and `for_each_in_equal_range`.
1 parent 118184c commit d1fe30a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/backend/WasmAlgo.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,16 +1788,17 @@ std::pair<HashTable::entry_t, Boolx1> OpenAddressingHashTable<IsGlobal, ValueInP
17881788
/*----- Probe slots, abort if end of bucket is reached or key already exists. -----*/
17891789
Var<Ptr<void>> slot(bucket);
17901790
Var<PrimitiveExpr<ref_t>> steps(0);
1791-
WHILE (steps != refs and reference_count(slot) != ref_t(0)) {
1791+
WHILE (steps != refs) {
1792+
Wasm_insist(reference_count(slot) != ref_t(0), "slot in bucket list must be occupied");
17921793
BREAK(equal_key(slot, std::move(key))); // move key at last use
17931794
steps += ref_t(1);
17941795
Wasm_insist(steps <= *num_entries_, "probing strategy has to find unoccupied slot if there is one");
17951796
slot = probing_strategy().advance_to_next_slot(slot, steps);
17961797
Wasm_insist(begin() <= slot and slot < end(), "slot out-of-bounds");
17971798
}
17981799

1799-
/*----- Key is found iff current slot is occupied. -----*/
1800-
const Var<Boolx1> key_found(reference_count(slot) != ref_t(0)); // create constant variable since `slot` may change
1800+
/*----- Key is found iff end of bucket is reached. -----*/
1801+
Boolx1 key_found = steps != refs;
18011802

18021803
if constexpr (not ValueInPlace) {
18031804
/*----- Set slot pointer to out-of-place values. -----*/
@@ -1839,7 +1840,8 @@ void OpenAddressingHashTable<IsGlobal, ValueInPlace>::for_each_in_equal_range(st
18391840
/*----- Iterate over slots and call pipeline (with entry handle argument) on matches with the given key. -----*/
18401841
Var<Ptr<void>> slot(bucket);
18411842
Var<PrimitiveExpr<ref_t>> steps(0);
1842-
WHILE (steps != refs and reference_count(slot) != ref_t(0)) { // end of bucket not reached and slot occupied
1843+
WHILE (steps != refs) { // end of bucket not reached
1844+
Wasm_insist(reference_count(slot) != ref_t(0), "slot in bucket list must be occupied");
18431845
if (predicated) {
18441846
CodeGenContext::Get().env().add_predicate(equal_key(slot, std::move(key)));
18451847
Pipeline(entry(slot));

0 commit comments

Comments
 (0)