Skip to content

Commit 44c46c2

Browse files
authored
Merge pull request #63483 from atrick/find-address-use
Tweak findTransitiveUsesForAddress implementation
2 parents 75771c1 + b893de6 commit 44c46c2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ bool swift::canOpcodeForwardOwnedValues(Operand *use) {
131131
// Find all use points of \p guaranteedValue within its borrow scope. All uses
132132
// are naturally dominated by \p guaranteedValue. If a PointerEscape is found,
133133
// then no assumption can be made about \p guaranteedValue's lifetime. Therefore
134-
// the use points are incomplete and this returns false.
134+
// the use points are incomplete and this returns false. The escape point that
135+
// was found must still be in \p usePoints to distinguish from dead addresses.
135136
//
136137
// Accumulate results in \p usePoints, ignoring existing elements.
137138
//
@@ -982,6 +983,8 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
982983

983984
AddressUseKind result = AddressUseKind::NonEscaping;
984985

986+
// Record all uses that aren't transitively followed. These are either
987+
// instanteneous uses of the addres, or cause a pointer escape.
985988
auto leafUse = [foundUses](Operand *use) {
986989
if (foundUses)
987990
foundUses->push_back(use);
@@ -1011,6 +1014,7 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
10111014
// the apply to be a use point.
10121015
if (isa<PartialApplyInst>(user) || isa<AddressToPointerInst>(user)) {
10131016
result = meet(result, AddressUseKind::PointerEscape);
1017+
leafUse(op);
10141018
continue;
10151019
}
10161020
// First, eliminate "end point uses" that we just need to check liveness at
@@ -1035,6 +1039,7 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
10351039
if (isa<UnconditionalCheckedCastAddrInst>(user)
10361040
|| isa<MarkFunctionEscapeInst>(user)) {
10371041
assert(!user->hasResults());
1042+
leafUse(op);
10381043
continue;
10391044
}
10401045

@@ -1108,6 +1113,7 @@ swift::findTransitiveUsesForAddress(SILValue projectedAddress,
11081113
(*onError)(op);
11091114
}
11101115
result = meet(result, AddressUseKind::Unknown);
1116+
leafUse(op);
11111117
}
11121118
return result;
11131119
}

0 commit comments

Comments
 (0)