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-13961] Compiler crash possibly related to enum and protocol #56358

swift-ci opened this issue Dec 12, 2020 · 6 comments

[SR-13961] Compiler crash possibly related to enum and protocol #56358

swift-ci opened this issue Dec 12, 2020 · 6 comments


Copy link

@swift-ci swift-ci commented Dec 12, 2020

Previous ID SR-13961
Radar rdar://problem/72302307
Original Reporter touyu (JIRA User)
Type Bug

Attachment: Download


Xcode 12.1 (12A7403)

Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: e37cdbb66dace69bb314bc90bc324f53

Issue Description:

Crash when running the following code.


  • Implement functionB with Associated value of enum.

  • Crash only when the argument of functionB is an array.

import Foundation

protocol ProtocolA {
    associatedtype B: ProtocolB

protocol ProtocolB {
    static func functionB(_: [Int]) -> Self

extension ProtocolA {
    func functionA() -> B {
        return .functionB([0])

class ObjectA: ProtocolA {
    enum B: ProtocolB {
        case functionB([Int])

let _ = ObjectA().functionA()

Crash Logs

$ swift EnumTest.swift

Stack dump:
0.      Program arguments: /Applications/ -frontend -interpret EnumTest.swift -enable-objc-interop -stack-check -sdk /Applications/ -color-diagnostics -target-sdk-version 10.15.6 -module-name EnumTest 
1.      Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2.      While running user code "EnumTest.swift"
0  swift                    0x00000001119ff865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001119fe865 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001119ffe1f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff6b02f5fd _sigtramp + 29
4  libsystem_platform.dylib 0x00007ffee2736280 _sigtramp + 18446744071418440864
5  libsystem_platform.dylib 0x0000000116c3104f _sigtramp + 18446603343397657199
6  swift                    0x000000010d5be5ff llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::Optional<llvm::StringRef>) + 2495
7  swift                    0x000000010d59b9fb 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> >&&) + 6747
8  swift                    0x000000010d576b2a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2426
9  swift                    0x000000010d566b10 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 21152
10 swift                    0x000000010d4e7c37 main + 1255
11 libdyld.dylib            0x00007fff6ae36cc9 start + 1
12 libdyld.dylib            0x000000000000000d start + 18446603338722874181
fish: 'swift EnumTest.swift' terminated by signal SIGSEGV (Address boundary error)
Copy link
Collaborator Author

@swift-ci swift-ci commented Dec 14, 2020

Comment by Yuto Akiba (JIRA)

I don't know if I can, but I'll try to investigate this issue myself.

Copy link
Collaborator Author

@swift-ci swift-ci commented Dec 14, 2020

Comment by Yuto Akiba (JIRA)

I got the following output when debugging with RelWithDebInfo.

Assertion failed: (getStrongExtraRefCount() >= dec && "releasing reference whose refcount is already zero"), function decrementStrongExtraRefCount

Copy link

@typesanitizer typesanitizer commented Dec 14, 2020

@swift-ci create

Copy link

@eeckstein eeckstein commented Jan 13, 2021

The problem is in SILGen: ProtocolA.functionA() calls the witness method ProtocolB.functionB with a "guaranteed" parameter:

  %17 = witness_method $Self.B, #ProtocolB.functionB : <Self where Self : ProtocolB> (Self.Type) -> ([Int]) -> Self : $@convention(witness_method: ProtocolB) <τ_0_0 where τ_0_0 : ProtocolB> (@guaranteed Array<Int>, @thick τ_0_0.Type) -> @out τ_0_0 // user: %18
  %18 = apply %17<Self.B>(%0, %16, %3) : $@convention(witness_method: ProtocolB) <τ_0_0 where τ_0_0 : ProtocolB> (@guaranteed Array<Int>, @thick τ_0_0.Type) -> @out τ_0_0

whereas the conforming method takes the parameter as "owned".

// protocol witness for static ProtocolB.functionB(_:) in conformance ObjectA.B
sil private [transparent] [thunk] [ossa] @$s4test7ObjectAC1BOAA9ProtocolBA2aFP9functionByxSaySiGFZTW : $@convention(witness_method: ProtocolB) (@owned Array<Int>, @thick ObjectA.B.Type) -> @out ObjectA.B {

Copy link

@eeckstein eeckstein commented Jan 13, 2021

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Copy link

@stackotter stackotter commented Apr 26, 2022

It seems like this issue has been fixed in Swift 5.6, should it be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

4 participants