swift
9f54e9cd - SILGen: Fix double-free of `__owned` parameters of functions with `@_backDeploy`.

Commit
2 years ago
SILGen: Fix double-free of `__owned` parameters of functions with `@_backDeploy`. The following program crashed when compiled with the Swift 5.7 and 5.8 compilers: ``` @available(macOS 12, *) @_backDeploy(before: macOS 99) public func foo<T>(_ t: __owned T) { print("foo") } class C { deinit { print("deinit") } } foo(C()) print("done") ``` ``` > ./test foo deinit [1] 49162 segmentation fault ./test ``` The root cause is that generated SIL for the back deployment thunk for `foo(_:)` included its own `destroy_addr` instruction for the value of `t`, but didn't copy the parameter before passing it to the real function implementation which also destroys the value. The fix is to forward ownership of the parameter values to the called function, which causes cleanup generation to be skipped. Resolves rdar://104436515
Author
Committer
Parents
Loading