Skip to content

Commit 24c800f

Browse files
authored
Change 'unsafeDowncast' to 'as!' (#186)
Motivation: The 'unsafeDowncast' can cause a miscompile leading to unexpected runtime behaviour. Modifications: - Use 'as!' instead Result: No miscompiles on 5.10
1 parent d58e6bf commit 24c800f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Sources/ConcurrencyHelpers/Lock.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
136136
let buffer = Self.create(minimumCapacity: 1) { _ in
137137
return value
138138
}
139-
let storage = unsafeDowncast(buffer, to: Self.self)
139+
// Avoid 'unsafeDowncast' as there is a miscompilation on 5.10.
140+
let storage = buffer as! Self
140141

141142
storage.withUnsafeMutablePointers { _, lockPtr in
142143
LockOperations.create(lockPtr)

0 commit comments

Comments
 (0)