swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.52k stars 10.35k forks source link

[SR-403] Swift compiler crash with this code snippet #43020

Closed swift-ci closed 7 years ago

swift-ci commented 8 years ago
Previous ID SR-403
Radar None
Original Reporter mohu3g (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment Mac OS X 10.11.2 Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, SILGen | |Assignee | @slavapestov | |Priority | Medium | md5: a21fb6465b4af12612744c35d1bafa27

Issue Description:

let options : [(String) -> ((Int) -> Void)] = [
    {
        (String) -> ((Int) -> Void) in
        return {

        }
    }
]

Save this snippet as file '1.swift', run command

swift 1.swift

or compile the snippet in Xcode, the result is the same.

backstrace:

0  swift                    0x000000010f47bfbb llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010f47c6fb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff96f6deaa _sigtramp + 26
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 1762206064
4  swift                    0x000000010d7817af emitTransformedFunctionValue(swift::Lowering::SILGenFunction&, swift::SILLocation, TranslationKind, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 1743
5  swift                    0x000000010d7810ab (anonymous namespace)::OrigToSubst::transformFunction(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::Lowering::TypeLowering const&) + 107
6  swift                    0x000000010d77c9aa (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::CanType, swift::Lowering::SGFContext) + 842
7  swift                    0x000000010d77c652 swift::Lowering::SILGenFunction::emitOrigToSubstValue(swift::SILLocation, swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::CanType, swift::Lowering::SGFContext) + 98
8  swift                    0x000000010d753edf swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 23647
9  swift                    0x000000010d74a846 swift::Lowering::SILGenFunction::emitRValue(swift::Expr*, swift::Lowering::SGFContext) + 22
10 swift                    0x000000010d78cf8a swift::Lowering::SILGenFunction::emitReturnExpr(swift::SILLocation, swift::Expr*) + 362
11 swift                    0x000000010d78acb4 swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 740
12 swift                    0x000000010d78ab2b swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 347
13 swift                    0x000000010d78a9c5 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
14 swift                    0x000000010d75c628 swift::Lowering::SILGenFunction::emitClosure(swift::AbstractClosureExpr*) + 216
15 swift                    0x000000010d715a54 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 212
16 swift                    0x000000010d755971 (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 97
17 swift                    0x000000010d74e39f swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 287
18 swift                    0x000000010d74d25f swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 47
19 swift                    0x000000010d70d834 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 340
20 swift                    0x000000010d70dcf8 swift::Lowering::ArgumentSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::Lowering::Initialization*, swift::Lowering::TypeLowering const&) && + 392
21 swift                    0x000000010d72b7b3 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1843
22 swift                    0x000000010d72bd25 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 261
23 swift                    0x000000010d72bb83 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2819
24 swift                    0x000000010d72cccd (anonymous namespace)::ArgEmitter::emitShuffle(swift::Expr*, swift::Expr*, llvm::ArrayRef<swift::TupleTypeElt>, swift::ConcreteDeclRef, llvm::ArrayRef<swift::Expr*>, llvm::ArrayRef<int>, llvm::ArrayRef<unsigned int>, swift::Type, swift::Lowering::AbstractionPattern) + 2445
25 swift                    0x000000010d72c2b5 (anonymous namespace)::ArgEmitter::emitExpanded(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 1685
26 swift                    0x000000010d72bb83 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 2819
27 swift                    0x000000010d72aacb (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<std::__1::pair<swift::Lowering::LValue, swift::SILLocation> >&, llvm::Optional<swift::ForeignErrorConvention> const&) && + 315
28 swift                    0x000000010d71f92a (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2730
29 swift                    0x000000010d71e67a swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 58
30 swift                    0x000000010d74e37d swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 253
31 swift                    0x000000010d74e454 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 468
32 swift                    0x000000010d74a797 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 263
33 swift                    0x000000010d73ef9e swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 174
34 swift                    0x000000010d73f09d swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 45
35 swift                    0x000000010d7175e1 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 209
36 swift                    0x000000010d717bdb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 779
37 swift                    0x000000010d718712 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 802
38 swift                    0x000000010d718ac6 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool, bool) + 38
39 swift                    0x000000010d56c8b5 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 11221
40 swift                    0x000000010d569ad3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2691
41 swift                    0x000000010d566154 main + 2324
42 libdyld.dylib            0x00007fff9d7a15ad start + 1
43 libdyld.dylib            0x000000000000000c start + 1652943456
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret 1.swift -target x86_64-apple-darwin15.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name main 
1.  While silgen closureexpr SIL function @_TF4mainU_FSSFSiT_ for expression at [1.swift:2:5 - line:7:5] RangeText="{
        (String) -> ((Int) -> Void) in
        return {

        }
    }"
2.  While emitting reabstraction thunk in SIL function @_TTRXFo__dT__XFo_dSi_dT__[1]    2332 segmentation fault  swift 1.swift
gottesmm commented 8 years ago

Can you post the back trace ad whether or not this happens with optimization?

swift-ci commented 8 years ago

Comment by huangguiyang (JIRA)

@gottesmm OK, the back trace is shown above.

gottesmm commented 8 years ago

Thanks!

slavapestov commented 7 years ago

Hmm:

(lldb) print srcTy.dump()
(function_type escaping
  (input=tuple_type num_elements=0)
  (output=tuple_type num_elements=0))
(lldb) print destTy.dump()
(function_type escaping
  (input=struct_type decl=Swift.(file).Int)
  (output=tuple_type num_elements=0))
slavapestov commented 7 years ago

This should not type check. The inner closure has the wrong type.

slavapestov commented 7 years ago

https://github.com/apple/swift/pull/6545