From 24c800fb494fbee6e42bc156dc94232dc08971af Mon Sep 17 00:00:00 2001 From: George Barnett Date: Wed, 24 Jul 2024 14:47:26 +0100 Subject: [PATCH] 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 --- Sources/ConcurrencyHelpers/Lock.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/ConcurrencyHelpers/Lock.swift b/Sources/ConcurrencyHelpers/Lock.swift index c3e3686..272a749 100644 --- a/Sources/ConcurrencyHelpers/Lock.swift +++ b/Sources/ConcurrencyHelpers/Lock.swift @@ -136,7 +136,8 @@ final class LockStorage: ManagedBuffer { 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)