[PATCH] Fix bug that CompareAtoms::compare is not transitive.

Rui Ueyama ruiu at google.com
Fri Oct 18 15:19:12 PDT 2013


Hi shankarke,

This patch fixes a bug in r190608. The results of a comparison function
passed to std::sort must be transitive, which is, if a < b and b < c, and if
a != b, a < c must be also true. CompareAtoms::compare did not actually
guarantee the transitivity. As a result the sort results were sometimes just
wrong.

Consider there are three atoms, X, Y, and Z, whose file ordinals are 1, 2, 3,
respectively. Z has a property "layout-after X". In this case, all the
following conditionals become true:

  X < Y because of X's ordinal is less than Y's
  Y < Z because of Y's ordinal is less than Z's
  Z < X because of the layout-after relationship

This is not of course transitive. The reason why this happened is because
we used follow-on relationships for comparison if two atoms falls in the same
follow-on chain, but we used each atom's properties if they did not. This patch
fixes the issue by using follow-on root atoms for comparison to get consistent
results.

http://llvm-reviews.chandlerc.com/D1980

Files:
  include/lld/Passes/LayoutPass.h
  lib/Passes/LayoutPass.cpp
  test/core/layout-transitivity.objtxt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1980.1.patch
Type: text/x-patch
Size: 7733 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131018/3405f532/attachment.bin>


More information about the llvm-commits mailing list