Search code examples
swift3archive

Archive project in Swift 3 and get "command failed due to signal segmentation fault 11"


I updated my code for Swift 3, run on devices and everything works, but when I Archive project, after cleaning and deleting Delivered Data, I have error "command failed due to signal segmentation fault 11"

My logs

0 swift 0x000000010a5ffb6d PrintStackTraceSignalHandler(void*) + 45

1 swift 0x000000010a5ff5b6 SignalHandler(int) + 470

2 libsystem_platform.dylib 0x00007fff9560152a _sigtramp + 26

3 libsystem_platform.dylib 0x00007fff5825ab50 _sigtramp + 3267728960

4 swift 0x0000000107d29432 swift::CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(swift::UnconditionalCheckedCastAddrInst*) + 1554

5 swift 0x0000000107db144d processFunction(swift::SILFunction&, bool, unsigned int) + 1901

6 swift 0x0000000107db7f9f (anonymous namespace)::ConstantPropagation::run() + 47

7 swift 0x0000000107d4862d swift::SILPassManager::runOneIteration() + 6077

8 swift 0x0000000107d4d7d6 swift::runSILOptimizationPasses(swift::SILModule&) + 3462

9 swift 0x0000000107a153cb performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef, int&, swift::FrontendObserver*) + 20107

10 swift 0x0000000107a0e265 swift::performFrontend(llvm::ArrayRef, char const*, void*, swift::FrontendObserver*) + 17029

11 swift 0x00000001079cb82d main + 8685

12 libdyld.dylib 0x00007fff8936c5ad start + 1

13 libdyld.dylib 0x000000000000006d start + 1992899265 Stack dump:

and this

  1. While running pass #1059521 SILFunctionTransform "Constant Propagation" on SILFunction "@_TTSg5VSC29UIApplicationLaunchOptionsKeyS_s8Hashable5UIKit_P__CSo8NSObjectS2_S0_10ObjectiveC_Ps9AnyObject____TFs17_dictionaryUpCastu2_Rxs8Hashable0_S_rFGVs10Dictionaryxq__GS0_q0_q1__".

Can someone help or tell, where should I search bug?


Solution

  • In my case I was passing launchOptions as function parameter to another class inside

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool

    After migrating to Swift 3, migrator added cast to match awaited parameter's type, which was of type [NSObject : AnyObject]? (pre Swift 3)

    All I had to do is just update my custom function to take [UIApplicationLaunchOptionsKey: Any] as parameter and remove that false cast. Simple as that

    I didn't have to compromise any optimization level (which shouldn't even be the last resort for developers, this is definitely not a way how to solve compiler errors/segmentation faults). After removing cast all is working fine with swift's whole module optimization.