[llvm] [Object] Provide operator< for ELFSymbolRef (PR #89861)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Apr 23 19:42:21 PDT 2024
    
    
  
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Amir Ayupov (aaupov)
<details>
<summary>Changes</summary>
Normally, operator< accepting DataRefImpl is used when comparing
SymbolRef/ELFSymbolRef. However, it uses std::memcmp which interprets
DataRefImpl union as char string. For ELFSymbolRef it's known that it
uses the struct view of the union, therefore a specialized operator< can
be used instead.
---
Full diff: https://github.com/llvm/llvm-project/pull/89861.diff
1 Files Affected:
- (modified) llvm/include/llvm/Object/ELFObjectFile.h (+8) 
``````````diff
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index 1d457be93741f2..8ec0e3fe15dc9d 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -199,6 +199,14 @@ class ELFSymbolRef : public SymbolRef {
   }
 };
 
+inline bool operator<(const ELFSymbolRef &A, const ELFSymbolRef &B) {
+  const DataRefImpl &DRIA = A.getRawDataRefImpl();
+  const DataRefImpl &DRIB = B.getRawDataRefImpl();
+  if (DRIA.d.a == DRIB.d.a)
+    return DRIA.d.b < DRIB.d.b;
+  return DRIA.d.a < DRIB.d.b;
+}
+
 class elf_symbol_iterator : public symbol_iterator {
 public:
   elf_symbol_iterator(const basic_symbol_iterator &B)
``````````
</details>
https://github.com/llvm/llvm-project/pull/89861
    
    
More information about the llvm-commits
mailing list