[llvm] [ADT][NFCI]: Fix iterator category for graph iterators with external … (PR #116403)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 22:26:27 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Mészáros Gergely (Maetveis)
<details>
<summary>Changes</summary>
…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
---
Full diff: https://github.com/llvm/llvm-project/pull/116403.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/DepthFirstIterator.h (+5-1)
- (modified) llvm/include/llvm/ADT/PostOrderIterator.h (+5-1)
``````````diff
diff --git a/llvm/include/llvm/ADT/DepthFirstIterator.h b/llvm/include/llvm/ADT/DepthFirstIterator.h
index 71053c2d0d8a8e..4ced758343806e 100644
--- a/llvm/include/llvm/ADT/DepthFirstIterator.h
+++ b/llvm/include/llvm/ADT/DepthFirstIterator.h
@@ -39,6 +39,7 @@
#include "llvm/ADT/iterator_range.h"
#include <iterator>
#include <optional>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -84,7 +85,10 @@ template <class GraphT,
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
class df_iterator : public df_iterator_storage<SetType, ExtStorage> {
public:
- using iterator_category = std::forward_iterator_tag;
+ // When External storage is used we are not multi-pass safe.
+ using iterator_category =
+ std::conditional_t<ExtStorage, std::input_iterator_tag,
+ std::forward_iterator_tag>;
using value_type = typename GT::NodeRef;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
diff --git a/llvm/include/llvm/ADT/PostOrderIterator.h b/llvm/include/llvm/ADT/PostOrderIterator.h
index edf0401a751708..1cbd3c170052c7 100644
--- a/llvm/include/llvm/ADT/PostOrderIterator.h
+++ b/llvm/include/llvm/ADT/PostOrderIterator.h
@@ -23,6 +23,7 @@
#include <iterator>
#include <optional>
#include <set>
+#include <type_traits>
#include <utility>
namespace llvm {
@@ -95,7 +96,10 @@ template <class GraphT,
bool ExtStorage = false, class GT = GraphTraits<GraphT>>
class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
public:
- using iterator_category = std::forward_iterator_tag;
+ // When External storage is used we are not multi-pass safe.
+ using iterator_category =
+ std::conditional_t<ExtStorage, std::input_iterator_tag,
+ std::forward_iterator_tag>;
using value_type = typename GT::NodeRef;
using difference_type = std::ptrdiff_t;
using pointer = value_type *;
``````````
</details>
https://github.com/llvm/llvm-project/pull/116403
More information about the llvm-commits
mailing list