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

SILGen crash on overloading functions which take varargs & arrays

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Compiler
    • Environment:

      Swift 2.2 targeting OS X.
      Swift main branch in lldb.

      Description

      An overloaded function where one instance takes an array and the other varargs will crash in SILGen.

      class Foo {
          func a(arr: Int..., n: String) { }
          func a(arr: [Int], n: String) { }
      }
      

      The stack trace from the REPL:

      * thread #1: tid = 0xb9705d, 0x00007fff8ab47f06 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
        * frame #0: 0x00007fff8ab47f06 libsystem_kernel.dylib`__pthread_kill + 10
          frame #1: 0x00007fff885c54ec libsystem_pthread.dylib`pthread_kill + 90
          frame #2: 0x00000001059da51b swift`::raise(sig=6) + 27 at Signals.inc:421
          frame #3: 0x00000001059da5d2 swift`::abort() + 18 at Signals.inc:438
          frame #4: 0x00000001059da5b1 swift`::__assert_rtn(func="preEmitFunction", file="/Users/JoeWillsher/Developer/SWIFT/swift/lib/SILGen/SILGen.cpp", line=484, expr="F->empty() && \"already emitted function?!\"") + 129 at Signals.inc:434
          frame #5: 0x00000001005b53e7 swift`void swift::Lowering::SILGenModule::preEmitFunction<swift::FuncDecl>(this=0x00007fff5fbf5a70, constant=SILDeclRef @ 0x00007fff5fbf4b40, astNode=0x000000010e123af0, F=0x0000000113000338, Loc=SILLocation @ 0x00007fff5fbf4b60) + 215 at SILGen.cpp:484
          frame #6: 0x00000001005a67fc swift`swift::Lowering::SILGenModule::emitFunction(this=0x00007fff5fbf53a0, f=0x0000000113000338)::$_1::operator()(swift::SILFunction*) const + 204 at SILGen.cpp:573
          frame #7: 0x000000010059f695 swift`void emitOrDelayFunction<swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1>(SGM=0x00007fff5fbf5a70, constant=SILDeclRef @ 0x00007fff5fbf5288, emitter=0x00007fff5fbf53a0)::$_1&&) + 853 at SILGen.cpp:472
          frame #8: 0x000000010059e8b5 swift`swift::Lowering::SILGenModule::emitFunction(this=0x00007fff5fbf5a70, fd=0x000000010e123af0) + 245 at SILGen.cpp:572
          frame #9: 0x000000010071dcb9 swift`SILGenExtension::visitFuncDecl(this=0x00007fff5fbf55c8, fd=0x000000010e123af0) + 73 at SILGenType.cpp:465
          frame #10: 0x000000010071d6ac swift`swift::ASTVisitor<SILGenExtension, void, void, void, void, void, void>::visit(this=0x00007fff5fbf55c8, D=0x000000010e123af0) + 620 at DeclNodes.def:127
          frame #11: 0x000000010071cde5 swift`SILGenExtension::emitExtension(this=0x00007fff5fbf55c8, e=0x000000010e1237b0) + 181 at SILGenType.cpp:437
          frame #12: 0x000000010071a72d swift`swift::Lowering::SILGenModule::visitExtensionDecl(this=0x00007fff5fbf5a70, ed=0x000000010e1237b0) + 45 at SILGenType.cpp:512
          frame #13: 0x00000001005b6bc4 swift`swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(this=0x00007fff5fbf5a70, D=0x000000010e1237b0) + 116 at DeclNodes.def:90
          frame #14: 0x00000001005a439c swift`swift::Lowering::SILGenModule::emitSourceFile(this=0x00007fff5fbf5a70, sf=0x000000010e0b0c00, startElem=1) + 220 at SILGen.cpp:1285
          frame #15: 0x00000001005a47bb swift`swift::SILModule::constructSIL(mod=0x000000010e011530, options=0x00007fff5fbfd1b0, SF=0x000000010e0b0c00, startElem=Optional<unsigned int> @ 0x00007fff5fbf5de0, makeModuleFragile=false, isWholeModule=false) + 907 at SILGen.cpp:1314
          frame #16: 0x00000001005a5107 swift`swift::performSILGeneration(sf=0x000000010e0b0c00, options=0x00007fff5fbfd1b0, startElem=Optional<unsigned int> @ 0x00007fff5fbf6060, makeModuleFragile=false) + 135 at SILGen.cpp:1378
          frame #17: 0x0000000100b0d69d swift`REPLEnvironment::executeSwiftSource(this=0x00007fff5fbf7cb0, Line=(Data = "extension Foo { func a(arr: [Int], n: String) { } }\n", Length = 52), CmdLine=size=9) + 1149 at REPL.cpp:830
          frame #18: 0x0000000100b067c8 swift`REPLEnvironment::handleREPLInput(this=0x00007fff5fbf7cb0, inputKind=SourceCode, Line=(Data = "extension Foo { func a(arr: [Int], n: String) { } }\n", Length = 52))::REPLInputKind, llvm::StringRef) + 9432 at REPL.cpp:1151
          frame #19: 0x0000000100b03c0f swift`swift::runREPL(CI=0x00007fff5fbfcd48, CmdLine=size=9, ParseStdlib=false) + 303 at REPL.cpp:1176
          frame #20: 0x00000001000271e8 swift`performCompile(Instance=0x00007fff5fbfcd48, Invocation=0x00007fff5fbfc6b0, Args=ArrayRef<const char *> @ 0x00007fff5fbf9160, ReturnValue=0x00007fff5fbfaf64) + 4008 at frontend_main.cpp:678
          frame #21: 0x0000000100025994 swift`frontend_main(Args=ArrayRef<const char *> @ 0x00007fff5fbfb248, Argv0="/Users/JoeWillsher/Developer/SWIFT/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift", MainAddr=0x000000010000cb70) + 12676 at frontend_main.cpp:1126
          frame #22: 0x000000010000dc37 swift`main(argc_=11, argv_=0x00007fff5fbff9c8) + 4231 at driver.cpp:158
          frame #23: 0x00007fff9657a5ad libdyld.dylib`start + 1
          frame #24: 0x00007fff9657a5ad libdyld.dylib`start + 1
      

      This compiles if there is no param after the vararg/array, or if the overloaded functions are free functions.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              eeckstein Erik Eckstein
              Reporter:
              joewillsher Josef Willsher
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: