-
Notifications
You must be signed in to change notification settings - Fork 10.5k
5.7 fix cast ownership #42378
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
5.7 fix cast ownership #42378
Conversation
(cherry picked from commit fd84606)
Added an AST helper in Types.h: - isPotentiallyAnyObject() This formalizes logic for when cast operations forward ownership. Various OSSA optimization rely on this for correctness. This fixes latent bugs throughout the optimizer. I was compelled to fix this now because we want to make OSSA optimizations across dynamic casts more aggressive. For example, we want to optimize retain/release across enum formation. (cherry picked from commit 1a9c2ad)
(cherry picked from commit 90ec837)
Allow borrowed class-to-AnyObject scalar casts. (cherry picked from commit 16e5fe9)
(cherry picked from commit 64ec981)
Use the new API that determines whether a cast preserves ownership. Remove an old hack. (cherry picked from commit a7c6a94)
@swift-ci test |
Linux error: |
@swift-ci test linux |
@eeckstein @tbkka these changes, taken together, should prevent the generation of ownership-guaranteed casts from This SIL becomes illegal, as it should be:
I'm cherry-picking this back to 5.7 because @eeckstein found this case occurring in a real project. Without these changes, the compiler ignores the SIL above, potentially miscompiling, until the function is specialized. Only when |
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.
lgtm
@tbkka hello branch manager |
@tbkka waiting for branch manager review |
Fixes rdar://91768775 (crash when specializing a cast for AnyObject)