@@ -10,13 +10,18 @@ function check_default_ordering(T::Type)
1010 xs = T[rand (T), rand (T)]
1111 x1 = rand (T)
1212 x2 = rand (T)
13+ check_default_ordering (xs, x1, x2)
14+ end
15+
16+ function check_default_ordering (xs:: AbstractArray{T} , x1:: T , x2:: T ) where T
1317 @debug " xs=$(repr (xs)) x1=$(repr (x1)) x2=$(repr (x2)) "
1418
1519 ptr = llvmptr (xs, 1 )
1620 GC. @preserve xs begin
1721 @test UnsafeAtomics. load (ptr) === xs[1 ]
1822 UnsafeAtomics. store! (ptr, x1)
1923 @test xs[1 ] === x1
24+ sizeof (T) == 0 && return # CAS hangs on zero sized data...
2025 desired = (old = x1, success = true )
2126 @test UnsafeAtomics. cas! (ptr, x1, x2) === (old = x1, success = true )
2227 @test xs[1 ] === x2
@@ -37,6 +42,10 @@ function test_explicit_ordering(T::Type = UInt)
3742 xs = T[rand (T), rand (T)]
3843 x1 = rand (T)
3944 x2 = rand (T)
45+ test_explicit_ordering (xs, x1, x2)
46+ end
47+
48+ function test_explicit_ordering (xs:: AbstractArray{T} , x1:: T , x2:: T ) where T
4049 @debug " xs=$(repr (xs)) x1=$(repr (x1)) x2=$(repr (x2)) "
4150
4251 ptr = llvmptr (xs, 1 )
@@ -45,6 +54,7 @@ function test_explicit_ordering(T::Type = UInt)
4554 @test UnsafeAtomics. load (ptr, acquire) === xs[1 ]
4655 UnsafeAtomics. store! (ptr, x1, release)
4756 @test xs[1 ] === x1
57+ sizeof (T) == 0 && return # CAS hangs on zero sized data...
4858 desired = (old = x1, success = true )
4959 @test UnsafeAtomics. cas! (ptr, x1, x2, acq_rel, acquire) === desired
5060 @test xs[1 ] === x2
@@ -74,9 +84,16 @@ function test_explicit_ordering(T::Type = UInt)
7484 end
7585end
7686
87+
7788@testset " UnsafeAtomicsLLVM" begin
7889 @testset for T in inttypes
7990 check_default_ordering (T)
8091 test_explicit_ordering (T)
8192 end
93+
94+ @testset " Zero-sized types" begin
95+ @test sizeof (Nothing) == 0
96+ check_default_ordering ([nothing , nothing ], nothing , nothing )
97+ test_explicit_ordering ([nothing , nothing ], nothing , nothing )
98+ end
8299end
0 commit comments