[OwnershipUtils] Undef isn't introduced/enclosed.

Previously, calling `visitEnclosingDefs` or `visitBorrowIntroducers`
would crash if the `SILValue` argument were an instance of `SILUndef`
because both instantiate a `::FindEnclosingDefs` with the the result of
of calling `getFunction()` on that argument and `::FindEnclosingDefs` in
turn uses that result to create a `ValueSet`; but
`SILUndef::getFunction` returns `nullptr`, which is illegal to use as
the function for a `ValueSet`(or any other data structure relying on
`NodeBits`).

If the function specified as a separate argument, no values would be
visited and `true` would be returned.  Instead of burdening the API with
a separate argument, check for `SILUndef` up front and return `true`.
This commit is contained in:
Nate Chandler
2023-04-19 13:45:31 -07:00
parent cc0f42f509
commit c40f7c3d0a
2 changed files with 23 additions and 0 deletions

View File

@@ -2230,12 +2230,16 @@ protected:
bool swift::visitEnclosingDefs(SILValue value,
function_ref<bool(SILValue)> visitor) {
if (isa<SILUndef>(value))
return true;
return FindEnclosingDefs(value->getFunction())
.visitEnclosingDefs(value, visitor);
}
bool swift::visitBorrowIntroducers(SILValue value,
function_ref<bool(SILValue)> visitor) {
if (isa<SILUndef>(value))
return true;
return FindEnclosingDefs(value->getFunction())
.visitBorrowIntroducers(value, visitor);
}