Skip to content

Commit c7eff33

Browse files
committed
cgutils: fix write barrier of atomic-setonce
Thanks to PermutationGroups.jl for dog-fooding our typos! This now matches the runtime implementation in datatype.c (setonce_bits) and ensures that we properly compute the success bit. The test that was intended to check for this is now written to inline that struct and thus actually test for this (undef fields are not eligible for inlining). Fix #59883
1 parent f8c7b22 commit c7eff33

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/cgutils.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2676,9 +2676,11 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
26762676
assert(!isboxed && maybe_null_if_boxed);
26772677
Value *first_ptr = extract_first_ptr(ctx, realinstr);
26782678
assert(first_ptr != nullptr);
2679-
Done = ctx.builder.CreateIsNotNull(first_ptr);
2679+
// Done = Success || first_ptr != NULL
2680+
Done = ctx.builder.CreateOr(Success, ctx.builder.CreateIsNotNull(first_ptr));
26802681
}
26812682
else {
2683+
// Done = Success || first_ptr == NULL || oldval == cmpop)
26822684
// Done = !(!Success && (first_ptr != NULL && oldval == cmpop))
26832685
Done = emit_guarded_test(ctx, ctx.builder.CreateNot(Success), false, [&] {
26842686
Value *first_ptr = nullptr;

test/atomics.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,8 @@ swap(x, y) = y
5757
struct UndefComplex{T}
5858
re::T
5959
im::T
60-
UndefComplex{T}() where {T} = new{T}()
6160
end
62-
Base.convert(T::Type{<:UndefComplex}, S) = T()
61+
Base.convert(T::Type{<:UndefComplex}, S) = T(S, 0)
6362

6463
let T1 = Refxy{NTuple{3,UInt8}},
6564
T2 = ARefxy{NTuple{3,UInt8}}

0 commit comments

Comments
 (0)