summaryrefslogtreecommitdiff
path: root/orc-rt
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2025-10-15 08:39:49 +1100
committerGitHub <noreply@github.com>2025-10-15 08:39:49 +1100
commitd098f19e0a7bcb259eaca634966f7ff0446443d5 (patch)
treec286e75e53e67f0f1944a4b3c9e61cd30c9109e9 /orc-rt
parent0fefa56b03c98cab7c0f9c61f4eaa735005f7b59 (diff)
[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 aa731e19045, which added the same operation to llvm::orc::ExecutorAddrRange.
Diffstat (limited to 'orc-rt')
-rw-r--r--orc-rt/include/orc-rt/ExecutorAddress.h3
-rw-r--r--orc-rt/unittests/ExecutorAddressTest.cpp6
2 files changed, 9 insertions, 0 deletions
diff --git a/orc-rt/include/orc-rt/ExecutorAddress.h b/orc-rt/include/orc-rt/ExecutorAddress.h
index cc7bbf53ac51..6ec583feace1 100644
--- a/orc-rt/include/orc-rt/ExecutorAddress.h
+++ b/orc-rt/include/orc-rt/ExecutorAddress.h
@@ -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);
}
diff --git a/orc-rt/unittests/ExecutorAddressTest.cpp b/orc-rt/unittests/ExecutorAddressTest.cpp
index 98074a7617de..2e049012cbfd 100644
--- a/orc-rt/unittests/ExecutorAddressTest.cpp
+++ b/orc-rt/unittests/ExecutorAddressTest.cpp
@@ -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) {