@@ -214,14 +214,14 @@ swap(i, j) = j
214214for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Complex{Int512}, Any)
215215 r = Ref {TT} (10 )
216216 GC. @preserve r begin
217- (function (:: Type{TT} ) where TT
217+ (@noinline function (:: Type{TT} ) where TT
218218 p = Base. unsafe_convert (Ptr{TT}, r)
219219 T (x) = convert (TT, x)
220220 S = UInt32
221221 if TT != = Any
222222 @test_throws TypeError Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent )
223- @test_throws TypeError Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent )
224- @test_throws TypeError Core. Intrinsics. atomic_pointerreplace (p, T (100 ), S (2 ), :sequentially_consistent , :sequentially_consistent )
223+ @test_throws TypeError Core. Intrinsics. atomic_pointerswap (p, S (2 ), :sequentially_consistent )
224+ @test_throws TypeError Core. Intrinsics. atomic_pointerreplace (p, T (10 ), S (3 ), :sequentially_consistent , :sequentially_consistent )
225225 end
226226 @test Core. Intrinsics. pointerref (p, 1 , 1 ) === T (10 ) === r[]
227227 if sizeof (r) > 8
@@ -234,7 +234,10 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
234234 @test_throws ErrorException (" atomic_pointerreplace: invalid pointer for atomic operation" ) Core. Intrinsics. atomic_pointerreplace (p, S (100 ), T (2 ), :sequentially_consistent , :sequentially_consistent )
235235 @test Core. Intrinsics. pointerref (p, 1 , 1 ) === T (10 ) === r[]
236236 else
237- TT != = Any && @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, swap, S (1 ), :sequentially_consistent )
237+ if TT != = Any
238+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, swap, S (4 ), :sequentially_consistent )
239+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, Returns (S (5 )), T (10 ), :sequentially_consistent )
240+ end
238241 @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (10 )
239242 @test Core. Intrinsics. atomic_pointerset (p, T (1 ), :sequentially_consistent ) === p
240243 @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (1 )
@@ -248,10 +251,12 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
248251 @test Core. Intrinsics. atomic_pointerswap (p, T (103 ), :sequentially_consistent ) === T (102 )
249252 @test Core. Intrinsics. atomic_pointerreplace (p, S (100 ), T (2 ), :sequentially_consistent , :sequentially_consistent ) === ReplaceType {TT} ((T (103 ), false ))
250253 @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (103 )
254+ @test Core. Intrinsics. atomic_pointermodify (p, Returns (T (105 )), nothing , :sequentially_consistent ) === Pair {TT,TT} (T (103 ), T (105 ))
255+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (105 )
251256 end
252257 if TT === Any
253- @test Core. Intrinsics. atomic_pointermodify (p, swap, S (103 ), :sequentially_consistent ) === Pair {TT,TT} (T (103 ), S (103 ))
254- @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === S (103 )
258+ @test Core. Intrinsics. atomic_pointermodify (p, swap, S (105 ), :sequentially_consistent ) === Pair {TT,TT} (T (105 ), S (105 ))
259+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === S (105 )
255260 @test Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent ) === p
256261 @test Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent ) === S (1 )
257262 @test Core. Intrinsics. atomic_pointerreplace (p, T (100 ), S (2 ), :sequentially_consistent , :sequentially_consistent ) === ReplaceType {TT} ((S (100 ), false ))
@@ -262,6 +267,37 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
262267 end
263268end
264269
270+ for TT in (Ptr{Nothing}, Ptr)
271+ r = Ref (nothing )
272+ GC. @preserve r begin
273+ p = Ref {TT} (Base. unsafe_convert (Ptr{Nothing}, r))
274+ (@noinline function (p:: Ref )
275+ p = p[]
276+ S = UInt32
277+ @test_throws TypeError Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent )
278+ @test_throws TypeError Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent )
279+ @test_throws TypeError Core. Intrinsics. atomic_pointerreplace (p, nothing , S (2 ), :sequentially_consistent , :sequentially_consistent )
280+ @test Core. Intrinsics. pointerref (p, 1 , 1 ) === nothing === r[]
281+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, swap, S (1 ), :sequentially_consistent )
282+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, Returns (S (1 )), nothing , :sequentially_consistent )
283+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
284+ @test Core. Intrinsics. atomic_pointerset (p, nothing , :sequentially_consistent ) === p
285+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
286+ @test Core. Intrinsics. atomic_pointerreplace (p, nothing , nothing , :sequentially_consistent , :sequentially_consistent ) === ReplaceType {Nothing} ((nothing , true ))
287+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
288+ @test Core. Intrinsics. atomic_pointerreplace (p, S (1 ), nothing , :sequentially_consistent , :sequentially_consistent ) === ReplaceType {Nothing} ((nothing , false ))
289+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
290+ @test Core. Intrinsics. atomic_pointermodify (p, Returns (nothing ), nothing , :sequentially_consistent ) === Pair {Nothing,Nothing} (nothing , nothing )
291+ @test Core. Intrinsics. atomic_pointermodify (p, Returns (nothing ), S (1 ), :sequentially_consistent ) === Pair {Nothing,Nothing} (nothing , nothing )
292+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
293+ @test Core. Intrinsics. atomic_pointerswap (p, nothing , :sequentially_consistent ) === nothing
294+ @test Core. Intrinsics. atomic_pointerreplace (p, S (100 ), nothing , :sequentially_consistent , :sequentially_consistent ) === ReplaceType {Nothing} ((nothing , false ))
295+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
296+ end )(p,)
297+ end
298+ end
299+
300+
265301mutable struct IntWrap <: Signed
266302 x:: Int
267303end
0 commit comments