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

Compiler crash assigning to local var from inside runAsyncAndBlock()

    XMLWordPrintable

    Details

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

      macOS 10.15
      Xcode 12.3
      swift-DEVELOPMENT-SNAPSHOT-2021-01-14-a
      Apple Swift version 5.4-dev (LLVM 4a2039285189ee5, Swift edcefe353246b16)

      Description

      This code reliably crashes the compiler on the current trunk snapshot:

      /// test.swift
      public func runAsyncAndBlockThrowing<R>(_ asyncFun: @escaping () async throws -> R) throws -> R {
          var result: Result<R, Error>? = nil
          runAsyncAndBlock {
              do {
                  result = .success(try await asyncFun())
              } catch {
                  result = .failure(error)
              }
          }
          return try result!.get()
      }
      

      Compiler invocation and output:

      $ swift -Xfrontend -enable-experimental-concurrency test.swift
      test.swift:5:13: warning: local var 'result' is unsafe to reference in code that may execute concurrently
                  result = .success(try await asyncFun())
                  ^
      test.swift:2:9: note: var declared here
          var result: Result<R, Error>? = nil
              ^
      test.swift:7:13: warning: local var 'result' is unsafe to reference in code that may execute concurrently
                  result = .failure(error)
                  ^
      test.swift:2:9: note: var declared here
          var result: Result<R, Error>? = nil
              ^
      Assertion failed: (llvm::isa<llvm::Argument>(Storage) && "arg expected to be load from inside %swift.context"), function visitDebugValueAddrInst, file /Users/buildnode/jenkins/workspace/oss-swift-package-macos/swift/lib/IRGen/IRGenSIL.cpp, line 4363.
      Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
      Stack dump:
      0.	Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2021-01-14-a.xctoolchain/usr/bin/swift-frontend -frontend -interpret test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -color-diagnostics -enable-experimental-concurrency -target-sdk-version 11.1 -module-name test
      1.	Apple Swift version 5.4-dev (LLVM 4a2039285189ee5, Swift edcefe353246b16)
      2.	While running user code "test.swift"
      3.	While evaluating request IRGenRequest(IR Generation for module test)
      4.	While emitting IR SIL function "@$s4test24runAsyncAndBlockThrowingyxxyYKcKlFyyYcfU_".
       for expression at [test.swift:3:22 - line:9:5] RangeText="{
              do {
                  result = .success(try await asyncFun())
              } catch {
                  result = .failure(error)
              }
          "
      0  swift-frontend           0x00000001144bac35 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
      1  swift-frontend           0x00000001144b9e95 llvm::sys::RunSignalHandlers() + 85
      2  swift-frontend           0x00000001144bb206 SignalHandler(int) + 262
      3  libsystem_platform.dylib 0x00007fff6b5ee5fd _sigtramp + 29
      4  libdyld.dylib            0x00007fff6b3f478f dyldGlobalLockRelease() + 0
      5  libsystem_c.dylib        0x00007fff6b4c4808 abort + 120
      6  libsystem_c.dylib        0x00007fff6b4c3ac6 err + 0
      7  swift-frontend           0x0000000114615943 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) (.cold.713) + 35
      8  swift-frontend           0x0000000110032eee swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 75150
      9  swift-frontend           0x000000011001c08f (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 7983
      10 swift-frontend           0x0000000110019c03 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1523
      11 swift-frontend           0x000000010fef47fb swift::irgen::IRGenerator::emitLazyDefinitions() + 1819
      12 swift-frontend           0x000000010ffde5e7 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2263
      13 swift-frontend           0x000000011001925d swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 157
      14 swift-frontend           0x000000011001917e swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 14
      15 swift-frontend           0x000000010ffea108 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 408
      16 swift-frontend           0x000000010ffdf7a0 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 576
      17 swift-frontend           0x000000010fd3d03d swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >&&) + 349
      18 swift-frontend           0x000000010fd05101 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1953
      19 swift-frontend           0x000000010fd0473c performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 636
      20 swift-frontend           0x000000010fcf937e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5214
      21 swift-frontend           0x000000010fc95642 main + 866
      22 libdyld.dylib            0x00007fff6b3f5cc9 start + 1
      23 libdyld.dylib            0x000000000000000d start + 18446603338716848965
      Abort trap: 6
      

        Attachments

          Activity

            People

            Assignee:
            aprantl Adrian Prantl
            Reporter:
            gwynne Gwynne Raskind
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: