Skip to content

Commit

Permalink
fix atomic fences (#43093)
Browse files Browse the repository at this point in the history
Previously, we were disallowing the opposite of the orders that we intended to disallow.
  • Loading branch information
vtjnash authored Nov 16, 2021
1 parent 4b99bc8 commit 28c49ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ static jl_cgval_t emit_atomicfence(jl_codectx_t &ctx, jl_cgval_t *argv)
{
const jl_cgval_t &ord = argv[0];
if (ord.constant && jl_is_symbol(ord.constant)) {
enum jl_memory_order order = jl_get_atomic_order((jl_sym_t*)ord.constant, false, false);
enum jl_memory_order order = jl_get_atomic_order((jl_sym_t*)ord.constant, true, true);
if (order == jl_memory_order_invalid) {
emit_atomic_error(ctx, "invalid atomic ordering");
return jl_cgval_t(); // unreachable
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ JL_DLLEXPORT jl_value_t *jl_atomic_pointerreplace(jl_value_t *p, jl_value_t *exp
JL_DLLEXPORT jl_value_t *jl_atomic_fence(jl_value_t *order_sym)
{
JL_TYPECHK(fence, symbol, order_sym);
enum jl_memory_order order = jl_get_atomic_order_checked((jl_sym_t*)order_sym, 0, 0);
enum jl_memory_order order = jl_get_atomic_order_checked((jl_sym_t*)order_sym, 1, 1);
if (order > jl_memory_order_monotonic)
jl_fence();
return jl_nothing;
Expand Down
11 changes: 10 additions & 1 deletion test/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,17 @@ end
@test_intrinsic Core.Intrinsics.fptoui UInt Float16(3.3) UInt(3)
end

@test Core.Intrinsics.atomic_fence(:sequentially_consistent) === nothing
using Base.Experimental: @force_compile
@test_throws ConcurrencyViolationError("invalid atomic ordering") (@force_compile; Core.Intrinsics.atomic_fence(:u)) === nothing
@test_throws ConcurrencyViolationError("invalid atomic ordering") (@force_compile; Core.Intrinsics.atomic_fence(Symbol("u", "x"))) === nothing
@test_throws ConcurrencyViolationError("invalid atomic ordering") Core.Intrinsics.atomic_fence(Symbol("u", "x")) === nothing
for order in (:not_atomic, :monotonic, :acquire, :release, :acquire_release, :sequentially_consistent)
@test Core.Intrinsics.atomic_fence(order) === nothing
@test (order -> Core.Intrinsics.atomic_fence(order))(order) === nothing
@test Base.invokelatest(@eval () -> Core.Intrinsics.atomic_fence($(QuoteNode(order)))) === nothing
end
@test Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent) == nothing
@test (@force_compile; Core.Intrinsics.atomic_pointerref(C_NULL, :sequentially_consistent)) == nothing

primitive type Int256 <: Signed 256 end
Int256(i::Int) = Core.Intrinsics.sext_int(Int256, i)
Expand Down

0 comments on commit 28c49ce

Please sign in to comment.