Skip to content

Commit 93d855c

Browse files
committed
[RemoteAddress] Handle comparison of addresses in different spaces
Sometimes it makes sense to compares addresses from different address spaces. rdar://148361743 (cherry picked from commit c97dfd6)
1 parent c631b45 commit 93d855c

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

include/swift/Remote/RemoteAddress.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,44 @@ class RemoteAddress {
5555
return !operator==(other);
5656
}
5757

58+
bool inRange(const RemoteAddress &begin, const RemoteAddress &end) const {
59+
assert(begin.AddressSpace != end.AddressSpace &&
60+
"Unexpected address spaces");
61+
if (AddressSpace != begin.AddressSpace)
62+
return false;
63+
return begin <= *this && *this < end;
64+
}
65+
5866
bool operator<(const RemoteAddress rhs) const {
5967
assert(AddressSpace == rhs.AddressSpace &&
6068
"Comparing remote addresses of different address spaces");
6169
return Data < rhs.Data;
6270
}
6371

72+
/// Less than operator to be used for ordering purposes. The default less than
73+
/// operator asserts if the address spaces are different, this one takes it
74+
/// into account to determine the order of the addresses.
75+
bool orderedLessThan(const RemoteAddress rhs) const {
76+
if (AddressSpace == rhs.AddressSpace)
77+
return Data < rhs.Data;
78+
return AddressSpace < rhs.AddressSpace;
79+
}
80+
6481
bool operator<=(const RemoteAddress rhs) const {
6582
assert(AddressSpace == rhs.AddressSpace &&
6683
"Comparing remote addresses of different address spaces");
6784
return Data <= rhs.Data;
6885
}
6986

87+
/// Less than or equal operator to be used for ordering purposes. The default
88+
/// less than or equal operator asserts if the address spaces are different,
89+
/// this one takes it into account to determine the order of the addresses.
90+
bool orderedLessThanOrEqual(const RemoteAddress rhs) const {
91+
if (AddressSpace == rhs.AddressSpace)
92+
return Data <= rhs.Data;
93+
return AddressSpace <= rhs.AddressSpace;
94+
}
95+
7096
bool operator>(const RemoteAddress &rhs) const {
7197
assert(AddressSpace == rhs.AddressSpace &&
7298
"Comparing remote addresses of different address spaces");

include/swift/RemoteInspection/ReflectionContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ class ReflectionContext
904904
for (auto Range : ranges) {
905905
auto Start = std::get<0>(Range);
906906
auto End = std::get<1>(Range);
907-
if (Start <= Address && Address < End)
907+
if (Address.inRange(Start, End))
908908
return true;
909909
}
910910

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class ReflectionSection {
6565

6666
bool containsRemoteAddress(remote::RemoteAddress remoteAddr,
6767
uint64_t size) const {
68+
if (Start.getRemoteAddress().getAddressSpace() !=
69+
remoteAddr.getAddressSpace())
70+
return false;
71+
6872
return Start.getRemoteAddress() <= remoteAddr &&
6973
remoteAddr + size <= Start.getRemoteAddress() + Size;
7074
}

stdlib/public/RemoteInspection/TypeRefBuilder.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
6464
.TypeReference.startAddress()
6565
.getRemoteAddress();
6666

67-
return typeReferenceAStart < typeReferenceBStart;
67+
return typeReferenceAStart.orderedLessThan(typeReferenceBStart);
6868
});
6969
}
7070

@@ -75,9 +75,11 @@ TypeRefBuilder::ReflectionTypeDescriptorFinder::
7575
ReflectionInfoIndexesSortedByTypeReferenceRange.begin(),
7676
ReflectionInfoIndexesSortedByTypeReferenceRange.end(), remoteAddr,
7777
[&](uint32_t ReflectionInfoIndex, remote::RemoteAddress remoteAddr) {
78-
return ReflectionInfos[ReflectionInfoIndex]
79-
.TypeReference.endAddress()
80-
.getRemoteAddress() <= remoteAddr;
78+
auto reflectionInfoAddress = ReflectionInfos[ReflectionInfoIndex]
79+
.TypeReference.endAddress()
80+
.getRemoteAddress();
81+
82+
return reflectionInfoAddress.orderedLessThanOrEqual(remoteAddr);
8183
});
8284

8385
if (possiblyMatchingReflectionInfoIndex ==

0 commit comments

Comments
 (0)