Xcode 7.0b6 (7A192o): [Swift] Various compiler crashes on closure creating UnsafePointer array using map

Originator:janoschhildebrand
Number:rdar://22436222 Date Originated:26-Aug-2015
Status:Duplicate of 22436079 (Closed) Resolved:Xcode 7.1b2
Product:Developer tools Product Version:Xcode 7.0b6 (7A192o)
Classification:Serious Bug Reproducible:Always
 
Summary:
The following snippets crash the Swift compiler (and SourceKitService). An example project and crash reports are attached.

I've included three crashing cases as they all produce different stack traces. However, as they are all very similar I included them in the same report as it might be likely that their causes are related.


// a)
_ = { () -> [UnsafePointer<Int>] in
    return [1, 2, 3].map {
        return UnsafePointer(UnsafeMutablePointer.alloc($0))
    }
}

// b)
_ = { () -> [UnsafePointer<Int>] in
    return (0..<100).map {
        return UnsafePointer(UnsafeMutablePointer.alloc($0))
    }
}

// c)
_ = {
    return [1, 2, 3].map {
        return UnsafeMutablePointer.alloc($0)
    }
}

Steps to Reproduce:
1. Open the attached project
2. Uncomment one of the crashing cases and build

Expected Results:
The code snippet should compile successfully

Actual Results:
The compiler & SourceKitService crash

Stack trace for a):

0  swift                    0x000000010b8b8edb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010b8b961b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff95333eaa _sigtramp + 26
3  libsystem_platform.dylib 0x00007fe03b87e478 _sigtramp + 2790565352
4  swift                    0x0000000109bb46bc swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::AccessKind) + 76
5  swift                    0x0000000109b9dcb0 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 128
6  swift                    0x0000000109b9c18f swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 47
7  swift                    0x0000000109b78c71 (anonymous namespace)::SILGenApply::visitExpr(swift::Expr*) + 49
8  swift                    0x0000000109b7b7d2 (anonymous namespace)::SILGenApply::visitApplyExpr(swift::ApplyExpr*) + 4466
9  swift                    0x0000000109b701f2 prepareApplyExpr(swift::Lowering::SILGenFunction&, swift::Expr*) + 178
10 swift                    0x0000000109b700ff swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 47
11 swift                    0x0000000109b9dda4 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 372
12 swift                    0x0000000109b99916 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 22
13 swift                    0x0000000109bdf22a swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 362
14 swift                    0x0000000109bdcf04 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 740
15 swift                    0x0000000109bdcd7b swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 347
16 swift                    0x0000000109bdcc15 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
17 swift                    0x0000000109bade98 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 216
18 swift                    0x0000000109b67544 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 212
19 swift                    0x0000000109ba59f1 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 97
20 swift                    0x0000000109b9ddc9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 409
21 swift                    0x0000000109b9c3ad swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 397
22 swift                    0x0000000109b9ff55 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 8997
23 swift                    0x0000000109b9c3ad swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 397
24 swift                    0x0000000109b69066 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 198
25 swift                    0x0000000109b6966b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
26 swift                    0x0000000109b6a230 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 944
27 swift                    0x0000000109b6a5dd swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
28 swift                    0x00000001099c8ed5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11445
29 swift                    0x00000001099c600a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2682
30 swift                    0x00000001099c2697 main + 2247
31 libdyld.dylib            0x00007fff8b77f5ad start + 1
32 libdyld.dylib            0x000000000000003a start + 1955072654



Stack trace for b):

(binary_expr type='<<error type>>' location=/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:14 range=[/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:13 - line:22:17] nothrow
  (overloaded_decl_ref_expr type='<<error type>>' location=/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:14 range=[/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:14 - line:22:14] name=..< #decls=3 specialized=no
  Swift.(file)...<
  Swift.(file)...<
  Swift.(file)...<)
  (tuple_expr type='<<error type>>' location=/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:13 range=[/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:13 - line:22:17]
    (integer_literal_expr type='<<error type>>' location=/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:13 range=[/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:13 - line:22:13] value=0)
    (integer_literal_expr type='<<error type>>' location=/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:17 range=[/Users/janoschhildebrand/Dropbox/Projects/Apple Bugs/untitled folder 2/Crash/Crash/main.swift:22:17 - line:22:17] value=100)))
0  swift                    0x0000000102aa2edb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x0000000102aa361b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff95333eaa _sigtramp + 26
3  swift                    0x0000000102a5d458 llvm::FoldingSetNodeID::operator==(llvm::FoldingSetNodeID const&) const + 40



Stack trace for c):

0  swift                    0x00000001099d5edb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x00000001099d661b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff95333eaa _sigtramp + 26
3  libsystem_platform.dylib 0x00000000ffffffff _sigtramp + 1791803759
4  swift                    0x0000000107c1f739 swift::Lowering::adjustFunctionType(swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo) + 25
5  swift                    0x0000000107c1fd9a swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 250
6  swift                    0x0000000107c42843 swift::SILModule::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t) + 147
7  swift                    0x0000000107c829f5 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 117
8  swift                    0x0000000107c844bc swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 76
9  swift                    0x0000000107cc29f1 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 97
10 swift                    0x0000000107cbadc9 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 409
11 swift                    0x0000000107cb93ad swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 397
12 swift                    0x0000000107cbcf55 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 8997
13 swift                    0x0000000107cb93ad swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 397
14 swift                    0x0000000107c86066 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 198
15 swift                    0x0000000107c8666b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
16 swift                    0x0000000107c87230 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 944
17 swift                    0x0000000107c875dd swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 109
18 swift                    0x0000000107ae5ed5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11445
19 swift                    0x0000000107ae300a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2682
20 swift                    0x0000000107adf697 main + 2247
21 libdyld.dylib            0x00007fff8b77f5ad start + 1
22 libdyld.dylib            0x000000000000003a start + 1955072654

Version:
Xcode 7.0b6 (7A192o)
Apple Swift version 2.0 (swiftlang-700.0.57.3 clang-700.0.72)

Notes:
Potentially related to rdar://22436079.

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!