Xcode 8.3.x: Swift 3.1 compiler crash (Segmentation fault: 11)

Originator:rsfinn
Number:rdar://31803589 Date Originated:2017-04-24
Status:Closed Resolved:
Product:Developer Tools Product Version:Xcode 8.3.2
Classification:Crash Reproducible:Always
 
Summary:
Building a complex project with Xcode 8.3 reliably crashes the Swift compiler in a particular source file.  I have been able to reduce the project to a relatively small sample project that crashes the compiler in the same way.  The crash occurred in each of Xcode 8.3, 8.3.1, and 8.3.2.

Steps to Reproduce:
1. Install Xcode 8.3.x (x = 0, 1, 2)
2. Open and build the attached project.

Expected Results:
The project build should complete (possibly with compiler errors) without the Swift compiler crashing.

Actual Results:
The Swift compiler crashes when trying to compile the file "main.swift".

Version:
Xcode version 8.3.2 (8E2002)
Apple LLVM version 8.1.0 (clang-802.0.42)
macOS 10.12.4 (16E195)

Comments

Fixed in Xcode 9 beta 3

The compiler crash no longer occurs when building the project using the compiler in Xcode 9 beta 3 (9M174d).

Workaround

I have discovered that moving the declaration of an enum type that was nested inside a class method definition
to the same level as the method definition suffices to avoid the compiler crash.

Crash log attached to bug report

Process:               swift [6563]
Path:                  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
Identifier:            swift
Version:               802.0.53
Code Type:             X86-64 (Native)
Parent Process:        swift [6561]
Responsible:           swift [6563]
User ID:               501

Date/Time:             2017-04-24 22:43:08.521 -0400
OS Version:            Mac OS X 10.12.4 (16E195)
Report Version:        12
Anonymous UUID:        F50F54C2-17B9-0CA5-5783-00047FC20EF0

Sleep/Wake UUID:       FCB158FB-1589-48CE-8491-8C135FBBD2D6

Time Awake Since Boot: 25000 seconds
Time Since Wake:       1200 seconds

System Integrity Protection: disabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [0]

VM Regions Near 0:
--> 
    __TEXT                 000000010a890000-000000010e164000 [ 56.8M] r-x/rwx SM=COW  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   swift          0x000000010b994757 swift::TypeBase::getCanonicalType() + 23
1   swift          0x000000010b1a8a3b swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 1227
2   swift          0x000000010b1abdc8 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 14424
3   swift          0x000000010b16b723 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 451
4   swift          0x000000010b0f1739 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 1081
5   swift          0x000000010b15f079 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 41
6   swift          0x000000010b108193 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 6979
7   swift          0x000000010b108b44 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 228
8   swift          0x000000010b10676e (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 286
9   swift          0x000000010b10b14d (anonymous namespace)::ArgEmitter::emitShuffle(swift::Expr*, swift::Expr*, llvm::ArrayRef, swift::ConcreteDeclRef, llvm::ArrayRef, llvm::ArrayRef, llvm::ArrayRef, swift::Type, swift::Lowering::AbstractionPattern) + 3677
10  swift          0x000000010b109206 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1958
11  swift          0x000000010b10676e (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 286
12  swift          0x000000010b105dd6 (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl&, llvm::SmallVectorImpl >&, llvm::Optional const&, swift::ImportAsMemberStatus const&) && + 438
13  swift          0x000000010b10312b (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 6123
14  swift          0x000000010b14ee7c swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 124
15  swift          0x000000010b161ed6 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 598
16  swift          0x000000010b1abe4a swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 14554
17  swift          0x000000010b16b509 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 409
18  swift          0x000000010b0ec89b swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 1867
19  swift          0x000000010b0eb8a2 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 642
20  swift          0x000000010b1b0efb (anonymous namespace)::SILGenType::emitType() + 971
21  swift          0x000000010b1b0acd swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 29
22  swift          0x000000010b0f8ecb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1483
23  swift          0x000000010b0faaa9 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional, bool, bool) + 1593
24  swift          0x000000010a90b604 swift::performFrontend(llvm::ArrayRef, char const*, void*, swift::FrontendObserver*) + 42516
25  swift          0x000000010a8bad6c main + 9052
26  libdyld.dylib  0x00007fff92a51235 start + 1

Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x00007fff55369820  rbx: 0x00007fd21b018af0  rcx: 0x000000010b1ac450  rdx: 0x0000000000000007
  rdi: 0x0000000000000000  rsi: 0x00007fd2189d70f8  rbp: 0x00007fff55365eb0  rsp: 0x00007fff55365d80
   r8: 0x000000007fffffff   r9: 0x00007fd21a522270  r10: 0x0000000000000001  r11: 0x0000000000000001
  r12: 0x00007fd2189d70f8  r13: 0x00007fff55366300  r14: 0x0000000000000000  r15: 0x0000000000000000
  rip: 0x000000010b994757  rfl: 0x0000000000010202  cr2: 0x0000000000000000
  
Logical CPU:     6
Error Code:      0x00000004
Trap Number:     14

Binary Images:
       0x10a890000 -        0x10e163fff +swift (802.0.53) <4A0E4F71-4627-3875-A1A1-5BC81D57E58B> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
       0x1185b3000 -        0x1185f0dc7  dyld (433.5) <8239D0D7-66F6-3C44-A77F-586F74525DA3> /usr/lib/dyld
    0x7fff914a9000 -     0x7fff914aaffb  libSystem.B.dylib (1238.51.1)  /usr/lib/libSystem.B.dylib
    0x7fff915e3000 -     0x7fff91639ff7  libc++.1.dylib (307.5) <0B43BB5D-E6EB-3464-8DE9-B41AC8ED9D1C> /usr/lib/libc++.1.dylib
    0x7fff9163a000 -     0x7fff91664fff  libc++abi.dylib (307.3) <30199352-88BF-30BD-8CFF-2A4FBE247523> /usr/lib/libc++abi.dylib
    0x7fff91a7b000 -     0x7fff91a99ff3  libedit.3.dylib (48.50.1) <5880F20C-5732-3285-B4F8-E2CBB464D950> /usr/lib/libedit.3.dylib
    0x7fff920aa000 -     0x7fff920dbffb  libncurses.5.4.dylib (51.30.1)  /usr/lib/libncurses.5.4.dylib
    0x7fff92157000 -     0x7fff92529047  libobjc.A.dylib (709)  /usr/lib/libobjc.A.dylib
    0x7fff92955000 -     0x7fff92966ff3  libz.1.dylib (67) <46E3FFA2-4328-327A-8D34-A03E20BFFB8E> /usr/lib/libz.1.dylib
    0x7fff92975000 -     0x7fff92979ff7  libcache.dylib (79) <093A4DAB-8385-3D47-A350-E20CB7CCF7BF> /usr/lib/system/libcache.dylib
    0x7fff9297a000 -     0x7fff92984fff  libcommonCrypto.dylib (60092.50.5)  /usr/lib/system/libcommonCrypto.dylib
    0x7fff92985000 -     0x7fff9298cfff  libcompiler_rt.dylib (62) <55D47421-772A-32AB-B529-1A46C2F43B4D> /usr/lib/system/libcompiler_rt.dylib
    0x7fff9298d000 -     0x7fff92995fff  libcopyfile.dylib (138) <819BEA3C-DF11-3E3D-A1A1-5A51C5BF1961> /usr/lib/system/libcopyfile.dylib
    0x7fff92996000 -     0x7fff92a19fdf  libcorecrypto.dylib (442.50.19) <8A39EE06-121C-3731-A9E9-35847064B3EE> /usr/lib/system/libcorecrypto.dylib
    0x7fff92a1a000 -     0x7fff92a4bfff  libdispatch.dylib (703.50.37)  /usr/lib/system/libdispatch.dylib
    0x7fff92a4c000 -     0x7fff92a51ffb  libdyld.dylib (433.5) <129D3B44-FB21-3750-9A68-48B5C3DC632B> /usr/lib/system/libdyld.dylib
    0x7fff92a52000 -     0x7fff92a52ffb  libkeymgr.dylib (28) <7AA011A9-DC21-3488-BF73-3B5B14D1FDD6> /usr/lib/system/libkeymgr.dylib
    0x7fff92a60000 -     0x7fff92a60fff  liblaunch.dylib (972.50.27) <037D198D-9B02-3EF9-A8E9-6F43EA555A9E> /usr/lib/system/liblaunch.dylib
    0x7fff92a61000 -     0x7fff92a66ff3  libmacho.dylib (898) <17D5D855-F6C3-3B04-B680-E9BF02EF8AED> /usr/lib/system/libmacho.dylib
    0x7fff92a67000 -     0x7fff92a69ff3  libquarantine.dylib (85.50.1) <7B32EA91-AB8B-32A4-8E52-9D3ED46CAC8E> /usr/lib/system/libquarantine.dylib
    0x7fff92a6a000 -     0x7fff92a6bffb  libremovefile.dylib (45) <38D4CB9C-10CD-30D3-8B7B-A515EC75FE85> /usr/lib/system/libremovefile.dylib
    0x7fff92a6c000 -     0x7fff92a84ff7  libsystem_asl.dylib (349.50.5) <096E4228-3B7C-30A6-8B13-EC909A64499A> /usr/lib/system/libsystem_asl.dylib
    0x7fff92a85000 -     0x7fff92a85ff7  libsystem_blocks.dylib (67) <10DC5404-73AB-35B3-A277-A8AFECB476EB> /usr/lib/system/libsystem_blocks.dylib
    0x7fff92a86000 -     0x7fff92b13fef  libsystem_c.dylib (1158.50.2)  /usr/lib/system/libsystem_c.dylib
    0x7fff92b14000 -     0x7fff92b17ffb  libsystem_configuration.dylib (888.51.2) <872C8A42-0871-3424-830B-84E587A75D27> /usr/lib/system/libsystem_configuration.dylib
    0x7fff92b18000 -     0x7fff92b1bfff  libsystem_coreservices.dylib (41.4)  /usr/lib/system/libsystem_coreservices.dylib
    0x7fff92b1c000 -     0x7fff92b34fff  libsystem_coretls.dylib (121.50.4)  /usr/lib/system/libsystem_coretls.dylib
    0x7fff92b35000 -     0x7fff92b3bfff  libsystem_dnssd.dylib (765.50.9)  /usr/lib/system/libsystem_dnssd.dylib
    0x7fff92b3c000 -     0x7fff92b65ff7  libsystem_info.dylib (503.50.4) <611DB84C-BF70-3F92-8702-B9F28A900920> /usr/lib/system/libsystem_info.dylib
    0x7fff92b66000 -     0x7fff92b88ff7  libsystem_kernel.dylib (3789.51.2)  /usr/lib/system/libsystem_kernel.dylib
    0x7fff92b89000 -     0x7fff92bd0fe7  libsystem_m.dylib (3121.6)  /usr/lib/system/libsystem_m.dylib
    0x7fff92bd1000 -     0x7fff92befff7  libsystem_malloc.dylib (116.50.8) <48D1BBA3-914E-3C65-AF70-C33B4A1B5233> /usr/lib/system/libsystem_malloc.dylib
    0x7fff92bf0000 -     0x7fff92c49ffb  libsystem_network.dylib (856.50.56)  /usr/lib/system/libsystem_network.dylib
    0x7fff92c4a000 -     0x7fff92c53ff3  libsystem_networkextension.dylib (563.50.32)  /usr/lib/system/libsystem_networkextension.dylib
    0x7fff92c54000 -     0x7fff92c5dff3  libsystem_notify.dylib (165.20.1)  /usr/lib/system/libsystem_notify.dylib
    0x7fff92c5e000 -     0x7fff92c66fe7  libsystem_platform.dylib (126.50.8) <5940EAB7-84D6-34DC-9B38-111648B2B589> /usr/lib/system/libsystem_platform.dylib
    0x7fff92c67000 -     0x7fff92c71ff7  libsystem_pthread.dylib (218.51.1) <62A84A68-431D-3B54-A7B6-31367CCF2884> /usr/lib/system/libsystem_pthread.dylib
    0x7fff92c72000 -     0x7fff92c75ff7  libsystem_sandbox.dylib (592.50.47) <87A2327D-B7A1-3E4C-A85D-D3D9484003DB> /usr/lib/system/libsystem_sandbox.dylib
    0x7fff92c76000 -     0x7fff92c77ff3  libsystem_secinit.dylib (24.50.4)  /usr/lib/system/libsystem_secinit.dylib
    0x7fff92c78000 -     0x7fff92c7fffb  libsystem_symptoms.dylib (532.50.47) <9CF6A47C-8343-3E85-9C27-A8D98E726A8B> /usr/lib/system/libsystem_symptoms.dylib
    0x7fff92c80000 -     0x7fff92c93ff7  libsystem_trace.dylib (518.51.1)  /usr/lib/system/libsystem_trace.dylib
    0x7fff92c94000 -     0x7fff92c99ffb  libunwind.dylib (35.3) <3D50D8A8-C460-334D-A519-2DA841102C6B> /usr/lib/system/libunwind.dylib
    0x7fff92c9a000 -     0x7fff92cc3ff7  libxpc.dylib (972.50.27)  /usr/lib/system/libxpc.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 20416
    thread_create: 0
    thread_set_state: 0

VM Region Summary:
ReadOnly portion of Libraries: Total=185.2M resident=0K(0%) swapped_out_or_unallocated=185.2M(100%)
Writable regions: Total=111.1M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=111.1M(100%)
 
                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Kernel Alloc Once                    8K        2 
MALLOC                           102.8M       23 
MALLOC guard page                   16K        4 
STACK GUARD                       56.0M        2 
Stack                             8192K        2 
VM_ALLOCATE (reserved)             256K        2         reserved VM address space (unallocated)
__DATA                            4216K       46 
__LINKEDIT                       120.1M        4 
__TEXT                            65.1M       44 
mapped file                       56.7M        9 
shared memory                        8K        3 
===========                     =======  ======= 
TOTAL                            413.0M      130 
TOTAL, minus reserved VM space   412.8M      130 

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!