Skip to content

Commit

Permalink
Change 'unsafeDowncast' to 'as!' (#186)
Browse files Browse the repository at this point in the history
Motivation:

The 'unsafeDowncast' can cause a miscompile leading to unexpected
runtime behaviour.

Modifications:

- Use 'as!' instead

Result:

No miscompiles on 5.10
  • Loading branch information
glbrntt authored Jul 24, 2024
1 parent d58e6bf commit 24c800f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/ConcurrencyHelpers/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
let buffer = Self.create(minimumCapacity: 1) { _ in
return value
}
let storage = unsafeDowncast(buffer, to: Self.self)
// Avoid 'unsafeDowncast' as there is a miscompilation on 5.10.
let storage = buffer as! Self

storage.withUnsafeMutablePointers { _, lockPtr in
LockOperations.create(lockPtr)
Expand Down

0 comments on commit 24c800f

Please sign in to comment.