Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14059] Compiler crash assigning to local var from inside runAsyncAndBlock() #56448

Closed
gwynne opened this issue Jan 16, 2021 · 3 comments
Closed
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features crash Bug: A crash, i.e., an abnormal termination of software

Comments

@gwynne
Copy link
Contributor

gwynne commented Jan 16, 2021

Previous ID SR-14059
Radar rdar://problem/73358988
Original Reporter @gwynne
Type Bug
Status Resolved
Resolution Done
Environment

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

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, Concurrency
Assignee @adrian-prantl
Priority Medium

md5: 4f55411f9cbb0650b8582cf5018a924c

Issue 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
@typesanitizer
Copy link

@swift-ci create

@adrian-prantl
Copy link
Member

See #35444

@adrian-prantl
Copy link
Member

FIxed in #35444

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

4 participants