Skip to content

Commit a059b47

Browse files
committed
Null slots on missing init, null-check box ptrs on drop. Works around missing typestate pass. Un-XFAIL box-in-tup.rs.
1 parent 3f9d5da commit a059b47

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ TEST_XFAILS_SELF := $(filter-out \
524524
arith-2.rs \
525525
bool-not.rs \
526526
box.rs \
527+
box-in-tup.rs \
527528
char.rs \
528529
complex.rs \
529530
dead-code-one-arm-if.rs \

src/comp/middle/trans.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -524,17 +524,24 @@ fn decr_refcnt_and_if_zero(@block_ctxt cx,
524524
str inner_name,
525525
TypeRef t_else, ValueRef v_else) -> result {
526526

527+
auto load_rc_cx = new_sub_block_ctxt(cx, "load rc");
527528
auto rc_adj_cx = new_sub_block_ctxt(cx, "rc--");
528529
auto inner_cx = new_sub_block_ctxt(cx, inner_name);
529530
auto next_cx = new_sub_block_ctxt(cx, "next");
530531

531-
auto rc_ptr = cx.build.GEP(box_ptr, vec(C_int(0),
532-
C_int(abi.box_rc_field_refcnt)));
533-
auto rc = cx.build.Load(rc_ptr);
532+
auto null_test = cx.build.IsNull(box_ptr);
533+
cx.build.CondBr(null_test, next_cx.llbb, load_rc_cx.llbb);
534534

535-
auto const_test = cx.build.ICmp(lib.llvm.LLVMIntEQ,
536-
C_int(abi.const_refcount as int), rc);
537-
cx.build.CondBr(const_test, next_cx.llbb, rc_adj_cx.llbb);
535+
536+
auto rc_ptr = load_rc_cx.build.GEP(box_ptr,
537+
vec(C_int(0),
538+
C_int(abi.box_rc_field_refcnt)));
539+
540+
auto rc = load_rc_cx.build.Load(rc_ptr);
541+
auto const_test =
542+
load_rc_cx.build.ICmp(lib.llvm.LLVMIntEQ,
543+
C_int(abi.const_refcount as int), rc);
544+
load_rc_cx.build.CondBr(const_test, next_cx.llbb, rc_adj_cx.llbb);
538545

539546
rc = rc_adj_cx.build.Sub(rc, C_int(1));
540547
rc_adj_cx.build.Store(rc, rc_ptr);
@@ -545,8 +552,9 @@ fn decr_refcnt_and_if_zero(@block_ctxt cx,
545552
inner_res.bcx.build.Br(next_cx.llbb);
546553

547554
auto phi = next_cx.build.Phi(t_else,
548-
vec(v_else, v_else, inner_res.val),
555+
vec(v_else, v_else, v_else, inner_res.val),
549556
vec(cx.llbb,
557+
load_rc_cx.llbb,
550558
rc_adj_cx.llbb,
551559
inner_res.bcx.llbb));
552560

@@ -865,7 +873,7 @@ fn copy_ty(@block_ctxt cx,
865873
} else if (typeck.type_is_boxed(t)) {
866874
auto r = incr_refcnt(cx, src);
867875
if (! is_init) {
868-
r = drop_ty(r.bcx, dst, t);
876+
r = drop_ty(r.bcx, r.bcx.build.Load(dst), t);
869877
}
870878
ret res(r.bcx, r.bcx.build.Store(src, dst));
871879

@@ -1499,7 +1507,7 @@ impure fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
14991507
auto rhs_res = trans_expr(lhs_res._0.bcx, src);
15001508
auto t = node_ann_type(cx.fcx.ccx, ann);
15011509
// FIXME: calculate copy init-ness in typestate.
1502-
ret copy_ty(rhs_res.bcx, true, lhs_res._0.val, rhs_res.val, t);
1510+
ret copy_ty(rhs_res.bcx, false, lhs_res._0.val, rhs_res.val, t);
15031511
}
15041512

15051513
case (ast.expr_call(?f, ?args, _)) {
@@ -1659,15 +1667,19 @@ impure fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
16591667
check (cx.fcx.lllocals.contains_key(local.id));
16601668
auto llptr = cx.fcx.lllocals.get(local.id);
16611669
auto ty = node_ann_type(cx.fcx.ccx, local.ann);
1662-
find_scope_cx(sub.bcx).cleanups +=
1670+
find_scope_cx(cx).cleanups +=
16631671
clean(bind drop_slot(_, llptr, ty));
16641672

16651673
alt (local.init) {
16661674
case (some[@ast.expr](?e)) {
16671675
sub = trans_expr(cx, e);
16681676
sub = copy_ty(sub.bcx, true, llptr, sub.val, ty);
16691677
}
1670-
case (_) { /* fall through */ }
1678+
case (_) {
1679+
auto llty = type_of(cx.fcx.ccx, ty);
1680+
auto null = lib.llvm.llvm.LLVMConstNull(llty);
1681+
sub = res(cx, cx.build.Store(null, llptr));
1682+
}
16711683
}
16721684
}
16731685
}

0 commit comments

Comments
 (0)