[lld] r227709 - [ELF] Don't compare an atom with itself in compareByPosition().

Davide Italiano davide at freebsd.org
Sat Jan 31 21:06:45 PST 2015


Author: davide
Date: Sat Jan 31 23:06:45 2015
New Revision: 227709

URL: http://llvm.org/viewvc/llvm-project?rev=227709&view=rev
Log:
[ELF] Don't compare an atom with itself in compareByPosition().

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

Modified:
    lld/trunk/lib/Core/DefinedAtom.cpp

Modified: lld/trunk/lib/Core/DefinedAtom.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/DefinedAtom.cpp?rev=227709&r1=227708&r2=227709&view=diff
==============================================================================
--- lld/trunk/lib/Core/DefinedAtom.cpp (original)
+++ lld/trunk/lib/Core/DefinedAtom.cpp Sat Jan 31 23:06:45 2015
@@ -85,6 +85,10 @@ bool DefinedAtom::compareByPosition(cons
                                     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());





More information about the llvm-commits mailing list