Skip to content

Commit c6a47e4

Browse files
committed
rustc: Hoist derived tydesc GC roots up to the top of the function so the GC doesn't try to access uninitialized tydescs
1 parent 6d8bb3c commit c6a47e4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/comp/middle/gc.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
5656
tk_derived. {
5757
// It's a derived type descriptor. First, spill it.
5858
let lltydescptr = trans::alloca(bcx, val_ty(lltydesc));
59-
bld::Store(bcx, lltydesc, lltydescptr);
59+
60+
let llderivedtydescs =
61+
trans::llderivedtydescs_block_ctxt(bcx_fcx(bcx));
62+
bld::Store(llderivedtydescs, lltydesc, lltydescptr);
6063

6164
let number = gc_cx.next_tydesc_num;
6265
gc_cx.next_tydesc_num += 1u;
@@ -71,10 +74,10 @@ fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
7174
lldestindex = lll::LLVMConstPointerCast(lldestindex, T_ptr(T_i8()));
7275
llsrcindex = lll::LLVMConstPointerCast(llsrcindex, T_ptr(T_i8()));
7376

74-
lltydescptr =
75-
bld::PointerCast(bcx, lltydescptr, T_ptr(T_ptr(T_i8())));
77+
lltydescptr = bld::PointerCast(llderivedtydescs, lltydescptr,
78+
T_ptr(T_ptr(T_i8())));
7679

77-
bld::Call(bcx, gcroot, [lltydescptr, lldestindex]);
80+
bld::Call(llderivedtydescs, gcroot, [lltydescptr, lldestindex]);
7881
bld::Call(bcx, gcroot, [llvalptr, llsrcindex]);
7982
}
8083
tk_param. {

0 commit comments

Comments
 (0)