Uploaded image for project: 'Swift'
  1. Swift
  2. SR-10345

Compiler crash on invalid closure syntax

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Duplicate
    • Component/s: Compiler
    • Labels:
      None

      Description

      This crashes if you try to compile it with swiftc:

      protocol TestProtocol {
          func protocolFunction()
      }
      
      struct Implementation: TestProtocol {
          func protocolFunction() {
              // no-op
          }
      }
      
      let instanceInArray = [Implementation()]
      
      // If this line is included, compiler crashes.
      let result = instanceInArray.compactMap(TestProtocol.protocolFunction)
      // This line works and is what I was trying to write.
      // let result = instanceInArray.compactMap({ $0.protocolFunction() })
      // Just for comparison, this line doesn't crash.
      // let result = instanceInArray.compactMap(Implementation.protocolFunction)

      Crashes without any options to swiftc:

      $ swiftc tmp.swift
      Stack dump:
      0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file tmp.swift -target x86_64-apple-darwin18.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name tmp -o /var/folders/zd/_60zyhdn6ps0fy8mvtbrkjg80000gq/T/tmp-0c9751.o
      0  swift                    0x000000010ef29ee3 PrintStackTraceSignalHandler(void*) + 51
      1  swift                    0x000000010ef296bc SignalHandler(int) + 348
      2  libsystem_platform.dylib 0x00007fff6b7bcb3d _sigtramp + 29
      3  swift                    0x000000010c2d08d6 swift::GenericFunctionType::get(swift::GenericSignature*, llvm::ArrayRef<swift::AnyFunctionType::Param>, swift::Type, swift::AnyFunctionType::ExtInfo) + 278
      4  swift                    0x000000010b95ba80 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 39344
      5  swift                    0x000000010b9527c8 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 1784
      6  swift                    0x000000010b9535d2 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 5378
      7  swift                    0x000000010b968c69 void llvm::function_ref<void (swift::Expr*)>::callback_fn<swift::Lowering::RValue swift::Lowering::SILGenFunction::emitOpenExistentialExpr<swift::Lowering::RValue, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16>(swift::OpenExistentialExpr*, (anonymous namespace)::RValueEmitter::visitOpenExistentialExpr(swift::OpenExistentialExpr*, swift::Lowering::SGFContext)::$_16)::'lambda'(swift::Expr*)>(long, swift::Expr*) + 41
      8  swift                    0x000000010b9690cb swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 1003
      9  swift                    0x000000010b959dfb swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 32043
      10 swift                    0x000000010b95b09f swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 36815
      11 swift                    0x000000010b8c88d3 swift::Lowering::ArgumentSource::getAsSingleValue(swift::Lowering::SILGenFunction&, swift::Lowering::SGFContext) && + 547
      12 swift                    0x000000010b94020d swift::Lowering::SILGenFunction::emitConvertedRValue(swift::SILLocation, swift::Lowering::Conversion const&, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SILGenFunction&, swift::SILLocation, swift::Lowering::SGFContext)>) + 429
      13 swift                    0x000000010b8ef4a9 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 5753
      14 swift                    0x000000010b900b99 (anonymous namespace)::ArgEmitter::emitTopLevel(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern) + 937
      15 swift                    0x000000010b90059a (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus) && + 714
      16 swift                    0x000000010b8fd8bb (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1467
      17 swift                    0x000000010b8fb2b8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2792
      18 swift                    0x000000010b8f73db swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 2331
      19 swift                    0x000000010b951ef3 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, llvm::Optional<swift::SILLocation>) + 131
      20 swift                    0x000000010b94598c swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 268
      21 swift                    0x000000010b8e52dd swift::ASTVisitor<swift::Lowering::SILGenFunction, void, void, void, void, void, void>::visit(swift::Decl*) + 141
      22 swift                    0x000000010b8e797e swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1070
      23 swift                    0x000000010b8e6776 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1206
      24 swift                    0x000000010b8e858c swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1228
      25 swift                    0x000000010ad8954a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 30106
      26 swift                    0x000000010ad7e6de swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
      27 swift                    0x000000010ad1c7be main + 1246
      28 libdyld.dylib            0x00007fff6b5d1ed9 start + 1
      29 libdyld.dylib            0x000000000000000f start + 2493702455
      <unknown>:0: error: unable to execute command: Segmentation fault: 11
      <unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
      

      swiftc version info:

      $ swiftc -v
      Apple Swift version 5.0 (swiftlang-1001.0.69.5 clang-1001.0.46.3)
      Target: x86_64-apple-darwin18.2.0
      

      The crash stack trace looks similar to SR-10343, but this crash can be reproduced without the optimization flag -O.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ansonj Anson Jablinski
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: