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

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 14 14:37:20 PDT 2025


https://github.com/lhames created https://github.com/llvm/llvm-project/pull/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.

>From 48165fbc74fd092f026d1723519bcb6d8c45f041 Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at gmail.com>
Date: Tue, 14 Oct 2025 15:57:46 +1100
Subject: [PATCH] [orc-rt] Add ExecutorAddrRange::contains overload for ranges.

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.
---
 orc-rt/include/orc-rt/ExecutorAddress.h  | 3 +++
 orc-rt/unittests/ExecutorAddressTest.cpp | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/orc-rt/include/orc-rt/ExecutorAddress.h b/orc-rt/include/orc-rt/ExecutorAddress.h
index cc7bbf53ac51a..6ec583feace12 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 98074a7617de4..2e049012cbfd2 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) {



More information about the llvm-commits mailing list