[llvm] r218040 - Fix DWARFUnitSection::getUnitForOffset().
Frederic Riss
friss at apple.com
Thu Sep 18 02:38:16 PDT 2014
Author: friss
Date: Thu Sep 18 04:38:15 2014
New Revision: 218040
URL: http://llvm.org/viewvc/llvm-project?rev=218040&view=rev
Log:
Fix DWARFUnitSection::getUnitForOffset().
The current code is only able to return the right unit if the passed offset
is the exact offset of a section. Generalize the search function by comparing
againt the offset of the next unit instead and by switching the search
algorithm to upper_bound.
This way, the unit returned is the first unit with a getNextUnitOffset()
strictly greater than the searched offset, which is exactly what we want.
Note that there is no need for testing the range of the resulting unit as
the offsets of a DWARFUnitSection are in a single contiguous range from
0 inclusive to lastUnit->getNextUnitOffset() exclusive.
Reviewers: dblaikie samsonov
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D5262
Modified:
llvm/trunk/lib/DebugInfo/DWARFUnit.h
Modified: llvm/trunk/lib/DebugInfo/DWARFUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFUnit.h?rev=218040&r1=218039&r2=218040&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFUnit.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFUnit.h Thu Sep 18 04:38:15 2014
@@ -46,17 +46,9 @@ class DWARFUnitSection final : public Sm
public DWARFUnitSectionBase {
struct UnitOffsetComparator {
- bool operator()(const std::unique_ptr<UnitType> &LHS,
- const std::unique_ptr<UnitType> &RHS) const {
- return LHS->getOffset() < RHS->getOffset();
- }
- bool operator()(const std::unique_ptr<UnitType> &LHS,
- uint32_t RHS) const {
- return LHS->getOffset() < RHS;
- }
bool operator()(uint32_t LHS,
const std::unique_ptr<UnitType> &RHS) const {
- return LHS < RHS->getOffset();
+ return LHS < RHS->getNextUnitOffset();
}
};
@@ -66,7 +58,7 @@ public:
typedef llvm::iterator_range<typename UnitVector::iterator> iterator_range;
UnitType *getUnitForOffset(uint32_t Offset) const {
- auto *CU = std::lower_bound(this->begin(), this->end(), Offset,
+ auto *CU = std::upper_bound(this->begin(), this->end(), Offset,
UnitOffsetComparator());
if (CU != this->end())
return CU->get();
More information about the llvm-commits
mailing list