14

I have a xcode project and running on the device, debug build everything is fine.

However when i try to archive the project im getting a segfault from the Swift Compiler:

0  swift                    0x0000000105c36608 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x0000000105c36af4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff852705aa _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000002 _sigtramp + 2061040242
4  swift                    0x0000000105f51896            swift::TypeBase::getTypeOfMember(swift::Module*, swift::ValueDecl const*,    swift::LazyResolver*, swift::Type) + 534
5  swift                    0x00000001050eee38 swift::SILType::getFieldType(swift::VarDecl*, swift::SILModule&) const + 56
6  swift                    0x00000001051a1252 (anonymous namespace)::SILSROA::run() + 3602
7  swift                    0x000000010516b116 swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>) + 310
8  swift                    0x000000010516b6f9 swift::SILPassManager::runOneIteration() + 761
9  swift                    0x000000010516b92b swift::SILPassManager::run() + 251
10 swift                    0x000000010516afbc swift::runSILOptimizationPasses(swift::SILModule&, swift::SILOptions const&) + 1644
11 swift                    0x0000000104ffb141 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 3537
12 swift                    0x0000000104ffa35d main + 1533
13 libdyld.dylib            0x00007fff885d75fd start + 1
14 libdyld.dylib            0x0000000000000052 start + 2007140950

I have seen people talking about certain synta that can cause this kind of error, but does anyone know how to try and track down which bit(s) of the code is causing the segfault?

Jozef Dransfield
  • 524
  • 4
  • 11

4 Answers4

36

I had a similar issue and the "solution" was to turn swift compiler code generation optimization level to -Onone in build settings for the release configuration. This is as of Xcode 6.0.1. Turning off swift compiler optimization

wfbarksdale
  • 7,498
  • 15
  • 65
  • 88
3

before lowering optimization level (which is definitely not a way how to solve compilation problems, unless you're using some pretty neat low level stuff or some specialities).

Simply look what compiler is trying to tell you - yeap. it's not human readable log yet. But you can read, can't you?:)

I got problem like this.

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

If you'll look closely at that mess, you will find that you're doing sort of upcasting, that's not allowed.

What does it mean? Look into your function

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

and find a place where you cast launchOptions as [NSObject : AnyObject]?

In swift 3 it has changed into [UIApplicationLaunchOptionsKey: Any]?. Remove that cast and update your code that awaits launchOptions as [NSObject : AnyObject]?.

If that helps, just turn on the amazing swift whole module optimization back + in case you don't have a clue what whole module optimization is -> read this article:

https://swift.org/blog/whole-module-optimizations/

deathhorse
  • 637
  • 6
  • 15
0

I had this issue as well and I've found out that certain constructs in code seem to cause compiler crash.

One of the constructs is when you use too much [weak self]s like this:

whatever { [weak self] in
    whatever2 { [weak self] in
    }
}

The second [weak self] is unnecessary and causes compiler to crash.

olejnjak
  • 1,163
  • 1
  • 9
  • 23
-1

On a project inherited from another development company, we faced the same error. We noticed there were some custom build settings related to the Swift language version and C++ language dialect (in the Apple LLVM section). Here's what we did to fix:

  • Put back Swift version to its default value (it was 2.3 before)
  • Reset all options related to the C++ dialect
  • Updated the pods with pod update and fixed some new warnings

We were then able to build and archive the project.

Also, when you set the device to Generic iOS Device, it's important to follow the steps in this order:

  • Product » Clean
  • Product » Build
  • Product » Archive
Andrea Lazzarotto
  • 2,471
  • 1
  • 22
  • 38