-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix unchecked_bitwise_cast to "escape" its operand's ownership #61393
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
Conversation
This makes it impossible for OSSA utilities to reason about the lifetime of the value being cast. This fixes bugs in which SILGen generates bitwise casts without protecting that lifetime. Fixes rdar://100527903 (Overrelease of optional closure when using shorthand syntax) The previous OSSA strategy was to gradually eliminate all "pointer escape" SIL patterns. That would define away a class of bugs in the OSSA utilities themselves. This was not friendly to developers working on SILGen, and we still don't have verification that can catch these bugs. The new strategy is to make all OSSA utilities aware of pointer escapes. This acknowledges reality that SIL is imperfect. Instead, optimizer support for transforming SIL always needs to recognize potentially dangerous patterns. The downside of this new strategy is that it hides performance problems because SIL optimizations can give up whenever they happen to see a "pointer escape". We need to keep working on this problem without being motivated by miscompiling code.
Fix the utilities used by LexicalDestroyHoisting that finds all uses to report a "PointerEscape". We can't rely on lifetime analysis when such a use is present.
Test that both canonicalization and lexical destroy hoisting recognize an "bail out" in the presence of unchecked_bitwise_cast.
@swift-ci test |
@swift-ci benchmark |
@@ -238,9 +238,31 @@ OPERAND_OWNERSHIP(PointerEscape, ProjectExistentialBox) | |||
OPERAND_OWNERSHIP(PointerEscape, UncheckedOwnershipConversion) | |||
OPERAND_OWNERSHIP(PointerEscape, ConvertEscapeToNoEscape) | |||
|
|||
// UncheckedBitwiseCast ownership behaves like RefToUnowned. It produces an | |||
// Unowned values from a non-trivial value, without consuming or borrowing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"an Unowned value"
bool swift::findUsesOfSimpleValue(SILValue value, | ||
SmallVectorImpl<Operand *> *usePoints) { | ||
for (auto *use : value->getUses()) { | ||
if (use->getOperandOwnership() == OperandOwnership::Borrow) { | ||
switch (use->getOperandOwnership()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the same change in LexicalDestroyFolding's findBorroweeUsage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'll need to figure out a test case for that one
@nate-chandler I'll merge this since CI is happy with it and the sooner it gets into builds the better. I'll immediately follow up with the destroy folding fix and comment grammar. |
Fix unchecked_bitwise_cast to "escape" its operand's ownership
This makes it impossible for OSSA utilities to reason about the
lifetime of the value being cast. This fixes bugs in which SILGen
generates bitwise casts without protecting that lifetime.
Also fix LexicalDestroyHoisting to bail out when ownership escapes via a
PointerEscape
operand.Fixes rdar://100527903 (Overrelease of optional closure when using shorthand syntax)
The previous OSSA strategy was to gradually eliminate all "pointer
escape" SIL patterns. That would define away a class of bugs in the
OSSA utilities themselves. This was not friendly to developers working
on SILGen, and we still don't have verification that can catch these
bugs.
The new strategy is to make all OSSA utilities aware of pointer
escapes. This acknowledges reality that SIL is imperfect. Instead,
optimizer support for transforming SIL always needs to recognize
potentially dangerous patterns.
The downside of this new strategy is that it hides performance
problems because SIL optimizations can give up whenever they happen to
see a "pointer escape". We need to keep working on this problem
without being motivated by miscompiling code.