Skip to content

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

Description

@swift-ci
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

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareoptimized onlyFlag: An issue whose reproduction requires optimized compilationregressionrun-time crashBug → crash: Swift code crashed during executionswift 4.1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions