@@ -214,14 +214,14 @@ swap(i, j) = j
214
214
for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Complex{Int512}, Any)
215
215
r = Ref {TT} (10 )
216
216
GC. @preserve r begin
217
- (function (:: Type{TT} ) where TT
217
+ (@noinline function (:: Type{TT} ) where TT
218
218
p = Base. unsafe_convert (Ptr{TT}, r)
219
219
T (x) = convert (TT, x)
220
220
S = UInt32
221
221
if TT != = Any
222
222
@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 )
225
225
end
226
226
@test Core. Intrinsics. pointerref (p, 1 , 1 ) === T (10 ) === r[]
227
227
if sizeof (r) > 8
@@ -234,7 +234,10 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
234
234
@test_throws ErrorException (" atomic_pointerreplace: invalid pointer for atomic operation" ) Core. Intrinsics. atomic_pointerreplace (p, S (100 ), T (2 ), :sequentially_consistent , :sequentially_consistent )
235
235
@test Core. Intrinsics. pointerref (p, 1 , 1 ) === T (10 ) === r[]
236
236
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
238
241
@test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (10 )
239
242
@test Core. Intrinsics. atomic_pointerset (p, T (1 ), :sequentially_consistent ) === p
240
243
@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
248
251
@test Core. Intrinsics. atomic_pointerswap (p, T (103 ), :sequentially_consistent ) === T (102 )
249
252
@test Core. Intrinsics. atomic_pointerreplace (p, S (100 ), T (2 ), :sequentially_consistent , :sequentially_consistent ) === ReplaceType {TT} ((T (103 ), false ))
250
253
@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 )
251
256
end
252
257
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 )
255
260
@test Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent ) === p
256
261
@test Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent ) === S (1 )
257
262
@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
262
267
end
263
268
end
264
269
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
+
265
301
mutable struct IntWrap <: Signed
266
302
x:: Int
267
303
end
0 commit comments