swiftlang / swift

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

[SR-7561] Release Scheme : Swift dealloc Bug : EXC_BAD_ACCESS : EXC_I386_INVOP #50103

Open swift-ci opened 6 years ago

swift-ci commented 6 years ago
Previous ID SR-7561
Radar https://bugreport.apple.com/web/?problemID=39735886
Original Reporter antony.newman (JIRA User)
Type Bug

Attachment: Download

Environment swift 4.1 / Xcode 9.3 / iOS 11.3 / any iDevice Compiled a nMP
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, OptimizedOnly, RunTimeCrash | |Assignee | None | |Priority | Medium | md5: fe8e820e91dd27418a99c6ac1f6ac393

Issue Description:

+++) The following code Crashes with a RELEASE scheme, but is OK on a DEBUG scheme.

+) To reproduce : Run in Xcode Simulator -> Click three times on the RED Box and it crashes.

+) Any of the following three changes to RELEASE scheme seem to fix this crash (and also fix much larger projects that crash with the same fault)

1) Change 'Enable Testability' -> Yes

2) Change 'Compilation Mode' -> Single File

3) Change 'Swift Compiler - Code Generation : Optimization Level' -> Either No optimization or Optimize for Size.

import UIKit

var g_but = MY_UIButton(frame: CGRect(x: 100, y: 100,width: 200,height: 200))
let g_false = false
let opt_zero : Int? = 0
class EMPTY_CLASS {}
let g_empty_arr : [EMPTY_CLASS] = []

class ViewController: UIViewController
{
    override func viewDidAppear(_ animated: Bool)
    {
        super.viewDidAppear(animated)
        g_but.backgroundColor = UIColor.red
        view.addSubview(g_but)
        g_but.addTarget(g_but,action: #selector(MY_UIButton.touchDown(_:)), for:.touchDown)
    }
}

class MY_UIButton : UIButton
{
    @objc func touchDown(_: MY_UIButton?)
    {
        if (opt_zero! >= g_empty_arr.count) {}
        let zero_str = (opt_zero == nil) ? "" : "\(opt_zero!)"
        if (g_false) {  print(zero_str) }
        if (opt_zero! >= g_empty_arr.count) {}
    }
}
bc7072e8-7d37-4a38-8fee-cab463d443b7 commented 6 years ago

cc @eeckstein