[llvm] r185676 - Remove use of asymmetric std::lower_bound comparator.
Ahmed Bougacha
ahmed.bougacha at gmail.com
Thu Jul 4 16:20:12 PDT 2013
Author: ab
Date: Thu Jul 4 18:20:12 2013
New Revision: 185676
URL: http://llvm.org/viewvc/llvm-project?rev=185676&view=rev
Log:
Remove use of asymmetric std::lower_bound comparator.
VS 2008 doesn't like it when in debug mode.
Modified:
llvm/trunk/include/llvm/MC/MCModule.h
llvm/trunk/lib/MC/MCModule.cpp
Modified: llvm/trunk/include/llvm/MC/MCModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCModule.h?rev=185676&r1=185675&r2=185676&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCModule.h (original)
+++ llvm/trunk/include/llvm/MC/MCModule.h Thu Jul 4 18:20:12 2013
@@ -51,6 +51,11 @@ class MCModule {
/// \brief Insert an atom in the module, using its Begin and End addresses.
void map(MCAtom *NewAtom);
+
+ /// \brief Return an iterator to the first atom that is completely or in part
+ /// located after \p Addr, i.e., that \p Addr is bigger than its end address.
+ AtomListTy::const_iterator atom_lower_bound(uint64_t Addr) const;
+ AtomListTy:: iterator atom_lower_bound(uint64_t Addr);
/// @}
/// \name Function tracking
Modified: llvm/trunk/lib/MC/MCModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCModule.cpp?rev=185676&r1=185675&r2=185676&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCModule.cpp (original)
+++ llvm/trunk/lib/MC/MCModule.cpp Thu Jul 4 18:20:12 2013
@@ -14,8 +14,19 @@
using namespace llvm;
-static bool AtomComp(const MCAtom *L, uint64_t Addr) {
- return L->getEndAddr() < Addr;
+static bool AtomComp(const MCAtom *LHS, const MCAtom *RHS) {
+ return LHS->getEndAddr() < RHS->getEndAddr();
+}
+
+MCModule::const_atom_iterator MCModule::atom_lower_bound(uint64_t Addr) const {
+ // This is a dummy atom, because VS 2008 doesn't like asymmetric comparators.
+ MCDataAtom AddrAtom(0, Addr, Addr);
+ return std::lower_bound(atom_begin(), atom_end(), &AddrAtom, AtomComp);
+}
+
+MCModule::atom_iterator MCModule::atom_lower_bound(uint64_t Addr) {
+ MCDataAtom AddrAtom(0, Addr, Addr);
+ return std::lower_bound(atom_begin(), atom_end(), &AddrAtom, AtomComp);
}
void MCModule::map(MCAtom *NewAtom) {
@@ -24,8 +35,7 @@ void MCModule::map(MCAtom *NewAtom) {
assert(Begin <= NewAtom->End && "Creating MCAtom with endpoints reversed?");
// Check for atoms already covering this range.
- AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
- Begin, AtomComp);
+ AtomListTy::iterator I = atom_lower_bound(Begin);
assert((I == atom_end() || (*I)->getBeginAddr() > NewAtom->End)
&& "Offset range already occupied!");
@@ -48,15 +58,13 @@ MCDataAtom *MCModule::createDataAtom(uin
// remap - Update the interval mapping for an atom.
void MCModule::remap(MCAtom *Atom, uint64_t NewBegin, uint64_t NewEnd) {
// Find and erase the old mapping.
- AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
- Atom->Begin, AtomComp);
+ AtomListTy::iterator I = atom_lower_bound(Atom->Begin);
assert(I != atom_end() && "Atom offset not found in module!");
assert(*I == Atom && "Previous atom mapping was invalid!");
Atoms.erase(I);
// Insert the new mapping.
- AtomListTy::iterator NewI = std::lower_bound(atom_begin(), atom_end(),
- NewBegin, AtomComp);
+ AtomListTy::iterator NewI = atom_lower_bound(NewBegin);
Atoms.insert(NewI, Atom);
// Update the atom internal bounds.
@@ -65,16 +73,14 @@ void MCModule::remap(MCAtom *Atom, uint6
}
const MCAtom *MCModule::findAtomContaining(uint64_t Addr) const {
- AtomListTy::const_iterator I = std::lower_bound(atom_begin(), atom_end(),
- Addr, AtomComp);
+ AtomListTy::const_iterator I = atom_lower_bound(Addr);
if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
return *I;
return 0;
}
MCAtom *MCModule::findAtomContaining(uint64_t Addr) {
- AtomListTy::iterator I = std::lower_bound(atom_begin(), atom_end(),
- Addr, AtomComp);
+ AtomListTy::iterator I = atom_lower_bound(Addr);
if (I != atom_end() && (*I)->getBeginAddr() <= Addr)
return *I;
return 0;
More information about the llvm-commits
mailing list