Skip to content

Commit d922b0a

Browse files
committed
Drop slots on the way out of scopes. Un-XFAIL box.rs.
1 parent 966cfed commit d922b0a

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/Makefile

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

src/comp/middle/trans.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,16 @@ fn incr_all_refcnts(@block_ctxt cx,
640640
ret res(cx, C_nil());
641641
}
642642

643+
fn drop_slot(@block_ctxt cx,
644+
ValueRef slot,
645+
@typeck.ty t) -> result {
646+
if (typeck.type_is_structural(t)) {
647+
be drop_ty(cx, slot, t);
648+
} else {
649+
be drop_ty(cx, cx.build.Load(slot), t);
650+
}
651+
}
652+
643653
fn drop_ty(@block_ctxt cx,
644654
ValueRef v,
645655
@typeck.ty t) -> result {
@@ -812,7 +822,8 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result {
812822
C_int(len)));
813823
sub.val = sub.bcx.build.IntToPtr(sub.val,
814824
T_ptr(T_str()));
815-
cx.cleanups += clean(bind trans_drop_str(_, sub.val));
825+
find_scope_cx(cx).cleanups +=
826+
clean(bind trans_drop_str(_, sub.val));
816827
ret sub;
817828
}
818829
}
@@ -1529,13 +1540,18 @@ impure fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result {
15291540
case (ast.stmt_decl(?d)) {
15301541
alt (d.node) {
15311542
case (ast.decl_local(?local)) {
1543+
1544+
// Make a note to drop this slot on the way out.
1545+
check (cx.fcx.lllocals.contains_key(local.id));
1546+
auto llptr = cx.fcx.lllocals.get(local.id);
1547+
auto ty = node_ann_type(cx.fcx.ccx, local.ann);
1548+
find_scope_cx(sub.bcx).cleanups +=
1549+
clean(bind drop_slot(_, llptr, ty));
1550+
15321551
alt (local.init) {
15331552
case (some[@ast.expr](?e)) {
1534-
check (cx.fcx.lllocals.contains_key(local.id));
1535-
auto llptr = cx.fcx.lllocals.get(local.id);
15361553
sub = trans_expr(cx, e);
1537-
sub = copy_ty(sub.bcx, true, llptr, sub.val,
1538-
typeck.expr_ty(e));
1554+
sub = copy_ty(sub.bcx, true, llptr, sub.val, ty);
15391555
}
15401556
case (_) { /* fall through */ }
15411557
}
@@ -1658,7 +1674,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result {
16581674
}
16591675
}
16601676

1661-
bcx = trans_block_cleanups(bcx, bcx);
1677+
bcx = trans_block_cleanups(bcx, find_scope_cx(bcx));
16621678
ret res(bcx, r.val);
16631679
}
16641680

0 commit comments

Comments
 (0)