Skip to content

Commit 6dd0637

Browse files
committed
ensure the value in the gcroot is transferred during union conversion
convert_julia_type is only ever called with needsgcroot=false, so this is mostly dead-code right now
1 parent c0b77de commit 6dd0637

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/codegen.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -981,18 +981,25 @@ static jl_cgval_t convert_julia_type(const jl_cgval_t &v, jl_value_t *typ, jl_co
981981
// root the result, and return a new mark_julia_slot over the result
982982
Value *boxv = box_union(v, ctx, skip_box);
983983
Value *froot = NULL;
984-
// XXX: need to clone the value from `v.gcroot` if this isn't a new box
985984
if (needsroot) {
986985
// build a new gc-root, as needed
987986
froot = emit_local_root(ctx);
988987
Value *newroot = boxv;
989-
if (wasboxed) { // oldbox might be all ghost values (which don't need roots)
988+
if (wasboxed || v.gcroot) { // oldbox might be all ghost values (which don't need roots)
990989
// store either the old box or the new box into the gc-root (skip_box ensures these are mutually-exclusive)
991-
Value *oldroot = v.V;
990+
// need to clone the value from `v.gcroot` if this isn't a new box
991+
Value *oldroot;
992+
if (v.gcroot)
993+
oldroot = builder.CreateLoad(v.gcroot);
994+
else
995+
oldroot = v.V;
992996
newroot = builder.CreateSelect(wasboxed, emit_bitcast(oldroot, boxv->getType()), newroot);
993997
}
994998
builder.CreateStore(newroot, froot);
995999
}
1000+
else {
1001+
mark_gc_use(v);
1002+
}
9961003
if (v.V == NULL) {
9971004
// v.V might be NULL if it was all ghost objects before
9981005
return jl_cgval_t(boxv, froot, false, typ, new_tindex);

0 commit comments

Comments
 (0)