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.

(cherry picked from commit 28c49ce)
  • Loading branch information
vtjnash authored and KristofferC committed Nov 26, 2021
1 parent 5dba096 commit fa51d23
Show file tree
Hide file tree
Showing 3 changed files with 11 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 @@ -693,7 +693,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 @@ -238,7 +238,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
10 changes: 9 additions & 1 deletion test/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ end
@test_intrinsic Core.Intrinsics.fptoui UInt Float16(3.3) UInt(3)
end

@test Core.Intrinsics.atomic_fence(:sequentially_consistent) === nothing
@test_throws ConcurrencyViolationError("invalid atomic ordering") (Core.Intrinsics.atomic_fence(:u)) === nothing
@test_throws ConcurrencyViolationError("invalid atomic ordering") (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 (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 fa51d23

Please sign in to comment.