I think we have llvm::contains() which would allow you to make this slightly better. Other than that, good find!<br><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 3, 2018 at 5:49 PM Leonard Mosescu via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">lemo created this revision.<br>
lemo added reviewers: zturner, labath, teemperor.<br>
lemo added a project: LLDB.<br>
<br>
I noticed a suspicious failure:<br>
<br>
[ RUN ] VMRange.CollectionContains<br>
llvm/src/tools/lldb/unittests/Utility/VMRangeTest.cpp:146: Failure<br>
Value of: VMRange::ContainsRange(collection, VMRange(0x100, 0x104))<br>
<br>
Actual: false<br>
<br>
Expected: true<br>
<br>
Looking at the code, it is a very real bug:<br>
<br>
class RangeInRangeUnaryPredicate {<br>
public:<br>
RangeInRangeUnaryPredicate(VMRange range) : _range(range) {} // note that _range binds to a temporary!<br>
bool operator()(const VMRange &range) const {<br>
return range.Contains(_range);<br>
}<br>
const VMRange &_range;<br>
};<br>
<br>
This change fixes the bug.<br>
<br>
<br>
Repository:<br>
rLLDB LLDB<br>
<br>
<a href="https://reviews.llvm.org/D50290" rel="noreferrer" target="_blank">https://reviews.llvm.org/D50290</a><br>
<br>
Files:<br>
include/lldb/Utility/VMRange.h<br>
source/Utility/VMRange.cpp<br>
<br>
<br>
Index: source/Utility/VMRange.cpp<br>
===================================================================<br>
--- source/Utility/VMRange.cpp<br>
+++ source/Utility/VMRange.cpp<br>
@@ -24,14 +24,16 @@<br>
<br>
bool VMRange::ContainsValue(const VMRange::collection &coll,<br>
lldb::addr_t value) {<br>
- ValueInRangeUnaryPredicate in_range_predicate(value);<br>
- return llvm::find_if(coll, in_range_predicate) != coll.end();<br>
+ return llvm::find_if(coll, [&](const VMRange &r) {<br>
+ return r.Contains(value);<br>
+ }) != coll.end();<br>
}<br>
<br>
bool VMRange::ContainsRange(const VMRange::collection &coll,<br>
const VMRange &range) {<br>
- RangeInRangeUnaryPredicate in_range_predicate(range);<br>
- return llvm::find_if(coll, in_range_predicate) != coll.end();<br>
+ return llvm::find_if(coll, [&](const VMRange &r) {<br>
+ return r.Contains(range);<br>
+ }) != coll.end();<br>
}<br>
<br>
void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {<br>
Index: include/lldb/Utility/VMRange.h<br>
===================================================================<br>
--- include/lldb/Utility/VMRange.h<br>
+++ include/lldb/Utility/VMRange.h<br>
@@ -87,24 +87,6 @@<br>
void Dump(Stream *s, lldb::addr_t base_addr = 0,<br>
uint32_t addr_width = 8) const;<br>
<br>
- class ValueInRangeUnaryPredicate {<br>
- public:<br>
- ValueInRangeUnaryPredicate(lldb::addr_t value) : _value(value) {}<br>
- bool operator()(const VMRange &range) const {<br>
- return range.Contains(_value);<br>
- }<br>
- lldb::addr_t _value;<br>
- };<br>
-<br>
- class RangeInRangeUnaryPredicate {<br>
- public:<br>
- RangeInRangeUnaryPredicate(VMRange range) : _range(range) {}<br>
- bool operator()(const VMRange &range) const {<br>
- return range.Contains(_range);<br>
- }<br>
- const VMRange &_range;<br>
- };<br>
-<br>
static bool ContainsValue(const VMRange::collection &coll,<br>
lldb::addr_t value);<br>
<br>
<br>
<br>
</blockquote></div>