From f7fdcac11a30ea0a794bb54a0cb00e13ad77536d Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 14 Jul 2021 15:30:31 -0400 Subject: [PATCH] atomics: disable unordered RMW ordering This is not a particularly meaningful combination (LLVM dislikes it). --- src/builtins.c | 2 +- test/atomics.jl | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index 7ef93faaa6368..4ef5d5ac5c2df 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -812,7 +812,7 @@ enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char sto { if (order == not_atomic_sym) return jl_memory_order_notatomic; - if (order == unordered_sym && (loading || storing)) + if (order == unordered_sym && (loading ^ storing)) return jl_memory_order_unordered; if (order == monotonic_sym && (loading || storing)) return jl_memory_order_monotonic; diff --git a/test/atomics.jl b/test/atomics.jl index e4202b5ce1aea..4c32fc12d87ed 100644 --- a/test/atomics.jl +++ b/test/atomics.jl @@ -184,7 +184,7 @@ test_field_operators(ARefxy{Float64}(123_10, 123_20)) @test getfield(r, :y) === x @test_throws ConcurrencyViolationError("invalid atomic ordering") swapfield!(r, :y, y, :u) - @test_throws ConcurrencyViolationError("swapfield!: non-atomic field cannot be written atomically") swapfield!(r, :y, y, :unordered) + @test_throws ConcurrencyViolationError("invalid atomic ordering") swapfield!(r, :y, y, :unordered) @test_throws ConcurrencyViolationError("swapfield!: non-atomic field cannot be written atomically") swapfield!(r, :y, y, :monotonic) @test_throws ConcurrencyViolationError("swapfield!: non-atomic field cannot be written atomically") swapfield!(r, :y, y, :acquire) @test_throws ConcurrencyViolationError("swapfield!: non-atomic field cannot be written atomically") swapfield!(r, :y, y, :release) @@ -193,7 +193,7 @@ test_field_operators(ARefxy{Float64}(123_10, 123_20)) @test swapfield!(r, :y, y, :not_atomic) === x @test_throws ConcurrencyViolationError("invalid atomic ordering") modifyfield!(r, :y, swap, y, :u) - @test_throws ConcurrencyViolationError("modifyfield!: non-atomic field cannot be written atomically") modifyfield!(r, :y, swap, y, :unordered) + @test_throws ConcurrencyViolationError("invalid atomic ordering") modifyfield!(r, :y, swap, y, :unordered) @test_throws ConcurrencyViolationError("modifyfield!: non-atomic field cannot be written atomically") modifyfield!(r, :y, swap, y, :monotonic) @test_throws ConcurrencyViolationError("modifyfield!: non-atomic field cannot be written atomically") modifyfield!(r, :y, swap, y, :acquire) @test_throws ConcurrencyViolationError("modifyfield!: non-atomic field cannot be written atomically") modifyfield!(r, :y, swap, y, :release) @@ -202,7 +202,7 @@ test_field_operators(ARefxy{Float64}(123_10, 123_20)) @test modifyfield!(r, :y, swap, x, :not_atomic) === (y, x) @test_throws ConcurrencyViolationError("invalid atomic ordering") replacefield!(r, :y, y, y, :u, :not_atomic) - @test_throws ConcurrencyViolationError("replacefield!: non-atomic field cannot be written atomically") replacefield!(r, :y, y, y, :unordered, :not_atomic) + @test_throws ConcurrencyViolationError("invalid atomic ordering") replacefield!(r, :y, y, y, :unordered, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: non-atomic field cannot be written atomically") replacefield!(r, :y, y, y, :monotonic, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: non-atomic field cannot be written atomically") replacefield!(r, :y, y, y, :acquire, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: non-atomic field cannot be written atomically") replacefield!(r, :y, y, y, :release, :not_atomic) @@ -223,8 +223,8 @@ test_field_operators(ARefxy{Float64}(123_10, 123_20)) @test_throws ConcurrencyViolationError("invalid atomic ordering") swapfield!(r, :x, x, :u) @test_throws ConcurrencyViolationError("swapfield!: atomic field cannot be written non-atomically") swapfield!(r, :x, x, :not_atomic) @test_throws ConcurrencyViolationError("swapfield!: atomic field cannot be written non-atomically") swapfield!(r, :x, x) - @test swapfield!(r, :x, x, :unordered) === y - @test swapfield!(r, :x, x, :monotonic) === x + @test_throws ConcurrencyViolationError("invalid atomic ordering") swapfield!(r, :x, x, :unordered) === y + @test swapfield!(r, :x, x, :monotonic) === y @test swapfield!(r, :x, x, :acquire) === x @test swapfield!(r, :x, x, :release) === x @test swapfield!(r, :x, x, :acquire_release) === x @@ -233,7 +233,7 @@ test_field_operators(ARefxy{Float64}(123_10, 123_20)) @test_throws ConcurrencyViolationError("invalid atomic ordering") modifyfield!(r, :x, swap, x, :u) @test_throws ConcurrencyViolationError("modifyfield!: atomic field cannot be written non-atomically") modifyfield!(r, :x, swap, x, :not_atomic) @test_throws ConcurrencyViolationError("modifyfield!: atomic field cannot be written non-atomically") modifyfield!(r, :x, swap, x) - @test modifyfield!(r, :x, swap, x, :unordered) === (x, x) + @test_throws ConcurrencyViolationError("invalid atomic ordering") modifyfield!(r, :x, swap, x, :unordered) @test modifyfield!(r, :x, swap, x, :monotonic) === (x, x) @test modifyfield!(r, :x, swap, x, :acquire) === (x, x) @test modifyfield!(r, :x, swap, x, :release) === (x, x) @@ -243,7 +243,7 @@ test_field_operators(ARefxy{Float64}(123_10, 123_20)) @test_throws ConcurrencyViolationError("invalid atomic ordering") replacefield!(r, :x, x, x, :u, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: atomic field cannot be written non-atomically") replacefield!(r, :x, x, x) @test_throws ConcurrencyViolationError("replacefield!: atomic field cannot be written non-atomically") replacefield!(r, :x, y, x, :not_atomic, :not_atomic) - @test_throws ConcurrencyViolationError("replacefield!: atomic field cannot be accessed non-atomically") replacefield!(r, :x, x, x, :unordered, :not_atomic) + @test_throws ConcurrencyViolationError("invalid atomic ordering") replacefield!(r, :x, x, x, :unordered, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: atomic field cannot be accessed non-atomically") replacefield!(r, :x, x, x, :monotonic, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: atomic field cannot be accessed non-atomically") replacefield!(r, :x, x, x, :acquire, :not_atomic) @test_throws ConcurrencyViolationError("replacefield!: atomic field cannot be accessed non-atomically") replacefield!(r, :x, x, x, :release, :not_atomic) @@ -288,21 +288,21 @@ end Base.convert(T::Type{<:UndefComplex}, S) = T() @noinline function _test_field_undef(r) r = r[] - T = fieldtype(typeof(r), :x) - x = convert(T, 12345_10) + TT = fieldtype(typeof(r), :x) + x = convert(TT, 12345_10) @test_throws UndefRefError getfield(r, :x) @test_throws UndefRefError getfield(r, :x, :sequentially_consistent) @test_throws UndefRefError modifyfield!(r, :x, add, 1, :sequentially_consistent) - @test_throws (T === Any ? UndefRefError : TypeError) replacefield!(r, :x, 1, 1.0, :sequentially_consistent) + @test_throws (TT === Any ? UndefRefError : TypeError) replacefield!(r, :x, 1, 1.0, :sequentially_consistent) @test_throws UndefRefError replacefield!(r, :x, 1, x, :sequentially_consistent) @test_throws UndefRefError getfield(r, :x, :sequentially_consistent) @test_throws UndefRefError swapfield!(r, :x, x, :sequentially_consistent) @test getfield(r, :x, :sequentially_consistent) === x === getfield(r, :x) nothing end -@noinline function test_field_undef(T) - _test_field_undef(Ref(T())) - _test_field_undef(Ref{Any}(T())) +@noinline function test_field_undef(TT) + _test_field_undef(Ref(TT())) + _test_field_undef(Ref{Any}(TT())) nothing end test_field_undef(ARefxy{BigInt})