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

crash with array of C++ objects exposed via SWIFT_SHARED_REFERENCE #72827

Closed
wtholliday opened this issue Apr 4, 2024 · 3 comments · Fixed by #73615
Closed

crash with array of C++ objects exposed via SWIFT_SHARED_REFERENCE #72827

wtholliday opened this issue Apr 4, 2024 · 3 comments · Fixed by #73615
Assignees
Labels
Array Area → standard library: The `Array` type bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution swift 5.10

Comments

@wtholliday
Copy link

Description

Exposed a C++ struct via SWIFT_SHARED_REFERENCE. Works when outside an array. When added to an array, crashes when array is deallocated. Please use attached project.

CompilerCrash.zip

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
    frame #0: 0x000000018466c6b4 libobjc.A.dylib`objc_release + 16
    frame #1: 0x0000000194a8ecf8 libswiftCore.dylib`swift_arrayDestroy + 196
    frame #2: 0x0000000194798cd8 libswiftCore.dylib`Swift._ContiguousArrayStorage.__deallocating_deinit + 96
    frame #3: 0x0000000194aa91a0 libswiftCore.dylib`_swift_release_dealloc + 56
    frame #4: 0x0000000194aa9cf8 libswiftCore.dylib`bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1>>::doDecrementSlow<(swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) + 136
  * frame #5: 0x000000010037a95c CompilerCrash`CompilerCrashApp.init() at CompilerCrashApp.swift:29:5

Reproduction

let thing = SharedThing.create()
let array = [thing]
#include <swift/bridging>

struct SharedThing {
    static SharedThing* _Nonnull create();
} SWIFT_SHARED_REFERENCE(retainSharedThing, releaseSharedThing);

void retainSharedThing(SharedThing * _Nonnull);
void releaseSharedThing(SharedThing * _Nonnull);

Expected behavior

Does not crash

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@wtholliday wtholliday added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Apr 4, 2024
@wtholliday
Copy link
Author

Simpler repro:

CompilerCrash.zip

@MaxDesiatov
Copy link
Member

cc @egorzhdan

@egorzhdan egorzhdan self-assigned this Apr 4, 2024
@hborla hborla added c++ interop Feature: Interoperability with C++ and removed triage needed This issue needs more specific labels labels Apr 27, 2024
@egorzhdan
Copy link
Collaborator

This was fixed in #73615.
Thanks @wtholliday for a small reproducer!

@AnthonyLatsis AnthonyLatsis added c++ to swift Feature → c++ interop: c++ to swift run-time crash Bug → crash: Swift code crashed during execution crash Bug: A crash, i.e., an abnormal termination of software Array Area → standard library: The `Array` type compiler The Swift compiler in itself swift 5.10 labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Array Area → standard library: The `Array` type bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ c++ to swift Feature → c++ interop: c++ to swift compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution swift 5.10
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants