4

I've just upgraded to Swift 1.2 and when I attempt to compile the iOS application using the Release scheme I receive a "segmentation fault: 11".

0  swift                    0x00000001105a9a08 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x00000001105a9ee4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff9a724f1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff4fd6f6b0 _sigtramp + 3043272624
4  swift                    0x00000001100e837a (anonymous namespace)::DCE::markControllingTerminatorsLive(swift::SILBasicBlock*) + 346
5  swift                    0x00000001100e8109 (anonymous namespace)::DCE::markValueLive(swift::ValueBase*) + 201
6  swift                    0x00000001100e791f (anonymous namespace)::DCE::run() + 1983
7  swift                    0x000000011008f55e swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>) + 1310
8  swift                    0x000000011008ffe9 swift::SILPassManager::runOneIteration() + 633
9  swift                    0x000000011008ea56 swift::runSILOptimizationPasses(swift::SILModule&) + 790
10 swift                    0x000000010fe92ee7 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4695
11 swift                    0x000000010fe91ae6 main + 1814
12 libdyld.dylib            0x00007fff995665c9 start + 1

The application compiles and runs perfectly when I use the Dev/Debug scheme.

I have narrowed the compiler issue down to a single file and a couple lines of code.

let directPhoneType = PhoneNumber.Codes.Contacts["D"]
phoneTypes = phoneTypes.filter { $0 != directPhoneType }

I've tried changing the filtering code around (using "element in", etc), but each attempt causes the segmentation fault still. There is other filtering logic throughout our application that compiles fine.

If I remove the filtering code or change it to a loop that manually filters the phone types, the Application runs fine in the Release scheme.

I've tried setting the optimization level to "Fastest, Unchecked" or "Fastest", the segmentation fault still occurs. If I set the optimization level to "None"; the project builds.

This code worked fine before Swift 1.2 in both schemes.

Anyone have any insight into what is going on here?

UPDATE: It looks like Xcode 6.3.1 has fixed my seg fault issues.

lionpants
  • 1,469
  • 14
  • 24
  • 1
    You have replaced one beta by another beta – qwerty_so Apr 10 '15 at 20:53
  • I found this and this worked for me. I'm not sure though what consequences it makes not to have the checks enabled http://stackoverflow.com/questions/26508911/cant-archive-working-6-0-1-swift-project-in-xcode-6-1-segmentation-fault-11 – batkru Apr 12 '15 at 03:21
  • Setting the optimization level to Fastest, Unchecked does not fix the problem for me. If I set the optimization level to None; the project builds. – lionpants Apr 13 '15 at 12:18
  • 1. The compiler shouldn't crash. Since you apparently have a reduced test case, please [file a bug](http://bugreport.apple.com) so Apple can fix this. 2. As a workaround, try explicitly declaring types on either `directPhoneType` or `$0`, maybe? – rickster Apr 13 '15 at 13:56
  • Ya, I tried the explicit typing, no luck. I've filed a bug and will use "None" optimization for now. Thanks. – lionpants Apr 13 '15 at 17:46
  • Thank you for reporting back! Note that there are also compilation bugs in 6.3.1, which are said to be fixed in 6.3.2 (GM seed released somewhat secretly today). – matt May 11 '15 at 19:26
  • I think this regressed in Xcode 7.x :-( – pohl Oct 01 '15 at 14:54
  • Uh oh. We haven't upgraded yet. Hopefully its fixed by that time. :P – lionpants Oct 01 '15 at 19:23

3 Answers3

4

Ran into the same problem, without having code similar to yours. Turning off whole module optimization (which is off by default) solved the issue for me, meaning I'm still able to archive with fastest optimization settings.

Pascal
  • 16,846
  • 4
  • 60
  • 69
1

Unfortunately we have these sorts of issues all the time. The fault is not with you and they are frustratingly difficult to track down. Usually somewhat arbitrary code changes eventually solve things.

Various superstitions we have developed include: reducing use of unowned where possible, reducing use of weak where possible, being cautious of the ?? operator, being cautious of "too much" stuff in one line (like max(min(x,y),z)), switching let to var, etc.

In your code I might try switching your let to a var, or try removing the filter and doing an old school

var resultList = [MyType]()
for type in phoneTypes {
     if type != directPhoneType {
         resultList.append(type)
     }
}

or change PhoneNumber.Codes.Contacts["D"] to access that differently.

Good luck! Happy hunting.

wxs
  • 5,617
  • 5
  • 36
  • 51
  • I agree--this error can happen for any of the reasons stated by @wxs. From my experience though, this is the Swift compiler actually detecting a compile-time error, but for some reason, it can't produce a better error message. Allow me to add: check if any of your implicitly unwrapped optionals are nil, especially in areas where you chain them. – Matthew Quiros May 11 '15 at 19:43
0

I had this problem when switching to Swift 1.2 and not just for release scheme. While migrating, I had changed a recommended "as!" to "as?" thinking that it was what I wanted. That seems to have caused the problem; I went back and changed to "as!" and it worked.

robertfiorentino
  • 584
  • 7
  • 20