[llvm] r330773 - [docs] Add a note on non-deterministic sorting order of equal elements

Mandeep Singh Grang via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 24 14:25:58 PDT 2018


Author: mgrang
Date: Tue Apr 24 14:25:57 2018
New Revision: 330773

URL: http://llvm.org/viewvc/llvm-project?rev=330773&view=rev
Log:
[docs] Add a note on non-deterministic sorting order of equal elements

Reviewers: RKSimon, t.p.northover, dexonsmith

Reviewed By: RKSimon

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45831

Modified:
    llvm/trunk/docs/CodingStandards.rst

Modified: llvm/trunk/docs/CodingStandards.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CodingStandards.rst?rev=330773&r1=330772&r2=330773&view=diff
==============================================================================
--- llvm/trunk/docs/CodingStandards.rst (original)
+++ llvm/trunk/docs/CodingStandards.rst Tue Apr 24 14:25:57 2018
@@ -826,6 +826,17 @@ As a rule of thumb, in case an ordered r
 sort an unordered container before iteration. Or use ordered containers
 like vector/MapVector/SetVector if you want to iterate pointer keys.
 
+Beware of non-deterministic sorting order of equal elements
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+std::sort uses a non-stable sorting algorithm in which the order of equal
+elements is not guaranteed to be preserved. Thus using std::sort for a
+container having equal elements may result in non-determinstic behavior.
+To uncover such instances of non-determinism, LLVM has introduced a new
+llvm::sort wrapper function. For an EXPENSIVE_CHECKS build this will randomly
+shuffle the container before sorting. As a rule of thumb, always make sure to
+use llvm::sort instead of std::sort.
+
 Style Issues
 ============
 




More information about the llvm-commits mailing list