Uploaded image for project: 'Swift'
  1. Swift
  2. SR-7354

Swift 4.1 Regression: EXC_BAD_ACCESS for Optimized Builds in Xcode 9.3

    XMLWordPrintable

    Details

      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

        Attachments

          Activity

            People

            • Assignee:
              atrick Andrew Trick
              Reporter:
              fabb Fabian Ehrentraud
            • Votes:
              3 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: