diff --git a/src/cgutils.cpp b/src/cgutils.cpp index bd1470c2503f1..1bb7fba070d0c 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -2722,12 +2722,14 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg ConstantInt::get(T_size, jl_field_offset(sty, i) + jl_field_size(sty, i) - 1)))); } } - bool need_wb = false; // TODO: verify that nargs <= nf (currently handled by front-end) for (size_t i = 0; i < nargs; i++) { const jl_cgval_t &rhs = argv[i]; - if (jl_field_isptr(sty, i) && !rhs.isboxed) - need_wb = true; + bool need_wb; // set to true if the store might cause the allocation of a box newer than the struct + if (jl_field_isptr(sty, i)) + need_wb = !rhs.isboxed; + else + need_wb = false; emit_typecheck(ctx, rhs, jl_svecref(sty->types, i), "new"); emit_setfield(ctx, sty, strctinfo, i, rhs, false, need_wb); } diff --git a/src/gc.c b/src/gc.c index 4f28af0e12734..48645b66c95d1 100644 --- a/src/gc.c +++ b/src/gc.c @@ -2334,7 +2334,7 @@ mark: { } goto pop; } - if (!flags.ptrarray || a->data == NULL) + if (!flags.ptrarray || a->data == NULL || jl_array_len(a) == 0) goto pop; size_t l = jl_array_len(a); uintptr_t nptr = (l << 2) | (bits & GC_OLD);