Skip to content

Commit 74d485e

Browse files
lhamesgithub-actions[bot]
authored andcommitted
Automerge: [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 aa731e1, which added the same operation to llvm::orc::ExecutorAddrRange.
2 parents a7c5e24 + d098f19 commit 74d485e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

orc-rt/include/orc-rt/ExecutorAddress.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ struct ExecutorAddrRange {
204204
constexpr bool contains(ExecutorAddr Addr) const noexcept {
205205
return Start <= Addr && Addr < End;
206206
}
207+
constexpr bool contains(const ExecutorAddrRange &Other) const noexcept {
208+
return (Other.Start >= Start && Other.End <= End);
209+
}
207210
constexpr bool overlaps(const ExecutorAddrRange &Other) const noexcept {
208211
return !(Other.End <= Start || End <= Other.Start);
209212
}

orc-rt/unittests/ExecutorAddressTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ TEST(ExecutorAddrTest, AddrRanges) {
9797
EXPECT_FALSE(R1.contains(A0));
9898
EXPECT_FALSE(R1.contains(A2));
9999

100+
EXPECT_TRUE(R3.contains(R0)); // True for singleton range at start.
101+
EXPECT_TRUE(R3.contains(R1)); // True for singleton range at end.
102+
EXPECT_FALSE(R3.contains(R2)); // False for non-overlaping singleton range.
103+
EXPECT_FALSE(R3.contains(R4)); // False for overlapping, uncontained range.
104+
100105
EXPECT_FALSE(R1.overlaps(R0));
101106
EXPECT_FALSE(R1.overlaps(R2));
102107
EXPECT_TRUE(R1.overlaps(R3));
103108
EXPECT_TRUE(R1.overlaps(R4));
109+
EXPECT_TRUE(R3.overlaps(R4));
104110
}
105111

106112
TEST(ExecutorAddrTest, Hashable) {

0 commit comments

Comments
 (0)