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-15527] Crash with unused unowned reference to deinited object #57830

Closed
RonAvitzur opened this issue Nov 26, 2021 · 2 comments
Closed

[SR-15527] Crash with unused unowned reference to deinited object #57830

RonAvitzur opened this issue Nov 26, 2021 · 2 comments
Labels
ARC Feature: automatic reference counting 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 run-time crash Bug → crash: Swift code crashed during execution SILOptimizer Area → compiler: SIL optimization passes

Comments

@RonAvitzur
Copy link

RonAvitzur commented Nov 26, 2021

Previous ID SR-15527
Radar rdar://problem/85772200
Original Reporter @RonAvitzur
Type Improvement
Status Resolved
Resolution Done

Attachment: Download

Environment

macOS 11.6, Xcode 13.1, Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6) & Apple Swift version 5.6-dev (LLVM 27222cde774bd6b, Swift 17f1cf9) I

Additional Detail from JIRA
Votes 0
Component/s swift
Labels Improvement
Assignee d066z (JIRA)
Priority Medium

md5: 6bec9221537d92e8ea919c53d666030d

Issue Description:

I’m seeing a crash when releasing an object containing an unowned reference to an already-release object.

In the sample code attached, the unowned reference: unowned var parent? = nil is set to self in setArgParents, where self is guaranteed to be valid. parent is never read or otherwise used by the sample code anywhere.

Is the mere existence of an unowned reference not allowed? Or is only not allowed to use it after the referenced object is deinited?

Notes:
Compiling the project in debug mode will not crash.
Compiling the project in release mode with Disable Safety Checks to Yes will not crash.
Using the development snapshot toolchain Apple Swift version 5.6-dev (LLVM 27222cde774bd6b, Swift 17f1cf9) I see the crash regardless of Disable Safety Checks settings.
Manually setting the child node’s parent to nil before removing the last strong reference to child node in flatten avoids the crash, also, in the ifdef’d out version of flatten()

(Apple feedback reported to FB9782558)

Expected output:

(vector(X,1),vector((Y,2),1))
vector((X,Y,2),(1,1))

Observed output:

(vector(X,1),vector((Y,2),1))
UnownedReferenceCrash(4984,0x1000d3d40) malloc: Non-aligned pointer 0x16fdff2d8 being freed

Additional discussion can be found at https://forums.swift.org/t/trying-to-understand-an-unowned-reference-crash/53704 (I’ve included everything I think relevant here in the bug report.)

@dnadoba
Copy link
Member

dnadoba commented Nov 26, 2021

@swift-ci create

@eeckstein
Copy link
Member

Fixed in #40325

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. run-time crash Bug → crash: Swift code crashed during execution compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software SILOptimizer Area → compiler: SIL optimization passes ARC Feature: automatic reference counting and removed improvement swift labels Jan 16, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARC Feature: automatic reference counting 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 run-time crash Bug → crash: Swift code crashed during execution SILOptimizer Area → compiler: SIL optimization passes
Projects
None yet
Development

No branches or pull requests

4 participants