[RemoteAddress] Handle comparison of addresses in different spaces

Sometimes it makes sense to compares addresses from different address
spaces.

rdar://148361743
This commit is contained in:
Augusto Noronha
2025-07-11 09:23:45 -07:00
parent d2ea4789d8
commit c97dfd6b05
4 changed files with 37 additions and 5 deletions

View File

@@ -55,18 +55,44 @@ public:
return !operator==(other);
}
bool inRange(const RemoteAddress &begin, const RemoteAddress &end) const {
assert(begin.AddressSpace != end.AddressSpace &&
"Unexpected address spaces");
if (AddressSpace != begin.AddressSpace)
return false;
return begin <= *this && *this < end;
}
bool operator<(const RemoteAddress rhs) const {
assert(AddressSpace == rhs.AddressSpace &&
"Comparing remote addresses of different address spaces");
return Data < rhs.Data;
}
/// Less than operator to be used for ordering purposes. The default less than
/// operator asserts if the address spaces are different, this one takes it
/// into account to determine the order of the addresses.
bool orderedLessThan(const RemoteAddress rhs) const {
if (AddressSpace == rhs.AddressSpace)
return Data < rhs.Data;
return AddressSpace < rhs.AddressSpace;
}
bool operator<=(const RemoteAddress rhs) const {
assert(AddressSpace == rhs.AddressSpace &&
"Comparing remote addresses of different address spaces");
return Data <= rhs.Data;
}
/// Less than or equal operator to be used for ordering purposes. The default
/// less than or equal operator asserts if the address spaces are different,
/// this one takes it into account to determine the order of the addresses.
bool orderedLessThanOrEqual(const RemoteAddress rhs) const {
if (AddressSpace == rhs.AddressSpace)
return Data <= rhs.Data;
return AddressSpace <= rhs.AddressSpace;
}
bool operator>(const RemoteAddress &rhs) const {
assert(AddressSpace == rhs.AddressSpace &&
"Comparing remote addresses of different address spaces");

View File

@@ -907,7 +907,7 @@ public:
for (auto Range : ranges) {
auto Start = std::get<0>(Range);
auto End = std::get<1>(Range);
if (Start <= Address && Address < End)
if (Address.inRange(Start, End))
return true;
}

View File

@@ -65,6 +65,10 @@ public:
bool containsRemoteAddress(remote::RemoteAddress remoteAddr,
uint64_t size) const {
if (Start.getRemoteAddress().getAddressSpace() !=
remoteAddr.getAddressSpace())
return false;
return Start.getRemoteAddress() <= remoteAddr &&
remoteAddr + size <= Start.getRemoteAddress() + Size;
}

View File

@@ -64,7 +64,7 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
.TypeReference.startAddress()
.getRemoteAddress();
return typeReferenceAStart < typeReferenceBStart;
return typeReferenceAStart.orderedLessThan(typeReferenceBStart);
});
}
@@ -75,9 +75,11 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
ReflectionInfoIndexesSortedByTypeReferenceRange.begin(),
ReflectionInfoIndexesSortedByTypeReferenceRange.end(), remoteAddr,
[&](uint32_t ReflectionInfoIndex, remote::RemoteAddress remoteAddr) {
return ReflectionInfos[ReflectionInfoIndex]
.TypeReference.endAddress()
.getRemoteAddress() <= remoteAddr;
auto reflectionInfoAddress = ReflectionInfos[ReflectionInfoIndex]
.TypeReference.endAddress()
.getRemoteAddress();
return reflectionInfoAddress.orderedLessThanOrEqual(remoteAddr);
});
if (possiblyMatchingReflectionInfoIndex ==