[lld] [llvm] [LLD][MachO] make InterfaceFile::symbols iteration order deterministic (PR #97615)

Ellis Hoag via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 3 12:40:12 PDT 2024


================
@@ -28,6 +29,18 @@ struct SymbolsMapKey {
 
   SymbolsMapKey(MachO::EncodeKind Kind, StringRef Name)
       : Kind(Kind), Name(Name) {}
+
+  bool operator==(const SymbolsMapKey &Other) const {
+    return Kind == Other.Kind && Name == Other.Name;
+  }
+
+  bool operator!=(const SymbolsMapKey &Other) const {
+    return operator==(Other);
+  }
+
+  bool operator<(const SymbolsMapKey &Other) const {
+    return Kind < Other.Kind || Name < Other.Name;
----------------
ellishg wrote:

```suggestion
    return std::make_pair(Kind, Name) < std::make_pair(Other.Kind, Other.Name);
```

If `Kind > Other.Kind`, this will confusingly return `true` if `Name < Other.Name`.

https://github.com/llvm/llvm-project/pull/97615


More information about the llvm-commits mailing list