| 283 | /** Given a dependency graph, and a todo set, read a topological subset of todo from reader. */ |
| 284 | template<typename SetType> |
| 285 | SetType ReadTopologicalSet(const DepGraph<SetType>& depgraph, const SetType& todo, SpanReader& reader, bool non_empty) |
| 286 | { |
| 287 | // Read a bitmask from the fuzzing input. Add 1 if non_empty, so the mask is definitely not |
| 288 | // zero in that case. |
| 289 | uint64_t mask{0}; |
| 290 | try { |
| 291 | reader >> VARINT(mask); |
| 292 | } catch(const std::ios_base::failure&) {} |
| 293 | if (mask != uint64_t(-1)) mask += non_empty; |
| 294 | |
| 295 | SetType ret; |
| 296 | for (auto i : todo) { |
| 297 | if (!ret[i]) { |
| 298 | if (mask & 1) ret |= depgraph.Ancestors(i); |
| 299 | mask >>= 1; |
| 300 | } |
| 301 | } |
| 302 | ret &= todo; |
| 303 | |
| 304 | // While mask starts off non-zero if non_empty is true, it is still possible that all its low |
| 305 | // bits are 0, and ret ends up being empty. As a last resort, use the in-todo ancestry of the |
| 306 | // first todo position. |
| 307 | if (non_empty && ret.None()) { |
| 308 | Assume(todo.Any()); |
| 309 | ret = depgraph.Ancestors(todo.First()) & todo; |
| 310 | Assume(ret.Any()); |
| 311 | } |
| 312 | return ret; |
| 313 | } |
| 314 | |
| 315 | /** Given a dependency graph, construct any valid linearization for it, reading from a SpanReader. */ |
| 316 | template<typename BS> |
no test coverage detected