[ORC] Stabilize output stream order
authorFangrui Song <i@maskray.me>
Sat, 22 Jul 2023 16:52:14 +0000 (09:52 -0700)
committerFangrui Song <i@maskray.me>
Sat, 22 Jul 2023 16:52:14 +0000 (09:52 -0700)
It currently depends on the StringMap iteration order, which is not
guaranteed to be deterministic. Use MapVector to stabilize the order.

llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp

index 3404adf..aca4576 100644 (file)
@@ -298,8 +298,12 @@ raw_ostream &operator<<(raw_ostream &OS, const SymbolState &S) {
 
 raw_ostream &operator<<(raw_ostream &OS, const SymbolStringPool &SSP) {
   std::lock_guard<std::mutex> Lock(SSP.PoolMutex);
+  SmallVector<std::pair<StringRef, int>, 0> Vec;
   for (auto &KV : SSP.Pool)
-    OS << KV.first() << ": " << KV.second << "\n";
+    Vec.emplace_back(KV.first(), KV.second);
+  llvm::sort(Vec, less_first());
+  for (auto &[K, V] : Vec)
+    OS << K << ": " << V << "\n";
   return OS;
 }