[orc-rt] Add ExecutorAddrRange::contains overload for ranges. (#163458)

Can be used to test that one address range is fully contained within
another. This is an orc-rt counterpart to aa731e1904, which added the
same operation to llvm::orc::ExecutorAddrRange.
This commit is contained in:
Lang Hames
2025-10-15 08:39:49 +11:00
committed by GitHub
parent 0fefa56b03
commit d098f19e0a
2 changed files with 9 additions and 0 deletions

View File

@@ -204,6 +204,9 @@ struct ExecutorAddrRange {
constexpr bool contains(ExecutorAddr Addr) const noexcept {
return Start <= Addr && Addr < End;
}
constexpr bool contains(const ExecutorAddrRange &Other) const noexcept {
return (Other.Start >= Start && Other.End <= End);
}
constexpr bool overlaps(const ExecutorAddrRange &Other) const noexcept {
return !(Other.End <= Start || End <= Other.Start);
}

View File

@@ -97,10 +97,16 @@ TEST(ExecutorAddrTest, AddrRanges) {
EXPECT_FALSE(R1.contains(A0));
EXPECT_FALSE(R1.contains(A2));
EXPECT_TRUE(R3.contains(R0)); // True for singleton range at start.
EXPECT_TRUE(R3.contains(R1)); // True for singleton range at end.
EXPECT_FALSE(R3.contains(R2)); // False for non-overlaping singleton range.
EXPECT_FALSE(R3.contains(R4)); // False for overlapping, uncontained range.
EXPECT_FALSE(R1.overlaps(R0));
EXPECT_FALSE(R1.overlaps(R2));
EXPECT_TRUE(R1.overlaps(R3));
EXPECT_TRUE(R1.overlaps(R4));
EXPECT_TRUE(R3.overlaps(R4));
}
TEST(ExecutorAddrTest, Hashable) {