@@ -215,14 +215,14 @@ swap(i, j) = j
215
215
for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Complex{Int512}, Any)
216
216
r = Ref {TT} (10 )
217
217
GC. @preserve r begin
218
- (function (:: Type{TT} ) where TT
218
+ (@noinline function (:: Type{TT} ) where TT
219
219
p = Base. unsafe_convert (Ptr{TT}, r)
220
220
T (x) = convert (TT, x)
221
221
S = UInt32
222
222
if TT != = Any
223
223
@test_throws TypeError Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent )
224
- @test_throws TypeError Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent )
225
- @test_throws TypeError Core. Intrinsics. atomic_pointerreplace (p, T (100 ), S (2 ), :sequentially_consistent , :sequentially_consistent )
224
+ @test_throws TypeError Core. Intrinsics. atomic_pointerswap (p, S (2 ), :sequentially_consistent )
225
+ @test_throws TypeError Core. Intrinsics. atomic_pointerreplace (p, T (10 ), S (3 ), :sequentially_consistent , :sequentially_consistent )
226
226
end
227
227
@test Core. Intrinsics. pointerref (p, 1 , 1 ) === T (10 ) === r[]
228
228
if sizeof (r) > 8
@@ -235,7 +235,10 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
235
235
@test_throws ErrorException (" atomic_pointerreplace: invalid pointer for atomic operation" ) Core. Intrinsics. atomic_pointerreplace (p, S (100 ), T (2 ), :sequentially_consistent , :sequentially_consistent )
236
236
@test Core. Intrinsics. pointerref (p, 1 , 1 ) === T (10 ) === r[]
237
237
else
238
- TT != = Any && @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, swap, S (1 ), :sequentially_consistent )
238
+ if TT != = Any
239
+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, swap, S (4 ), :sequentially_consistent )
240
+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, Returns (S (5 )), T (10 ), :sequentially_consistent )
241
+ end
239
242
@test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (10 )
240
243
@test Core. Intrinsics. atomic_pointerset (p, T (1 ), :sequentially_consistent ) === p
241
244
@test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (1 )
@@ -249,10 +252,12 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
249
252
@test Core. Intrinsics. atomic_pointerswap (p, T (103 ), :sequentially_consistent ) === T (102 )
250
253
@test Core. Intrinsics. atomic_pointerreplace (p, S (100 ), T (2 ), :sequentially_consistent , :sequentially_consistent ) === ReplaceType {TT} ((T (103 ), false ))
251
254
@test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (103 )
255
+ @test Core. Intrinsics. atomic_pointermodify (p, Returns (T (105 )), nothing , :sequentially_consistent ) === Pair {TT,TT} (T (103 ), T (105 ))
256
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === T (105 )
252
257
end
253
258
if TT === Any
254
- @test Core. Intrinsics. atomic_pointermodify (p, swap, S (103 ), :sequentially_consistent ) === Pair {TT,TT} (T (103 ), S (103 ))
255
- @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === S (103 )
259
+ @test Core. Intrinsics. atomic_pointermodify (p, swap, S (105 ), :sequentially_consistent ) === Pair {TT,TT} (T (105 ), S (105 ))
260
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === S (105 )
256
261
@test Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent ) === p
257
262
@test Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent ) === S (1 )
258
263
@test Core. Intrinsics. atomic_pointerreplace (p, T (100 ), S (2 ), :sequentially_consistent , :sequentially_consistent ) === ReplaceType {TT} ((S (100 ), false ))
@@ -263,6 +268,37 @@ for TT in (Int8, Int16, Int32, Int64, Int128, Int256, Int512, Complex{Int32}, Co
263
268
end
264
269
end
265
270
271
+ for TT in (Ptr{Nothing}, Ptr)
272
+ r = Ref (nothing )
273
+ GC. @preserve r begin
274
+ p = Ref {TT} (Base. unsafe_convert (Ptr{Nothing}, r))
275
+ (@noinline function (p:: Ref )
276
+ p = p[]
277
+ S = UInt32
278
+ @test_throws TypeError Core. Intrinsics. atomic_pointerset (p, S (1 ), :sequentially_consistent )
279
+ @test_throws TypeError Core. Intrinsics. atomic_pointerswap (p, S (100 ), :sequentially_consistent )
280
+ @test_throws TypeError Core. Intrinsics. atomic_pointerreplace (p, nothing , S (2 ), :sequentially_consistent , :sequentially_consistent )
281
+ @test Core. Intrinsics. pointerref (p, 1 , 1 ) === nothing === r[]
282
+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, swap, S (1 ), :sequentially_consistent )
283
+ @test_throws TypeError Core. Intrinsics. atomic_pointermodify (p, Returns (S (1 )), nothing , :sequentially_consistent )
284
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
285
+ @test Core. Intrinsics. atomic_pointerset (p, nothing , :sequentially_consistent ) === p
286
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
287
+ @test Core. Intrinsics. atomic_pointerreplace (p, nothing , nothing , :sequentially_consistent , :sequentially_consistent ) === ReplaceType {Nothing} ((nothing , true ))
288
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
289
+ @test Core. Intrinsics. atomic_pointerreplace (p, S (1 ), nothing , :sequentially_consistent , :sequentially_consistent ) === ReplaceType {Nothing} ((nothing , false ))
290
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
291
+ @test Core. Intrinsics. atomic_pointermodify (p, Returns (nothing ), nothing , :sequentially_consistent ) === Pair {Nothing,Nothing} (nothing , nothing )
292
+ @test Core. Intrinsics. atomic_pointermodify (p, Returns (nothing ), S (1 ), :sequentially_consistent ) === Pair {Nothing,Nothing} (nothing , nothing )
293
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
294
+ @test Core. Intrinsics. atomic_pointerswap (p, nothing , :sequentially_consistent ) === nothing
295
+ @test Core. Intrinsics. atomic_pointerreplace (p, S (100 ), nothing , :sequentially_consistent , :sequentially_consistent ) === ReplaceType {Nothing} ((nothing , false ))
296
+ @test Core. Intrinsics. atomic_pointerref (p, :sequentially_consistent ) === nothing
297
+ end )(p,)
298
+ end
299
+ end
300
+
301
+
266
302
mutable struct IntWrap <: Signed
267
303
x:: Int
268
304
end
0 commit comments