[Swift] 'if case ...' pattern match with tuple pattern crashes compiler

Originator:AustinZheng
Number:rdar://22872854 Date Originated:27-Sep-2015 10:37 AM
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification: Reproducible:
 
Summary:
Trying to use pattern matching in 'if' statements with a tuple pattern causes the compiler to segfault when compiling the code. This also happens with 'guard', 'for-in', and 'while'. An example follows:

let a = true
let b = true
if case (true, true) = (a, b) {
  print("both 'a' and 'b' are true")
}

I've enclosed the stacktrace/error message when the segfault happens:

CompileSwift normal x86_64 /Users/austinzheng/Experimental/TestProject/TestProject/main.swift
    cd /Users/austinzheng/Experimental/TestProject
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/austinzheng/Experimental/TestProject/TestProject/main.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I /Users/austinzheng/Experimental/TestProject/Build/Products/Debug -F /Users/austinzheng/Experimental/TestProject/Build/Products/Debug -enable-testing -g -module-cache-path /Users/austinzheng/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-generated-files.hmap -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-own-target-headers.hmap -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-all-target-headers.hmap -Xcc -iquote -Xcc /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-project-headers.hmap -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Products/Debug/include -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/DerivedSources/x86_64 -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/austinzheng/Experimental/TestProject -emit-module-doc-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name TestProject -emit-module-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.swiftdeps -o /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.o

0  swift                    0x000000010747137b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x0000000107471abb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff87153f1a _sigtramp + 26
3  libsystem_platform.dylib 0x5800000105716b7c _sigtramp + 2119969916
4  swift                    0x0000000105737fe5 swift::ASTVisitor<(anonymous namespace)::InitializationForPattern, void, void, void, std::__1::unique_ptr<swift::Lowering::Initialization, std::__1::default_delete<swift::Lowering::Initialization> >, void, void>::visit(swift::Pattern*) + 53
5  swift                    0x000000010573808f swift::ASTVisitor<(anonymous namespace)::InitializationForPattern, void, void, void, std::__1::unique_ptr<swift::Lowering::Initialization, std::__1::default_delete<swift::Lowering::Initialization> >, void, void>::visit(swift::Pattern*) + 223
6  swift                    0x0000000105737be1 swift::Lowering::SILGenFunction::emitStmtCondition(llvm::MutableArrayRef<swift::StmtConditionElement>, swift::Lowering::JumpDest, swift::SILLocation) + 209
7  swift                    0x0000000105784312 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 4210
8  swift                    0x00000001057833fb swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 347
9  swift                    0x0000000105783295 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
10 swift                    0x0000000105754ddb swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 331
11 swift                    0x000000010570cdbf swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 479
12 swift                    0x0000000105712fd0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 272
13 swift                    0x000000010571056b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
14 swift                    0x0000000105711120 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 928
15 swift                    0x00000001057114cd swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
16 swift                    0x00000001055652b2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11442
17 swift                    0x00000001055623f3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
18 swift                    0x000000010555ea74 main + 2324
19 libdyld.dylib            0x00007fff820735c9 start + 1
20 libdyld.dylib            0x000000000000003a start + 2113456754
Stack dump:
0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/austinzheng/Experimental/TestProject/TestProject/main.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I /Users/austinzheng/Experimental/TestProject/Build/Products/Debug -F /Users/austinzheng/Experimental/TestProject/Build/Products/Debug -enable-testing -g -module-cache-path /Users/austinzheng/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-generated-files.hmap -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-own-target-headers.hmap -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-all-target-headers.hmap -Xcc -iquote -Xcc /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/TestProject-project-headers.hmap -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Products/Debug/include -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/DerivedSources/x86_64 -Xcc -I/Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -working-directory/Users/austinzheng/Experimental/TestProject -emit-module-doc-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main~partial.swiftdoc -Onone -module-name TestProject -emit-module-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main~partial.swiftmodule -serialize-diagnostics-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.swiftdeps -o /Users/austinzheng/Experimental/TestProject/Build/Intermediates/TestProject.build/Debug/TestProject.build/Objects-normal/x86_64/main.o 
1.	While emitting SIL for 'myFunc' at /Users/austinzheng/Experimental/TestProject/TestProject/main.swift:18:1

Comments


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!