<div dir="ltr">Might be worth pivoting this a bit differently to talk about ordering of pointers if that's the specific niche we're going to discourage/outlaw. (this could happen on std::set/map/etc too, when used with pointer keys)<br><br>Also "sort before iteration" is a bit too strong since it's only about when iterating to produce an ordered result (if it's an iteration to compute, say, a total or some order-agnostic summary/result, that's fine).<br><br>- Dave</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 6, 2017 at 11:55 AM Mandeep Singh Grang via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">mgrang created this revision.<br>
<br>
Beware of non-determinism due to iteration order of unordered containers<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D37525" rel="noreferrer" target="_blank">https://reviews.llvm.org/D37525</a><br>
<br>
Files:<br>
  docs/CodingStandards.rst<br>
<br>
<br>
Index: docs/CodingStandards.rst<br>
===================================================================<br>
--- docs/CodingStandards.rst<br>
+++ docs/CodingStandards.rst<br>
@@ -811,6 +811,20 @@<br>
   for (const auto *Ptr : Container) { observe(*Ptr); }<br>
   for (auto *Ptr : Container) { Ptr->change(); }<br>
<br>
+Beware of non-determinism due to iteration order of unordered containers<br>
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
+<br>
+Unordered containers like SmallPtrSet, DenseMap and DenseSet do not have<br>
+a defined iteration order. As a result, iteration of such containers can<br>
+result in non-deterministic code generation. While the generated code<br>
+might not necessarily be "wrong code", this non-determinism might result<br>
+in unexpected runtime crashes or simply hard to reproduce bugs on the<br>
+customer side making it harder to debug and fix.<br>
+<br>
+As a rule of thumb, remember to sort an unordered container before<br>
+iteration. Or try using ordered containers like SmallVector or MapVector<br>
+in case iteration is needed.<br>
+<br>
 Style Issues<br>
 ============<br>
<br>
<br>
<br>
</blockquote></div>