swift
swift copied to clipboard
Swift 6.0.0.4.52 Double deinit called for non-copyable type crossing module boundary
Description
A double call to deinit is made for the same instance under very specific conditions:
- Release configuration must be used
- The instance is non-copyable (
~Copyable
) - The init method must be generic over the argument (
_ scalars: some Collection<Float>
) - The init method must use the argument (
for _ in zip(0..<15, scalars.indices) {}
- The init method muts be
@inlinable
- The call site must be in a separate module
- The call site must call from a generic closure
Reproduction
> rm -rf .build; swift build -c release && ./.build/release/clitool
Building for production...
(warnings...)
[7/7] Linking clitool
Build complete! (2.55s)
Init Optional(0x0000600002e18440), refCount 1
Init Optional(0x0000600002e184c0), refCount 1
Deinit Optional(0x0000600002e184c0), refCount 0
Init Optional(0x0000600002e184c0), refCount 1
Deinit Optional(0x0000600002e184c0), refCount 0
Deinit Optional(0x0000600002e18440), refCount 0
Deinit Optional(0x0000600002e18440), refCount -1
DeinitNonCopyableLib/SomeNonCopyable.swift:24: Fatal error: Over freed
[1] 19457 trace trap ./.build/release/clitool
Expected behavior
No double freeing of non-copyable types
Environment
swiftc -version swift-driver version: 1.110 Apple Swift version 6.0 (swiftlang-6.0.0.4.52 clang-1600.0.21.1.3) Target: arm64-apple-macosx14.0
Additional information
No response