mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
An @objc convenience initializer can replace 'self'. Since IRGen has no way to tell what the new 'self' value is from looking at SIL, it always refers back to the original 'self' argument when recovering DynamicSelfType metadata. This could cause a crash if the metadata was used after the 'self' value had been replaced. To fix the crash, always insert the metadata recovery into the entry block, where the 'self' value should be valid (even if uninitialized, the 'isa' pointer should be correct). Fixes <rdar://problem/50594689>.
37 lines
666 B
Swift
37 lines
666 B
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-build-swift %s -o %t/main -swift-version 5
|
|
// RUN: %target-codesign %t/main
|
|
// RUN: %target-run %t/main
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
import StdlibUnittest
|
|
|
|
func foo(_ x: @escaping () -> ()) { x() }
|
|
|
|
public class C {
|
|
var x: Int = 0
|
|
|
|
init(blah: ()) {}
|
|
|
|
@objc convenience init() {
|
|
self.init(blah: ())
|
|
|
|
foo { [weak self] in
|
|
guard let `self` = self else { return }
|
|
self.x += 1
|
|
}
|
|
}
|
|
}
|
|
|
|
var ConvenienceInitSelfTest = TestSuite("ConvenienceInitSelf")
|
|
|
|
ConvenienceInitSelfTest.test("SelfMetadata") {
|
|
let c = C()
|
|
expectEqual(c.x, 1)
|
|
}
|
|
|
|
runAllTests() |