Skip to content
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

[SR-7354] Swift 4.1 Regression: EXC_BAD_ACCESS for Optimized Builds in Xcode 9.3 #49902

Closed
swift-ci opened this issue Apr 4, 2018 · 14 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software optimized only Flag: An issue whose reproduction requires optimized compilation regression run-time crash Bug → crash: Swift code crashed during execution swift 4.1

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 4, 2018

Previous ID SR-7354
Radar rdar://problem/39209102
Original Reporter fabb (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 9.3 + iPhone X Simulator 11.3, or iPhone 6 Device 11.3

Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Bug, 4.1Regression, OptimizedOnly, RunTimeCrash
Assignee @atrick
Priority Medium

md5: 01fbdfe890b85cc4dcce92b1c7fe221d

Issue Description:

Since updating to Xcode 9.3 our project crashes on launch for optimized builds. It happens both on device and simulator, but not necessarily in the same locations. It worked fine with the previous Xcode. It happens for all builds with -O or -Osize optimizations, independent of WMO de/activated, and independent of Swift 3 / Swift 4 mode.

Changing arbitrary things in the method makes it run without crash. Even putting it into a different file might make it not crash anymore.

Example repro code:

// crashes when called on an optimized build (-O or -Osize) both on simulator and device
func crash() {
    let blah = ProblematicEnum.problematicCase.problematicMethod()
    NSLog("\(blah)")
}

enum ProblematicEnum {
    case first, second, problematicCase
    
    func problematicMethod() -> SomeClass {
        let someVariable: SomeClass
        
        switch self {
        case .first:
            someVariable = SomeClass()
        case .second:
            someVariable = SomeClass()
        case .problematicCase:
            someVariable = SomeClass(someParameter: NSObject())
            _ = NSObject().description
            return someVariable // EXC_BAD_ACCESS (simulator: EXC_I386_GPFLT, device: code=1)
        }
        
        let _ = [someVariable]
        return SomeClass(someParameter: NSObject())
    }
    
}

class SomeClass: NSObject {
    override init() {}
    init(someParameter: NSObject) {}
}

Example project for convenience: https://github.com/fabb/swift_4_1_crash

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 5, 2018

Comment by Fabian Ehrentraud (JIRA)

it's a very strange crash, e.g. removing the NSObject as a parent class of SomeClass results in not crashing anymore. So does not passing someParameter anymore in either of the 2 locations. Or removing the `second` case, or merging the 2 cases in the `switch`.

@belkadan
Copy link
Contributor

belkadan commented Apr 5, 2018

Very strange. Thanks, Fabian!

@swift-ci create

@gottesmm
Copy link
Member

gottesmm commented Apr 6, 2018

Looking at this.

@swift-ci
Copy link
Collaborator Author

Comment by Fabian Ehrentraud (JIRA)

@gottesmm any news on this? it would be helpful for us if after analyzing, you could give an exact description under which circumstances the bug happens, so we can analyze the rest of our codebase for this pattern. currently we're afraid to update as it's hard to test all the special cases in our app.

@gottesmm
Copy link
Member

We have already triaged the issue and have a fix:

#15840

@swift-ci
Copy link
Collaborator Author

Comment by Fabian Ehrentraud (JIRA)

@gottesmm awesome, thanks for the fast fix!

@gottesmm @belkadan Do you consider the bug bad enough to warrant an Xcode bugfix release?
As a non-compiler-engineer I couldn't really deduce which kind of Swift code might be affected from the explanation in the PR. Is it even possible to do that, or are the possibly dangerous patterns endless?

@atrick
Copy link
Member

atrick commented Apr 11, 2018

This has to do with the interaction between passes. There's nothing really unusual about the Swift code that triggers it. It should be fixed at the next possible opportunity.

@belkadan
Copy link
Contributor

We can't ever talk about whether there'll be an Xcode bugfix release, or whether particular fixes would make it into any such release. This bug is pretty bad, especially in that you can't tell whether you're going to hit it beforehand, but every bug without a workaround is blocking somebody.

@atrick
Copy link
Member

atrick commented Apr 12, 2018

@swift-ci
Copy link
Collaborator Author

Comment by Fabian Ehrentraud (JIRA)

@belkadan thank you. too bad that no fixing xcode release seems in sight. we rolled back to xcode 9.2.

@belkadan
Copy link
Contributor

belkadan commented May 2, 2018

Since the beta is out now I can say that this should be in Xcode 9.4b2.

@swift-ci
Copy link
Collaborator Author

Comment by Fabian Ehrentraud (JIRA)

@belkadan Xcode 9.4 just was released, but this bugfix is not mentioned in the release notes. Is it included?

@belkadan
Copy link
Contributor

Yes, it is!

@swift-ci
Copy link
Collaborator Author

Comment by Fabian Ehrentraud (JIRA)

Awesome, thank you!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software optimized only Flag: An issue whose reproduction requires optimized compilation regression run-time crash Bug → crash: Swift code crashed during execution swift 4.1
Projects
None yet
Development

No branches or pull requests

5 participants