From 368a8f3b9bc5a3e95eea01969182c4047290e8a5 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> Date: Thu, 6 Jan 2022 04:31:52 +0900 Subject: [PATCH] fix atomic `getfield` with boundcheck on interpreter (#43602) --- src/builtins.c | 6 +++--- test/atomics.jl | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/builtins.c b/src/builtins.c index 54df354f7172b..900a3c44dc4ec 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -867,9 +867,9 @@ JL_CALLABLE(jl_f_getfield) enum jl_memory_order order = jl_memory_order_unspecified; JL_NARGS(getfield, 2, 4); if (nargs == 4) { - JL_TYPECHK(getfield, symbol, args[3]); - JL_TYPECHK(getfield, bool, args[4]); - order = jl_get_atomic_order_checked((jl_sym_t*)args[3], 1, 0); + JL_TYPECHK(getfield, symbol, args[2]); + JL_TYPECHK(getfield, bool, args[3]); + order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0); } else if (nargs == 3) { if (!jl_is_bool(args[2])) { diff --git a/test/atomics.jl b/test/atomics.jl index c53471ed0da26..15ffd84a2c0a2 100644 --- a/test/atomics.jl +++ b/test/atomics.jl @@ -370,3 +370,14 @@ let a = ARefxy(1, -1) @test_throws ConcurrencyViolationError @atomicreplace :not_atomic a.x xchg @test_throws ConcurrencyViolationError @atomicreplace :monotonic :acquire a.x xchg end + +# atomic getfield with boundcheck +# via codegen +getx(a, boundcheck) = getfield(a, :x, :sequentially_consistent, boundcheck) +@test getx(ARefxy{Any}(42, 42), true) == 42 +@test getx(ARefxy{Any}(42, 42), false) == 42 +# via interpreter +ans = getfield(ARefxy{Any}(42, 42), :x, :sequentially_consistent, true) +@test ans == 42 +ans = getfield(ARefxy{Any}(42, 42), :x, :sequentially_consistent, false) +@test ans == 42