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

Rui Ueyama ruiu at google.com
Mon Feb 2 11:03:03 PST 2015


This is a nit, but probably we should move the if statement to the very
beginning of the function, so that we can save two function calls of file()
if the two pointers are the same.

On Sat, Jan 31, 2015 at 9:06 PM, Davide Italiano <davide at freebsd.org> wrote:

> 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());
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150202/066265fe/attachment.html>


More information about the llvm-commits mailing list