@@ -137,6 +137,35 @@ UnsafeMutableRawPointerExtraTestSuite.test("load.invalid.mutable")
137137 expectUnreachable ( )
138138}
139139
140+ UnsafeMutableRawPointerExtraTestSuite . test ( " store.unaligned " )
141+ . skip ( . custom( {
142+ if #available( SwiftStdlib 5 . 7 , * ) { return false }
143+ return true
144+ } , reason: " Requires Swift 5.7's stdlib " ) )
145+ . code {
146+ let count = MemoryLayout < UInt > . stride * 2
147+ let p1 = UnsafeMutableRawPointer . allocate (
148+ byteCount: count,
149+ alignment: MemoryLayout< UInt> . alignment
150+ )
151+ defer { p1. deallocate ( ) }
152+ Array ( repeating: UInt8 . zero, count: count) . withUnsafeBufferPointer {
153+ p1. copyBytes ( from: UnsafeRawPointer ( $0. baseAddress!) , count: $0. count)
154+ }
155+ let value = UInt . max
156+ let offset = 3
157+ p1. storeBytes ( of: value, toByteOffset: offset, as: UInt . self)
158+ expectEqual ( p1. load ( fromByteOffset: offset- 1 , as: UInt8 . self) ,
159+ 0 )
160+ expectEqual ( p1. load ( fromByteOffset: offset, as: UInt8 . self) ,
161+ . max)
162+ let storedLength = MemoryLayout< UInt> . size
163+ expectEqual ( p1. load ( fromByteOffset: offset- 1 + storedLength, as: UInt8 . self) ,
164+ . max)
165+ expectEqual ( p1. load ( fromByteOffset: offset+ storedLength, as: UInt8 . self) ,
166+ 0 )
167+ }
168+
140169UnsafeMutableRawPointerExtraTestSuite . test ( " store.invalid " )
141170. skip ( . custom( { !_isDebugAssertConfiguration( ) } ,
142171 reason: " This tests a debug precondition.. " ) )
0 commit comments