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-9566] Conditional Conformance Crash on type casting #52013

Open
swift-ci opened this issue Dec 22, 2018 · 2 comments
Open

[SR-9566] Conditional Conformance Crash on type casting #52013

swift-ci opened this issue Dec 22, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution runtime The Swift Runtime standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9566
Radar None
Original Reporter k-o-d-e-n (JIRA User)
Type Bug
Environment

Xcode 10.1 (10B61)

Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, RunTimeCrash, Runtime
Assignee None
Priority Medium

md5: 7542aad37ab17588adf8a5268320eb15

Issue Description:

I have a similar code in my project.

/// playground
protocol RealtimeValue {}
protocol WritableRealtimeValue: RealtimeValue {}
protocol ChangeableRealtimeValue: RealtimeValue {}
protocol RealtimeCollection: RealtimeValue {}

class _RealtimeValue: RealtimeValue {}


class Object: _RealtimeValue {}


class __RepresentableCollection<Element: RealtimeValue, Ref: RealtimeValue>: _RealtimeValue, RealtimeCollection {}
extension __RepresentableCollection: WritableRealtimeValue where Ref: WritableRealtimeValue {}


struct RCItem: WritableRealtimeValue {}


class References<Element: RealtimeValue>: __RepresentableCollection<Element, RCItem> {}


let _references: _RealtimeValue = __RepresentableCollection<Object, RCItem>()
/// uncomment and crash won't be
//_references as? WritableRealtimeValue


let references: _RealtimeValue = References<Object>()
references as? WritableRealtimeValue // crash

The same happened in regular Xcode project with disabled optimizations.
Crash description:

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.


* thread #&#8203;1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #&#8203;0: 0x000000011ac1b3aa libswiftCore.dylib`swift_getObjCClassMetadata + 26
    frame #&#8203;1: 0x000000011ac2ddd9 libswiftCore.dylib`searchInConformanceCache(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 57
    frame #&#8203;2: 0x000000011ac2d908 libswiftCore.dylib`swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 56
    frame #&#8203;3: 0x000000011ac0c3a6 libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 38
    frame #&#8203;4: 0x000000011ac2d250 libswiftCore.dylib`swift::_checkGenericRequirements(llvm::ArrayRef<swift::TargetGenericRequirementDescriptor<swift::InProcess> >, std::__1::vector<void const*, std::__1::allocator<void const*> >&, llvm::function_ref<swift::TargetMetadata<swift::InProcess> const* (unsigned int)>, llvm::function_ref<swift::TargetMetadata<swift::InProcess> const* (unsigned int, unsigned int)>) + 416
    frame #&#8203;5: 0x000000011ac2d044 libswiftCore.dylib`swift::TargetProtocolConformanceDescriptor<swift::InProcess>::getWitnessTable(swift::TargetMetadata<swift::InProcess> const*) const + 244
    frame #&#8203;6: 0x000000011ac2e088 libswiftCore.dylib`swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*)::$_3::operator()(swift::TargetProtocolConformanceDescriptor<swift::InProcess> const&, swift::TargetMetadata<swift::InProcess> const*) const + 232
    frame #&#8203;7: 0x000000011ac2db19 libswiftCore.dylib`swift_conformsToProtocolImpl(swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*) + 585
    frame #&#8203;8: 0x000000011ac0c3a6 libswiftCore.dylib`swift::_conformsToProtocol(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetProtocolDescriptor<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 38
    frame #&#8203;9: 0x000000011ac120d5 libswiftCore.dylib`_conformsToProtocols(swift::OpaqueValue const*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::TargetWitnessTable<swift::InProcess> const**) + 213
    frame #&#8203;10: 0x000000011ac10dc6 libswiftCore.dylib`_dynamicCastToExistential(swift::OpaqueValue*, swift::OpaqueValue*, swift::TargetMetadata<swift::InProcess> const*, swift::TargetExistentialTypeMetadata<swift::InProcess> const*, swift::DynamicCastFlags) + 422
    frame #&#8203;11: 0x000000011dcb621a $__lldb_expr94`main at Untitled Page 2.xcplaygroundpage:26
    frame #&#8203;12: 0x0000000104e705f0 Whats-New-In-Swift-4-2`linkResources + 304
    frame #&#8203;13: 0x00000001066ea62c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    frame #&#8203;14: 0x00000001066e9de0 CoreFoundation`__CFRunLoopDoBlocks + 336
    frame #&#8203;15: 0x00000001066e4654 CoreFoundation`__CFRunLoopRun + 1284
    frame #&#8203;16: 0x00000001066e3e11 CoreFoundation`CFRunLoopRunSpecific + 625
    frame #&#8203;17: 0x000000010b0dd1dd GraphicsServices`GSEventRunModal + 62
    frame #&#8203;18: 0x000000010bbb381d UIKitCore`UIApplicationMain + 140
    frame #&#8203;19: 0x0000000104e706bd Whats-New-In-Swift-4-2`main + 205
    frame #&#8203;20: 0x000000010810d575 libdyld.dylib`start + 1
    frame #&#8203;21: 0x000000010810d575 libdyld.dylib`start + 1
@belkadan
Copy link
Contributor

belkadan commented Jan 7, 2019

@rjmccall, @jckarter, any idea what's going on?

@swift-ci
Copy link
Collaborator Author

swift-ci commented Apr 9, 2019

Comment by Leonard Stellbrink (JIRA)

Experiences the same with Swift 4.2.

Generic classes that get extended by a protocol with conditional conformance seem to be the reason here.

Casting a object to the protocol will not crash it but when calling a function on the casted object even after making sure that the object is conform to the protocol via a guarded cast will crash at runtime.

@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
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. crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution runtime The Swift Runtime standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants