-
Type:
Bug
-
Status: Resolved
-
Priority:
Medium
-
Resolution: Done
-
Component/s: Compiler
-
Labels:
-
Environment:
Xcode 9.3 + iPhone X Simulator 11.3, or iPhone 6 Device 11.3
-
Radar URL:
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