[PATCH] D26064: [ADT] IntervalMap: fix setStart and setStop
Michael LeMay via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 27 21:30:32 PDT 2016
mlemay-intel created this revision.
mlemay-intel added reviewers: stoklund, chandlerc.
mlemay-intel added a subscriber: llvm-commits.
These functions currently require that the new closed interval has a length of
at least 2. They also currently permit empty half-open intervals. This patch
defines nonEmpty in each traits structure and uses it to correct the
implementations of setStart and setStop.
https://reviews.llvm.org/D26064
Files:
include/llvm/ADT/IntervalMap.h
Index: include/llvm/ADT/IntervalMap.h
===================================================================
--- include/llvm/ADT/IntervalMap.h
+++ include/llvm/ADT/IntervalMap.h
@@ -150,6 +150,12 @@
return a+1 == b;
}
+ /// nonEmpty - Return true if [a;b] is non-empty.
+ /// This is a <= b for a closed interval, a < b for [a;b) half-open intervals.
+ static inline bool nonEmpty(const T &a, const T &b) {
+ return a <= b;
+ }
+
};
template <typename T>
@@ -170,6 +176,11 @@
return a == b;
}
+ /// nonEmpty - Return true if [a;b) is non-empty.
+ static inline bool nonEmpty(const T &a, const T &b) {
+ return a < b;
+ }
+
};
/// IntervalMapImpl - Namespace used for IntervalMap implementation details.
@@ -1669,7 +1680,7 @@
template <typename KeyT, typename ValT, unsigned N, typename Traits>
void IntervalMap<KeyT, ValT, N, Traits>::
iterator::setStart(KeyT a) {
- assert(Traits::stopLess(a, this->stop()) && "Cannot move start beyond stop");
+ assert(Traits::nonEmpty(a, this->stop()) && "Cannot move start beyond stop");
KeyT &CurStart = this->unsafeStart();
if (!Traits::startLess(a, CurStart) || !canCoalesceLeft(a, this->value())) {
CurStart = a;
@@ -1685,7 +1696,7 @@
template <typename KeyT, typename ValT, unsigned N, typename Traits>
void IntervalMap<KeyT, ValT, N, Traits>::
iterator::setStop(KeyT b) {
- assert(Traits::stopLess(this->start(), b) && "Cannot move stop beyond start");
+ assert(Traits::nonEmpty(this->start(), b) && "Cannot move stop beyond start");
if (Traits::startLess(b, this->stop()) ||
!canCoalesceRight(b, this->value())) {
setStopUnchecked(b);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26064.76165.patch
Type: text/x-patch
Size: 1654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161028/8424791f/attachment.bin>
More information about the llvm-commits
mailing list