Skip to content

[SR-12589] Segmentation Fault when compiling instance method call from protocol #55034

@swift-ci

Description

@swift-ci
Previous ID SR-12589
Radar None
Original Reporter ben-z (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

> swift --version
Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0

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

md5: bee9a80b85986a4d2ed9df54dfaf1571

duplicates:

  • SR-75 Referencing a protocol function crashes the compiler

Issue Description:

I'm getting a segmentation fault when I try to compile code that includes an instance call using protocol methods (not sure how to properly word this). Consider this example:
{{
import Foundation

protocol SomeProtocol {
func someMethod()
}

class SomeClass: SomeProtocol {
func someMethod() {
print("hello")
}
}

let a = SomeClass()
SomeProtocol.someMethod(a)()
}}

Compiling this results in a segfault:

```
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret test.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test

  1. Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29)
    0 swift 0x000000010f6e54ea PrintStackTraceSignalHandler(void*) + 42
    1 swift 0x000000010f6e4cc0 SignalHandler(int) + 352
    2 libsystem_platform.dylib 0x00007fff6ba155fd _sigtramp + 29
    3 libsystem_platform.dylib 0x0000000000800000 _sigtramp + 2497620512
    4 swift 0x000000010b8cea8a swift::Lowering::SILGenFunction::emitOpenExistentialExprImpl(swift::OpenExistentialExpr*, llvm::function_ref<void (swift::Expr*)>) + 666
    5 swift 0x000000010b8bfc2a swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 38938
    6 swift 0x000000010b86df63 (anonymous namespace)::SILGenApply::visitExpr(swift::Expr*) + 51
    7 swift 0x000000010b863304 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 196
    8 swift 0x000000010b8d0297 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 823
    9 swift 0x000000010b856a5b swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1227
    10 swift 0x000000010b8557ac swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1356
    11 swift 0x000000010b85788a swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 1530
    12 swift 0x000000010b4393cb swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55595
    13 swift 0x000000010b3af4d3 main + 1283
    14 libdyld.dylib 0x00007fff6b81ccc9 start + 1
    15 libdyld.dylib 0x000000000000000b start + 2491298627
    [1] 13168 segmentation fault swift test.swift
    ```

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions