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-12885] Compiler crash involving Self-returning function #55332

Closed
bjhomer opened this issue May 26, 2020 · 4 comments
Closed

[SR-12885] Compiler crash involving Self-returning function #55332

bjhomer opened this issue May 26, 2020 · 4 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 optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@bjhomer
Copy link
Contributor

bjhomer commented May 26, 2020

Previous ID SR-12885
Radar None
Original Reporter @bjhomer
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)

Xcode 11.5

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

md5: 35d40c51dca59b8ead4d845e9d05c296

Issue Description:

The following code crashes the compiler in Xcode 11.5, but did not crash using Xcode 11.4.1. The crash only happens when compiling in release mode:

import Cocoa


class CrashyThing: NSViewController {
    @objc
    static func create() -> Self {
        let storyboard: NSStoryboard = NSStoryboard(name: "CrashyThing", bundle: nil)
        return storyboard.instantiateInitialController() as! Self
    }
}

The crash goes away if I use `CrashyThing` instead of `Self`

1.  Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
2.  While emitting IR SIL function "@$s13Compilercrash11CrashyThingC6createACXDyFZTf4d_n".
 for 'create()' (at /Users/bjhomer/Desktop/Compilercrash/Compilercrash/CrashyController.swift:14:5)
0  swift                    0x0000000106b704ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000106b6fcc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff735d45fd _sigtramp + 29
3  libsystem_platform.dylib 0x000000010834b080 _sigtramp + 2497145504
4  swift                    0x0000000102b489a6 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 566
5  swift                    0x0000000102b4c50b swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 219
6  swift                    0x000000010295d1a5 swift::irgen::emitCheckedCast(swift::irgen::IRGenFunction&, swift::irgen::Address, swift::CanType, swift::irgen::Address, swift::CanType, swift::CastConsumptionKind, swift::irgen::CheckedCastMode) + 277
7  swift                    0x0000000102afa6ae swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 286
8  swift                    0x0000000102af7053 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
9  swift                    0x00000001029ad336 swift::irgen::IRGenerator::emitLazyDefinitions() + 8790
10 swift                    0x0000000102ad329b swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 1979
11 swift                    0x00000001028cc9e1 performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 4129
12 swift                    0x00000001028c3b95 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
13 swift                    0x0000000102839b73 main + 1283
14 libdyld.dylib            0x00007fff733dbcc9 start + 1
error: Segmentation fault: 11 (in target 'Compilercrash' from project 'Compilercrash')
@theblixguy
Copy link
Collaborator

This doesn't crash for me on master. Could you try with a trunk and/or 5.3 snapshot?

@bjhomer
Copy link
Contributor Author

bjhomer commented May 26, 2020

Yeah, I'm not getting a crash on the 5.3 snapshot from May 19, so that probably means it's fixed.

@swift-ci
Copy link
Collaborator

swift-ci commented Jun 3, 2020

Comment by Maxim Krouk (JIRA)

(swift 5.2) Faced the same issue here

import SwiftUI

internal final class DropHanlder: DropDelegate {
    private var _performDrop: ((DropInfo) -> Bool)?
    public func performDrop(info: DropInfo) -> Bool { _performDrop?(info) ?? false }
    
    @discardableResult
    public func onDrop(perform action: ((DropInfo) -> Bool)?) -> Self {
        modification(of: self, \._performDrop, to: action)
    }
}

public func modification<Object, Value>(
    of object: Object,
    _ keyPath: WritableKeyPath<Object, Value>,
    to value: Value
) -> Object { modification(of: object) {  $0[keyPath: keyPath] = value } }

public func modification<Object>(
    of object: Object,
    transform: (inout Object) throws -> Void
) rethrows -> Object {
    var object = object
    try transform(&object)
    return object
}

with

@discardableResult func...-> Self

Works fine with

{code:swift} -> DropDelegate

instead of 
{code:swift} -> Self 

Or with

{code:swift} _performDrop = action; return self

instead of
{code:swift} modification(of: self, \._performDrop, to: action) 

Logs:

1.  Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
2.  While emitting IR SIL function "@$s6Athena11DropHanlderC12onValidation7performACXDSb7SwiftUI0B4InfoVcSg_tF".
 for 'onValidation(perform:)' (at /Users/maximkrouk/Develop/Swift/NEW/Athena/AthenaMacOS/AthenaMacOS/App/Intermodular/Helpers/DropHandler.swift:34:12)
0  swift                    0x000000010810d4ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010810ccc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff715a95fd _sigtramp + 29
3  libsystem_platform.dylib 0x0000000800000000 _sigtramp + 2393205280
4  swift                    0x0000000103fcdeb5 swift::irgen::IRGenModule::getAddrOfKeyPathPattern(swift::KeyPathPattern*, swift::SILLocation) + 3557
5  swift                    0x000000010409b98a swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 17402
6  swift                    0x0000000104094053 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
7  swift                    0x0000000103f47722 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1410
8  swift                    0x0000000104072649 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1097
9  swift                    0x0000000103e69a5f performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 4255
10 swift                    0x0000000103e5eeba swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48426
11 swift                    0x0000000103dd6b73 main + 1283
12 libdyld.dylib            0x00007fff713b0cc9 start + 1
error: Segmentation fault: 11 (in target 'Athena' from project 'AthenaMacOS')

@LucianoPAlmeida
Copy link
Collaborator

@theblixguy Since you and @bjhomer reported fixed on master, should this be resolved/closed? 🙂

@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 crash Bug: A crash, i.e., an abnormal termination of software optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

No branches or pull requests

5 participants