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

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

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

swift-ci opened this issue Dec 12, 2020 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

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

Attachment: Download

Environment

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.

Points

  • 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/Xcode-12.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret EnumTest.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode-12.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -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)
@swift-ci
Copy link
Collaborator Author

Comment by Yuto Akiba (JIRA)

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

@swift-ci
Copy link
Collaborator Author

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

@typesanitizer
Copy link

@swift-ci create

@eeckstein
Copy link
Member

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 {

@eeckstein
Copy link
Member

cc @jckarter

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

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

@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
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 crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

5 participants