Skip to content

Commit 468b66a

Browse files
committed
[ADT][NFCI]: Fix iterator category for graph iterators with external storage
Set the iterator category for graph iterators to input_iterator_tag when the visited set is stored externally. In that case we can't provide multi-pass guarantee, so we should not claim to be a forward iterator. Fixes: #116400
1 parent af3295b commit 468b66a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

llvm/include/llvm/ADT/DepthFirstIterator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/ADT/iterator_range.h"
4040
#include <iterator>
4141
#include <optional>
42+
#include <type_traits>
4243
#include <utility>
4344
#include <vector>
4445

@@ -84,7 +85,10 @@ template <class GraphT,
8485
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
8586
class df_iterator : public df_iterator_storage<SetType, ExtStorage> {
8687
public:
87-
using iterator_category = std::forward_iterator_tag;
88+
// When External storage is used we are not multi-pass safe.
89+
using iterator_category =
90+
std::conditional_t<ExtStorage, std::input_iterator_tag,
91+
std::forward_iterator_tag>;
8892
using value_type = typename GT::NodeRef;
8993
using difference_type = std::ptrdiff_t;
9094
using pointer = value_type *;

llvm/include/llvm/ADT/PostOrderIterator.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <iterator>
2424
#include <optional>
2525
#include <set>
26+
#include <type_traits>
2627
#include <utility>
2728

2829
namespace llvm {
@@ -95,7 +96,10 @@ template <class GraphT,
9596
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
9697
class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
9798
public:
98-
using iterator_category = std::forward_iterator_tag;
99+
// When External storage is used we are not multi-pass safe.
100+
using iterator_category =
101+
std::conditional_t<ExtStorage, std::input_iterator_tag,
102+
std::forward_iterator_tag>;
99103
using value_type = typename GT::NodeRef;
100104
using difference_type = std::ptrdiff_t;
101105
using pointer = value_type *;

0 commit comments

Comments
 (0)