From d7117298f51000668cc99d1c81684e5d357230a7 Mon Sep 17 00:00:00 2001 From: Cody Tapscott Date: Thu, 6 Jun 2024 15:38:43 -0400 Subject: [PATCH] codegen: fix unsoundness in `globalop` NULL check This code had not considered "mutation tearing", so the emitted operations could be incorrect if any mutations were dropped. --- src/codegen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 3f1c714f9b30a..1f2ab7cccd2c9 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3228,7 +3228,7 @@ static jl_cgval_t emit_globalop(jl_codectx_t &ctx, jl_module_t *mod, jl_sym_t *s return jl_cgval_t(); } bool isboxed = true; - bool maybe_null = jl_atomic_load_relaxed(&bnd->value) == NULL; + bool maybe_null = (!bnd->isdefined && !bnd->constp) || (jl_atomic_load_relaxed(&bnd->value) == NULL); return typed_store(ctx, julia_binding_pvalue(ctx, bp), rval, cmp, ty,