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-12589] Segmentation Fault when compiling instance method call from protocol #55034

Closed
swift-ci opened this issue Apr 15, 2020 · 2 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

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
    ```
@swift-ci
Copy link
Collaborator Author

Comment by Ben Zhang (JIRA)

Just realized that the segfault happens even without the call:

```
import Foundation

protocol SomeProtocol {
func someMethod()
}

let _ = SomeProtocol.someMethod
```

Is this intended (unsupported) behaviour?

@hamishknight
Copy link
Collaborator

This has been fixed on master by #28698 please verify using the latest development snapshot from https://swift.org/download/#snapshots.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

2 participants