summaryrefslogtreecommitdiffstats
path: root/llvm/docs/CodingStandards.rst
diff options
context:
space:
mode:
authorMandeep Singh Grang <mgrang@codeaurora.org>2018-04-24 21:25:57 +0000
committerMandeep Singh Grang <mgrang@codeaurora.org>2018-04-24 21:25:57 +0000
commit434d4c0b88ff827ed99b06e297dfd466c094fcdb (patch)
tree7d22602b0f8322e858fba46df57f25a177d9985c /llvm/docs/CodingStandards.rst
parentb9b3a62727b38635a721be94ce24106580673aef (diff)
downloadbcm5719-llvm-434d4c0b88ff827ed99b06e297dfd466c094fcdb.tar.gz
bcm5719-llvm-434d4c0b88ff827ed99b06e297dfd466c094fcdb.zip
[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 llvm-svn: 330773
Diffstat (limited to 'llvm/docs/CodingStandards.rst')
-rw-r--r--llvm/docs/CodingStandards.rst11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index 1d631ccd92f..1010a4bf4af 100644
--- a/llvm/docs/CodingStandards.rst
+++ b/llvm/docs/CodingStandards.rst
@@ -826,6 +826,17 @@ As a rule of thumb, in case an ordered result is expected, remember to
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
============
OpenPOWER on IntegriCloud