Skip to content

[RemoteAddress] Handle comparison of addresses in different spaces #82995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions include/swift/Remote/RemoteAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,44 @@ class RemoteAddress {
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");
Expand Down
2 changes: 1 addition & 1 deletion include/swift/RemoteInspection/ReflectionContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ class ReflectionContext
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;
}

Expand Down
4 changes: 4 additions & 0 deletions include/swift/RemoteInspection/TypeRefBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class ReflectionSection {

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;
}
Expand Down
10 changes: 6 additions & 4 deletions stdlib/public/RemoteInspection/TypeRefBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
.TypeReference.startAddress()
.getRemoteAddress();

return typeReferenceAStart < typeReferenceBStart;
return typeReferenceAStart.orderedLessThan(typeReferenceBStart);
});
}

Expand All @@ -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 ==
Expand Down