Skip to content

Commit 7e0172f

Browse files
committed
fix atomic getfield with boundcheck on interpreter
1 parent 754ce5d commit 7e0172f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/builtins.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,9 @@ JL_CALLABLE(jl_f_getfield)
867867
enum jl_memory_order order = jl_memory_order_unspecified;
868868
JL_NARGS(getfield, 2, 4);
869869
if (nargs == 4) {
870-
JL_TYPECHK(getfield, symbol, args[3]);
871-
JL_TYPECHK(getfield, bool, args[4]);
872-
order = jl_get_atomic_order_checked((jl_sym_t*)args[3], 1, 0);
870+
JL_TYPECHK(getfield, symbol, args[2]);
871+
JL_TYPECHK(getfield, bool, args[3]);
872+
order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0);
873873
}
874874
else if (nargs == 3) {
875875
if (!jl_is_bool(args[2])) {

test/atomics.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,14 @@ let a = ARefxy(1, -1)
370370
@test_throws ConcurrencyViolationError @atomicreplace :not_atomic a.x xchg
371371
@test_throws ConcurrencyViolationError @atomicreplace :monotonic :acquire a.x xchg
372372
end
373+
374+
# atomic getfield with boundcheck
375+
# via codegen
376+
getx(a, boundcheck) = getfield(a, :x, :sequentially_consistent, boundcheck)
377+
@test getx(ARefxy{Any}(42, 42), true) == 42
378+
@test getx(ARefxy{Any}(42, 42), false) == 42
379+
# via interpreter
380+
ans = getfield(ARefxy{Any}(42, 42), :x, :sequentially_consistent, true)
381+
@test ans == 42
382+
ans = getfield(ARefxy{Any}(42, 42), :x, :sequentially_consistent, false)
383+
@test ans == 42

0 commit comments

Comments
 (0)