File tree Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Expand file tree Collapse file tree 4 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -742,19 +742,21 @@ extension Unsafe${Mutable}BufferPointer {
742
742
return try body ( . init( start: nil , count: 0 ) )
743
743
}
744
744
745
+ _debugPrecondition (
746
+ Int ( bitPattern: . init( base) ) & ( MemoryLayout < T > . alignment- 1 ) == 0 ,
747
+ " baseAddress must be a properly aligned pointer for types Element and T "
748
+ )
749
+
745
750
let newCount : Int
746
751
if MemoryLayout< T> . stride == MemoryLayout< Element> . stride {
747
752
newCount = count
748
- _debugPrecondition (
749
- MemoryLayout< T> . alignment == MemoryLayout< Element> . alignment
750
- )
751
753
} else {
752
754
newCount = count * MemoryLayout < Element > . stride / MemoryLayout < T > . stride
753
755
_debugPrecondition (
754
- Int ( bitPattern: . init( base) ) & ( MemoryLayout < T > . alignment- 1 ) == 0 &&
755
756
MemoryLayout < T > . stride > MemoryLayout< Element> . stride
756
757
? MemoryLayout< T> . stride % MemoryLayout < Element > . stride == 0
757
- : MemoryLayout < Element > . stride % MemoryLayout < T > . stride == 0
758
+ : MemoryLayout < Element > . stride % MemoryLayout < T > . stride == 0 ,
759
+ " Buffer must contain a whole number of Element instances "
758
760
)
759
761
}
760
762
let binding = Builtin . bindMemory ( base, newCount. _builtinWordValue, T . self)
Original file line number Diff line number Diff line change @@ -319,7 +319,10 @@ public struct UnsafePointer<Pointee>: _Pointer {
319
319
( MemoryLayout < Pointee > . stride > MemoryLayout< T> . stride
320
320
? MemoryLayout< Pointee> . stride % MemoryLayout < T > . stride == 0
321
321
: MemoryLayout < T > . stride % MemoryLayout < Pointee > . stride == 0
322
- ) ) )
322
+ )
323
+ ) ,
324
+ " self must be a properly aligned pointer for types Pointee and T "
325
+ )
323
326
let binding = Builtin . bindMemory ( _rawValue, count. _builtinWordValue, T . self)
324
327
defer { Builtin . rebindMemory ( _rawValue, binding) }
325
328
return try body ( . init( _rawValue) )
@@ -1026,7 +1029,10 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
1026
1029
( MemoryLayout < Pointee > . stride > MemoryLayout< T> . stride
1027
1030
? MemoryLayout< Pointee> . stride % MemoryLayout < T > . stride == 0
1028
1031
: MemoryLayout < T > . stride % MemoryLayout < Pointee > . stride == 0
1029
- ) ) )
1032
+ )
1033
+ ) ,
1034
+ " self must be a properly aligned pointer for types Pointee and T "
1035
+ )
1030
1036
let binding = Builtin . bindMemory ( _rawValue, count. _builtinWordValue, T . self)
1031
1037
defer { Builtin . rebindMemory ( _rawValue, binding) }
1032
1038
return try body ( . init( _rawValue) )
Original file line number Diff line number Diff line change @@ -866,7 +866,8 @@ extension Unsafe${Mutable}RawBufferPointer {
866
866
return try body ( . init( start: nil , count: 0 ) )
867
867
}
868
868
_debugPrecondition (
869
- Int ( bitPattern: s) & ( MemoryLayout < T > . alignment- 1 ) == 0
869
+ Int ( bitPattern: s) & ( MemoryLayout < T > . alignment- 1 ) == 0 ,
870
+ " baseAddress must be a properly aligned pointer for type T "
870
871
)
871
872
// initializer ensures _end is nil only when _position is nil.
872
873
_internalInvariant ( _end != nil )
Original file line number Diff line number Diff line change @@ -378,7 +378,8 @@ public struct UnsafeRawPointer: _Pointer {
378
378
_ body: ( _ pointer: UnsafePointer < T > ) throws -> Result
379
379
) rethrows -> Result {
380
380
_debugPrecondition (
381
- Int ( bitPattern: self ) & ( MemoryLayout < T > . alignment- 1 ) == 0
381
+ Int ( bitPattern: self ) & ( MemoryLayout < T > . alignment- 1 ) == 0 ,
382
+ " self must be a properly aligned pointer for type T "
382
383
)
383
384
let binding = Builtin . bindMemory ( _rawValue, count. _builtinWordValue, T . self)
384
385
defer { Builtin . rebindMemory ( _rawValue, binding) }
@@ -934,7 +935,8 @@ public struct UnsafeMutableRawPointer: _Pointer {
934
935
_ body: ( _ pointer: UnsafeMutablePointer < T > ) throws -> Result
935
936
) rethrows -> Result {
936
937
_debugPrecondition (
937
- Int ( bitPattern: self ) & ( MemoryLayout < T > . alignment- 1 ) == 0
938
+ Int ( bitPattern: self ) & ( MemoryLayout < T > . alignment- 1 ) == 0 ,
939
+ " self must be a properly aligned pointer for type T "
938
940
)
939
941
let binding = Builtin . bindMemory ( _rawValue, count. _builtinWordValue, T . self)
940
942
defer { Builtin . rebindMemory ( _rawValue, binding) }
You can’t perform that action at this time.
0 commit comments