[ELF] Don't compare an atom with itself in compareByPosition().
authorDavide Italiano <davide@freebsd.org>
Sun, 1 Feb 2015 05:06:45 +0000 (05:06 +0000)
committerDavide Italiano <davide@freebsd.org>
Sun, 1 Feb 2015 05:06:45 +0000 (05:06 +0000)
This caused some tests to fail on FreeBSD, and Mac OS X.
Some std::sort() implementations will check for strict-weak-ordering
by comparing with the same element, or will compare an element to
itself for 1-element sequence. Take care of this case. Thanks to
chandlerc for explaning that to me.

Reviewed by: ruiu

llvm-svn: 227709

lld/lib/Core/DefinedAtom.cpp

index 1d7795a..6e5ddaf 100644 (file)
@@ -85,6 +85,10 @@ bool DefinedAtom::compareByPosition(const DefinedAtom *lhs,
                                     const DefinedAtom *rhs) {
   const File *lhsFile = &lhs->file();
   const File *rhsFile = &rhs->file();
+
+  if (lhs == rhs)
+    return false; 
+
   if (lhsFile->ordinal() != rhsFile->ordinal())
     return lhsFile->ordinal() < rhsFile->ordinal();
   assert(lhs->ordinal() != rhs->ordinal());