Skip to content

Commit 026bd5b

Browse files
Apply workaround to iterator comparison bug
This is a workaround to a bug that gets triggered in dependence_graph.cpp - in the function dep_graph_domaint::control_dependencies, find is called on cfg_dominators_templatet::target_sett, with an iterator parameter called "from". It is not ensured that this iterator is from the same list as the iterators within the dominators set, this is a problem according to C++ Draft Standard N3960: 24.2.1 An iterator j is called reachable from an iterator i if and only if there is a finite sequence of applications of the expression ++i that makes i == j. If j is reachable from i, they refer to elements of the same sequence. 24.2.5 The domain of == for forward iterators is that of iterators over the same underlying sequence.
1 parent c844f8d commit 026bd5b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/analyses/cfg_dominators.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,19 @@ class dominatorst
183183

184184
const_iterator find(const T &node) const
185185
{
186-
return std::find(begin(), end(), node);
186+
std::less<T> less;
187+
// FIXME This works around a bug in other parts of the code
188+
// in particular, dependence_graph.cpp,
189+
// where iterators to different lists than those that are
190+
// stored in this set are passed to find.
191+
// The Debug libstdc++ will (correctly!) run into an assertion failure
192+
// using std::find. std::less for some reason doesn't trigger this assertion
193+
// failure, so we use this as an ugly workaround until that code is fixed.
194+
195+
// NOLINTNEXTLINE
196+
return std::find_if(cbegin(), cend(), [&](const T &other_node) {
197+
return !less(node, other_node) && !less(other_node, node);
198+
});
187199
}
188200

189201
/// The size of the set; Linear time on the first call,

0 commit comments

Comments
 (0)