Skip to content

Commit 71258c4

Browse files
committed
[stdlib] add failure explanations to debug preconditions
addresses rdar://128543858
1 parent 66e3110 commit 71258c4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,10 @@ extension UnsafeRawPointer {
517517
fromByteOffset offset: Int = 0,
518518
as type: T.Type
519519
) -> T {
520-
_debugPrecondition(_isPOD(T.self))
520+
_debugPrecondition(
521+
_isPOD(T.self),
522+
"loadUnaligned only supports loading BitwiseCopyable types."
523+
)
521524
return _withUnprotectedUnsafeTemporaryAllocation(of: T.self, capacity: 1) {
522525
let temporary = $0.baseAddress._unsafelyUnwrappedUnchecked
523526
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
@@ -1351,7 +1354,10 @@ extension UnsafeMutableRawPointer {
13511354
fromByteOffset offset: Int = 0,
13521355
as type: T.Type
13531356
) -> T {
1354-
_debugPrecondition(_isPOD(T.self))
1357+
_debugPrecondition(
1358+
_isPOD(T.self),
1359+
"loadUnaligned only supports loading BitwiseCopyable types."
1360+
)
13551361
return _withUnprotectedUnsafeTemporaryAllocation(of: T.self, capacity: 1) {
13561362
let temporary = $0.baseAddress._unsafelyUnwrappedUnchecked
13571363
Builtin.int_memcpy_RawPointer_RawPointer_Int64(
@@ -1456,7 +1462,10 @@ extension UnsafeMutableRawPointer {
14561462
public func storeBytes<T>(
14571463
of value: T, toByteOffset offset: Int = 0, as type: T.Type
14581464
) {
1459-
_debugPrecondition(_isPOD(T.self))
1465+
_debugPrecondition(
1466+
_isPOD(T.self),
1467+
"storeBytes only supports storing the bytes of BitwiseCopyable types."
1468+
)
14601469

14611470
#if $TypedThrows
14621471
withUnsafePointer(to: value) { source in

0 commit comments

Comments
 (0)