[llvm] [ADT][NFCI]: Fix iterator category for graph iterators with external … (PR #116403)
Mészáros Gergely via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 15 07:59:14 PST 2024
https://github.com/Maetveis created https://github.com/llvm/llvm-project/pull/116403
…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
>From 468b66a56a948e1427c99d0c8e699fff89f1b1fd Mon Sep 17 00:00:00 2001
From: Gergely Meszaros <gergely.meszaros at intel.com>
Date: Fri, 15 Nov 2024 07:45:23 -0800
Subject: [PATCH] [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
---
llvm/include/llvm/ADT/DepthFirstIterator.h | 6 +++++-
llvm/include/llvm/ADT/PostOrderIterator.h | 6 +++++-
2 files changed, 10 insertions(+), 2 deletions(-)
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 *;
More information about the llvm-commits
mailing list