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)); +}