Skip to content

Commit 2c65083

Browse files
aviateskKristofferC
authored andcommitted
fix atomic getfield with boundcheck on interpreter (#43602)
(cherry picked from commit 368a8f3)
1 parent 04f6a38 commit 2c65083

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
@@ -861,9 +861,9 @@ JL_CALLABLE(jl_f_getfield)
861861
enum jl_memory_order order = jl_memory_order_unspecified;
862862
JL_NARGS(getfield, 2, 4);
863863
if (nargs == 4) {
864-
JL_TYPECHK(getfield, symbol, args[3]);
865-
JL_TYPECHK(getfield, bool, args[4]);
866-
order = jl_get_atomic_order_checked((jl_sym_t*)args[3], 1, 0);
864+
JL_TYPECHK(getfield, symbol, args[2]);
865+
JL_TYPECHK(getfield, bool, args[3]);
866+
order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0);
867867
}
868868
else if (nargs == 3) {
869869
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)