From ea0ce326fd12178b1797b7f3e3b2a204d22d0ab7 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 8 Feb 2022 16:10:10 +1100 Subject: [PATCH] [ORC-RT] Make ExecutorAddr hashable. This will be used in an upcoming macho_platform patch. --- compiler-rt/lib/orc/executor_address.h | 11 +++++++++++ .../lib/orc/unittests/executor_address_test.cpp | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/compiler-rt/lib/orc/executor_address.h b/compiler-rt/lib/orc/executor_address.h index 79ad9b7f1409..f8f417cb636d 100644 --- a/compiler-rt/lib/orc/executor_address.h +++ b/compiler-rt/lib/orc/executor_address.h @@ -212,4 +212,15 @@ using SPSExecutorAddrRangeSequence = SPSSequence; } // End namespace __orc_rt +namespace std { + +// Make ExecutorAddr hashable. +template <> struct hash<__orc_rt::ExecutorAddr> { + size_t operator()(const __orc_rt::ExecutorAddr &A) const { + return hash()(A.getValue()); + } +}; + +} // namespace std + #endif // ORC_RT_EXECUTOR_ADDRESS_H diff --git a/compiler-rt/lib/orc/unittests/executor_address_test.cpp b/compiler-rt/lib/orc/unittests/executor_address_test.cpp index 19a794ab6e18..7712ef9a773f 100644 --- a/compiler-rt/lib/orc/unittests/executor_address_test.cpp +++ b/compiler-rt/lib/orc/unittests/executor_address_test.cpp @@ -75,3 +75,10 @@ TEST(ExecutorAddrTest, AddrRanges) { EXPECT_TRUE(R1.overlaps(R3)); EXPECT_TRUE(R1.overlaps(R4)); } + +TEST(ExecutorAddrTest, Hashable) { + uint64_t RawAddr = 0x1234567890ABCDEF; + ExecutorAddr Addr(RawAddr); + + EXPECT_EQ(std::hash()(RawAddr), std::hash()(Addr)); +}