-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SILGen: Fix potential use-after-free in @_backDeploy
coroutines
#60021
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
SILGen: Fix potential use-after-free in @_backDeploy
coroutines
#60021
Conversation
The SIL verifier has identified an issue with the SIL generated for property accessors structured like this: ``` public struct S { @available(macOS, introduced: 12.0) @_backDeploy(before: macOS 13.0) public var x: String { _read { yield "x" } } } ``` The emitted SIL is invalid because the value `%9` is used after `end_apply` may have ended the lifetime of the value: ``` bb1: %8 = function_ref @$s4test1SV1xSSvrTwB : $@yield_once @convention(method) (S) -> @yields @guaranteed String9 (%9, %10) = begin_apply %8(%0) : $@yield_once @convention(method) (S) -> @yields @guaranteed String end_apply %10 yield %9 : $String, resume bb3, unwind bb2 ``` The fix is to move the `end_apply` to the resume and unwind blocks, after the value has been yielded to the caller. Resolves rdar://96879247
@swift-ci please smoke test |
I am not reviewing this... but unless the test that you modified has this specific test there, you aren't actually testing the broken test case? If my guess is right, can you dd that test case explicitly and check the SILGen? |
The changed location of I am not sure whether the fact that the verifier didn't catch this on this existing test case is a bug in the verifier or not. It seems like the lifetime of |
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.
Seems correct to me.
Yes, I think that's a good idea. You can do that in a follow-up PR. These kind of lifetime/ownership verifications are only done for non-trivial types. So if you use e.g. a class in your test, it should work. |
…lds a non-trivial value. This is a follow up to swiftlang#60021 to ensure that a test exists that would cause lifetime verification to fail if the fix regressed.
I've expanded the runtime tests for |
…lds a non-trivial value. This is a follow up to swiftlang#60021 to ensure that a test exists that would cause lifetime verification to fail if the fix regressed.
…lds a non-trivial value. This is a follow up to swiftlang#60021 to ensure that a test exists that would cause lifetime verification to fail if the fix regressed.
The SIL verifier has identified an issue with the SIL generated for property accessors structured like this:
The emitted SIL is invalid because the value
%9
is used afterend_apply
may have ended the lifetime of the value:The fix is to move the
end_apply
to the resume and unwind blocks, after the value has been yielded to the caller.Resolves rdar://96879247