Skip to content

Commit 60aebd6

Browse files
committed
[ORC] Fix bug in WaitingOnGraph::Coalescer::remove.
This method takes a predicate, but was only deleting the first node for which the predicate returned true. This patch updates it to remove all nodes for which the predicate returns true. Bug found by inspection while investigating #169135. No testcase, since exercising this bug would involve finding sets with identical hashes.
1 parent 590bb3e commit 60aebd6

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

llvm/include/llvm/ExecutionEngine/Orc/WaitingOnGraph.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,20 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
155155
}
156156

157157
template <typename Pred> void remove(Pred &&Remove) {
158+
std::vector<hash_code> HashesToErase;
158159
for (auto &[Hash, SNs] : CanonicalSNs) {
159-
bool Found = false;
160-
for (size_t I = 0; I != SNs.size(); ++I) {
160+
for (size_t I = 0; I != SNs.size();) {
161161
if (Remove(SNs[I])) {
162162
std::swap(SNs[I], SNs.back());
163163
SNs.pop_back();
164-
Found = true;
165-
break;
166-
}
167-
}
168-
if (Found) {
169-
if (SNs.empty())
170-
CanonicalSNs.erase(Hash);
171-
break;
164+
} else
165+
++I;
172166
}
167+
if (SNs.empty())
168+
HashesToErase.push_back(Hash);
173169
}
170+
for (auto Hash : HashesToErase)
171+
CanonicalSNs.erase(Hash);
174172
}
175173

176174
private:
@@ -396,9 +394,14 @@ template <typename ContainerIdT, typename ElementIdT> class WaitingOnGraph {
396394
++I;
397395
}
398396

397+
CoalesceToPendingSNs.remove([&](SuperNode *SN) {
398+
for (auto &E : FailedSNs)
399+
if (E.get() == SN)
400+
return true;
401+
return false;
402+
});
403+
399404
for (auto &SN : FailedSNs) {
400-
CoalesceToPendingSNs.remove(
401-
[&](SuperNode *SNC) { return SNC == SN.get(); });
402405
for (auto &[Container, Elems] : SN->Defs) {
403406
assert(ElemToPendingSN.count(Container));
404407
auto &CElems = ElemToPendingSN[Container];

0 commit comments

Comments
 (0)