diff options
| author | Graydon Hoare <[email protected]> | 2010-12-02 19:44:24 -0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-12-02 19:44:24 -0800 |
| commit | d922b0ad9c126e416b1d6d68a567e0dcbabbbf29 (patch) | |
| tree | 960f262ee36a8d6d91d3e6d838d3efddc8ba946d | |
| parent | Modify block ctxt / cleanup handling to only occur on scope blocks. (diff) | |
| download | rust-d922b0ad9c126e416b1d6d68a567e0dcbabbbf29.tar.xz rust-d922b0ad9c126e416b1d6d68a567e0dcbabbbf29.zip | |
Drop slots on the way out of scopes. Un-XFAIL box.rs.
| -rw-r--r-- | src/Makefile | 1 | ||||
| -rw-r--r-- | src/comp/middle/trans.rs | 28 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/Makefile b/src/Makefile index 297739ff..814f78e7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -523,6 +523,7 @@ TEST_XFAILS_SELF := $(filter-out \ arith-1.rs \ arith-2.rs \ bool-not.rs \ + box.rs \ char.rs \ complex.rs \ dead-code-one-arm-if.rs \ diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 585373e7..ccacffca 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -640,6 +640,16 @@ fn incr_all_refcnts(@block_ctxt cx, ret res(cx, C_nil()); } +fn drop_slot(@block_ctxt cx, + ValueRef slot, + @typeck.ty t) -> result { + if (typeck.type_is_structural(t)) { + be drop_ty(cx, slot, t); + } else { + be drop_ty(cx, cx.build.Load(slot), t); + } +} + fn drop_ty(@block_ctxt cx, ValueRef v, @typeck.ty t) -> result { @@ -812,7 +822,8 @@ impure fn trans_lit(@block_ctxt cx, &ast.lit lit) -> result { C_int(len))); sub.val = sub.bcx.build.IntToPtr(sub.val, T_ptr(T_str())); - cx.cleanups += clean(bind trans_drop_str(_, sub.val)); + find_scope_cx(cx).cleanups += + clean(bind trans_drop_str(_, sub.val)); ret sub; } } @@ -1529,13 +1540,18 @@ impure fn trans_stmt(@block_ctxt cx, &ast.stmt s) -> result { case (ast.stmt_decl(?d)) { alt (d.node) { case (ast.decl_local(?local)) { + + // Make a note to drop this slot on the way out. + check (cx.fcx.lllocals.contains_key(local.id)); + auto llptr = cx.fcx.lllocals.get(local.id); + auto ty = node_ann_type(cx.fcx.ccx, local.ann); + find_scope_cx(sub.bcx).cleanups += + clean(bind drop_slot(_, llptr, ty)); + alt (local.init) { case (some[@ast.expr](?e)) { - check (cx.fcx.lllocals.contains_key(local.id)); - auto llptr = cx.fcx.lllocals.get(local.id); sub = trans_expr(cx, e); - sub = copy_ty(sub.bcx, true, llptr, sub.val, - typeck.expr_ty(e)); + sub = copy_ty(sub.bcx, true, llptr, sub.val, ty); } case (_) { /* fall through */ } } @@ -1658,7 +1674,7 @@ impure fn trans_block(@block_ctxt cx, &ast.block b) -> result { } } - bcx = trans_block_cleanups(bcx, bcx); + bcx = trans_block_cleanups(bcx, find_scope_cx(bcx)); ret res(bcx, r.val); } |