swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.31k stars 10.34k forks source link

[SR-4687] Object corruption when generics are used with UIView on iOS 9 simulators #47264

Closed swift-ci closed 3 years ago

swift-ci commented 7 years ago
Previous ID SR-4687
Radar rdar://problem/31813495
Original Reporter mjholgate (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment Xcode 8.3.2, iOS 9.2/9.3 simulator
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, Miscompile, RunTimeCrash | |Assignee | None | |Priority | Medium | md5: e174098a42cc35c0971bb5029f815063

Issue Description:

I'm seeing a really weird issue where objects get corrupted when using generics on the iOS 9.2/9.3 simulators. I've attached an Xcode project showing the issue. Also I've reproduced the problematic part of the code below:


class MainObject: NSObject {
    let a = BaseView<Double>()
    let b = BaseView<Int>()

    override init() {
        super.init()
        a.label.text = "HELLO" // Crash here on iOS 9 simulator
                               // Change type of b to BaseView<Int>() - doesn't crash
    }
}

class BaseView<T>: UIView {
    private let x = UIPickerView()
    let label: UILabel = UILabel()
    private var value : T?    
}

It looks like the initialisation of 'b' in MainObject is causing 'a' to become corrupted. The crash is:

2017-04-25 13:31:41.687 Test[13321:33688179] -[UIPickerView setText:]: unrecognized selector sent to instance 0x7af38670

It appears that when trying to read the label property we actually end up reading the x property instead. I suspect this is something to do with the difference in the sizing of the specialisation (Int vs Double); if I change both a and b to be of type BaseView<Double>, then problem goes away.

Other observations:

belkadan commented 7 years ago

@swift-ci create

aschwaighofer commented 7 years ago

https://github.com/apple/swift/pull/9945