lionpants
lionpants

Reputation: 1479

Swift 1.2 segmentation fault on compile of Release scheme

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.

Upvotes: 4

Views: 1314

Answers (3)

wxs
wxs

Reputation: 5837

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.

Upvotes: 1

robertfiorentino
robertfiorentino

Reputation: 594

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.

Upvotes: 0

Pascal
Pascal

Reputation: 16941

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.

Upvotes: 4

Related Questions