[SR-15527] Crash with unused unowned reference to deinited object #57830
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
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
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:
Observed output:
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.)
The text was updated successfully, but these errors were encountered: