aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMandeep Singh Grang <mgrang@codeaurora.org>2017-09-06 20:19:10 +0000
committerMandeep Singh Grang <mgrang@codeaurora.org>2017-09-06 20:19:10 +0000
commit41915c0baa768b67f4d042e0e3a2868666e79487 (patch)
treed4aec5f9e3118057a86b04b8c4959f1418f325d0 /docs
parent9ca441aa442dd8c33b7a580447ede231b8f02ea7 (diff)
downloadllvm-41915c0baa768b67f4d042e0e3a2868666e79487.tar.gz
[docs] Add a note on iteration of unordered containers to coding standards
Summary: Beware of non-determinism due to ordering of pointers Reviewers: dblaikie, dexonsmith Reviewed By: dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D37525 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312667 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r--docs/CodingStandards.rst15
1 files changed, 15 insertions, 0 deletions
diff --git a/docs/CodingStandards.rst b/docs/CodingStandards.rst
index c4e25e4216e..0de2fc6b1a8 100644
--- a/docs/CodingStandards.rst
+++ b/docs/CodingStandards.rst
@@ -811,6 +811,21 @@ As a rule of thumb, use ``auto &`` unless you need to copy the result, and use
for (const auto *Ptr : Container) { observe(*Ptr); }
for (auto *Ptr : Container) { Ptr->change(); }
+Beware of non-determinism due to ordering of pointers
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+In general, there is no relative ordering among pointers. As a result,
+when unordered containers like sets and maps are used with pointer keys
+the iteration order is undefined. Hence, iterating such containers may
+result in non-deterministic code generation. While the generated code
+might not necessarily be "wrong code", this non-determinism might result
+in unexpected runtime crashes or simply hard to reproduce bugs on the
+customer side making it harder to debug and fix.
+
+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.
+
Style Issues
============