[obj2yaml] - Stop triggering UB when dumping corrupted strings.
[llvm-complete.git] / unittests / ADT / DepthFirstIteratorTest.cpp
blob0e3e0e66d71e0083103e27ad4d0e71d9d2127227
1 //=== llvm/unittest/ADT/DepthFirstIteratorTest.cpp - DFS iterator tests ---===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/DepthFirstIterator.h"
10 #include "TestGraph.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
15 namespace llvm {
17 template <typename T> struct CountedSet {
18 typedef typename SmallPtrSet<T, 4>::iterator iterator;
20 SmallPtrSet<T, 4> S;
21 int InsertVisited = 0;
23 std::pair<iterator, bool> insert(const T &Item) {
24 InsertVisited++;
25 return S.insert(Item);
28 size_t count(const T &Item) const { return S.count(Item); }
30 void completed(T) { }
33 template <typename T> class df_iterator_storage<CountedSet<T>, true> {
34 public:
35 df_iterator_storage(CountedSet<T> &VSet) : Visited(VSet) {}
37 CountedSet<T> &Visited;
40 TEST(DepthFirstIteratorTest, ActuallyUpdateIterator) {
41 typedef CountedSet<Graph<3>::NodeType *> StorageT;
42 typedef df_iterator<Graph<3>, StorageT, true> DFIter;
44 Graph<3> G;
45 G.AddEdge(0, 1);
46 G.AddEdge(0, 2);
47 StorageT S;
48 for (auto N : make_range(DFIter::begin(G, S), DFIter::end(G, S)))
49 (void)N;
51 EXPECT_EQ(3, S.InsertVisited);