[llvm-branch-commits] [lldb] r339107 - Merging r338949:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 7 00:43:13 PDT 2018


Author: hans
Date: Tue Aug  7 00:43:13 2018
New Revision: 339107

URL: http://llvm.org/viewvc/llvm-project?rev=339107&view=rev
Log:
Merging r338949:
------------------------------------------------------------------------
r338949 | lemo | 2018-08-04 04:15:26 +0200 (Sat, 04 Aug 2018) | 27 lines

Fix a bug in VMRange

I noticed a suspicious failure:

[ RUN ] VMRange.CollectionContains
llvm/src/tools/lldb/unittests/Utility/VMRangeTest.cpp:146: Failure
Value of: VMRange::ContainsRange(collection, VMRange(0x100, 0x104))

Actual: false
Expected: true

Looking at the code, it is a very real bug:

class RangeInRangeUnaryPredicate {
public:
  RangeInRangeUnaryPredicate(VMRange range) : _range(range) {} // note that _range binds to a temporary!
  bool operator()(const VMRange &range) const {
    return range.Contains(_range);
  }
  const VMRange &_range;
};

This change fixes the bug.

Differential Revision: https://reviews.llvm.org/D50290


------------------------------------------------------------------------

Modified:
    lldb/branches/release_70/   (props changed)
    lldb/branches/release_70/include/lldb/Utility/VMRange.h
    lldb/branches/release_70/source/Utility/VMRange.cpp

Propchange: lldb/branches/release_70/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  7 00:43:13 2018
@@ -1,2 +1,3 @@
 /lldb/branches/apple/python-GIL:156467-162159
 /lldb/branches/iohandler:198360-200250
+/lldb/trunk:338949

Modified: lldb/branches/release_70/include/lldb/Utility/VMRange.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_70/include/lldb/Utility/VMRange.h?rev=339107&r1=339106&r2=339107&view=diff
==============================================================================
--- lldb/branches/release_70/include/lldb/Utility/VMRange.h (original)
+++ lldb/branches/release_70/include/lldb/Utility/VMRange.h Tue Aug  7 00:43:13 2018
@@ -87,24 +87,6 @@ public:
   void Dump(Stream *s, lldb::addr_t base_addr = 0,
             uint32_t addr_width = 8) const;
 
-  class ValueInRangeUnaryPredicate {
-  public:
-    ValueInRangeUnaryPredicate(lldb::addr_t value) : _value(value) {}
-    bool operator()(const VMRange &range) const {
-      return range.Contains(_value);
-    }
-    lldb::addr_t _value;
-  };
-
-  class RangeInRangeUnaryPredicate {
-  public:
-    RangeInRangeUnaryPredicate(VMRange range) : _range(range) {}
-    bool operator()(const VMRange &range) const {
-      return range.Contains(_range);
-    }
-    const VMRange &_range;
-  };
-
   static bool ContainsValue(const VMRange::collection &coll,
                             lldb::addr_t value);
 

Modified: lldb/branches/release_70/source/Utility/VMRange.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/release_70/source/Utility/VMRange.cpp?rev=339107&r1=339106&r2=339107&view=diff
==============================================================================
--- lldb/branches/release_70/source/Utility/VMRange.cpp (original)
+++ lldb/branches/release_70/source/Utility/VMRange.cpp Tue Aug  7 00:43:13 2018
@@ -24,14 +24,16 @@ using namespace lldb_private;
 
 bool VMRange::ContainsValue(const VMRange::collection &coll,
                             lldb::addr_t value) {
-  ValueInRangeUnaryPredicate in_range_predicate(value);
-  return llvm::find_if(coll, in_range_predicate) != coll.end();
+  return llvm::find_if(coll, [&](const VMRange &r) {
+           return r.Contains(value);
+         }) != coll.end();
 }
 
 bool VMRange::ContainsRange(const VMRange::collection &coll,
                             const VMRange &range) {
-  RangeInRangeUnaryPredicate in_range_predicate(range);
-  return llvm::find_if(coll, in_range_predicate) != coll.end();
+  return llvm::find_if(coll, [&](const VMRange &r) {
+           return r.Contains(range);
+         }) != coll.end();
 }
 
 void VMRange::Dump(Stream *s, lldb::addr_t offset, uint32_t addr_width) const {




More information about the llvm-branch-commits mailing list