[Lldb-commits] [PATCH] D77568: Return correct entry in RangeDataVector::FindEntryThatContains
Shivam Mittal via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Mon Apr 6 10:18:47 PDT 2020
shivammittal99 created this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
The FindEntryThatContains function does not return the correct entry in
the case when two non-consecutive entries contain the range.
Eg. Vector = [(0, 40, 0), (10, 10, 1)] and query = (25, 1). The function
currently returns nullptr, but it should return entry 0.
Signed-off-by: Shivam Mittal <shivammittal99 at gmail.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77568
Files:
lldb/include/lldb/Utility/RangeMap.h
lldb/unittests/Utility/RangeMapTest.cpp
Index: lldb/unittests/Utility/RangeMapTest.cpp
===================================================================
--- lldb/unittests/Utility/RangeMapTest.cpp
+++ lldb/unittests/Utility/RangeMapTest.cpp
@@ -53,10 +53,7 @@
// With overlapping intervals, the intention seems to be to return the first
// interval which contains the address.
EXPECT_THAT(Map.FindEntryThatContains(25), EntryIs(0));
-
- // However, this does not always succeed.
- // TODO: This should probably return the range (0, 40) as well.
- EXPECT_THAT(Map.FindEntryThatContains(35), nullptr);
+ EXPECT_THAT(Map.FindEntryThatContains(35), EntryIs(0));
}
TEST(RangeDataVector, CustomSort) {
Index: lldb/include/lldb/Utility/RangeMap.h
===================================================================
--- lldb/include/lldb/Utility/RangeMap.h
+++ lldb/include/lldb/Utility/RangeMap.h
@@ -540,14 +540,13 @@
if (!m_entries.empty()) {
typename Collection::const_iterator begin = m_entries.begin();
typename Collection::const_iterator end = m_entries.end();
- typename Collection::const_iterator pos =
- std::lower_bound(begin, end, range, BaseLessThan);
-
- while (pos != begin && pos[-1].Contains(range))
- --pos;
+ typename Collection::const_iterator limit =
+ std::upper_bound(begin, end, range, BaseLessThan);
- if (pos != end && pos->Contains(range))
- return &(*pos);
+ for (auto pos = begin; pos < limit; ++pos) {
+ if (pos->Contains(range))
+ return &(*pos);
+ }
}
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77568.255389.patch
Type: text/x-patch
Size: 1585 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200406/0b336c75/attachment.bin>
More information about the lldb-commits
mailing list