Skip to content

Commit 9b38e2b

Browse files
committed
---
yaml --- r: 16110 b: refs/heads/try c: 1f4b3cf h: refs/heads/master v: v3
1 parent c2ac9a8 commit 9b38e2b

File tree

3 files changed

+32
-23
lines changed

3 files changed

+32
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 555492e427035caf4a0849580b16130ede6dcf5b
5+
refs/heads/try: 1f4b3cfc3639f939b44396c4aa6074a4d60bc5c7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/rustc/middle/trans/base.rs

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,29 @@ fn umin(cx: block, a: ValueRef, b: ValueRef) -> ValueRef {
256256
}
257257

258258
fn alloca(cx: block, t: TypeRef) -> ValueRef {
259+
alloca_maybe_zeroed(cx, t, false)
260+
}
261+
262+
fn alloca_zeroed(cx: block, t: TypeRef) -> ValueRef {
263+
alloca_maybe_zeroed(cx, t, true)
264+
}
265+
266+
fn alloca_maybe_zeroed(cx: block, t: TypeRef, zero: bool) -> ValueRef {
259267
let _icx = cx.insn_ctxt("alloca");
260268
if cx.unreachable { ret llvm::LLVMGetUndef(t); }
261-
ret Alloca(raw_block(cx.fcx, cx.fcx.llstaticallocas), t);
269+
let initcx = raw_block(cx.fcx, cx.fcx.llstaticallocas);
270+
let p = Alloca(initcx, t);
271+
if zero { Store(initcx, C_null(t), p); }
272+
ret p;
273+
}
274+
275+
fn zero_mem(cx: block, llptr: ValueRef, t: ty::t) -> block {
276+
let _icx = cx.insn_ctxt("zero_mem");
277+
let bcx = cx;
278+
let ccx = cx.ccx();
279+
let llty = type_of(ccx, t);
280+
Store(bcx, C_null(llty), llptr);
281+
ret bcx;
262282
}
263283

264284
fn arrayalloca(cx: block, t: TypeRef, v: ValueRef) -> ValueRef {
@@ -1386,14 +1406,14 @@ fn move_val(cx: block, action: copy_action, dst: ValueRef,
13861406
if src.kind == owned { src_val = Load(cx, src_val); }
13871407
if action == DROP_EXISTING { cx = drop_ty(cx, dst, t); }
13881408
Store(cx, src_val, dst);
1389-
if src.kind == owned { ret zero_alloca(cx, src.val, t); }
1409+
if src.kind == owned { ret zero_mem(cx, src.val, t); }
13901410
// If we're here, it must be a temporary.
13911411
revoke_clean(cx, src_val);
13921412
ret cx;
13931413
} else if type_is_structural_or_param(t) {
13941414
if action == DROP_EXISTING { cx = drop_ty(cx, dst, t); }
13951415
memmove_ty(cx, dst, src_val, t);
1396-
if src.kind == owned { ret zero_alloca(cx, src_val, t); }
1416+
if src.kind == owned { ret zero_mem(cx, src_val, t); }
13971417
// If we're here, it must be a temporary.
13981418
revoke_clean(cx, src_val);
13991419
ret cx;
@@ -1695,7 +1715,7 @@ fn root_value(bcx: block, val: ValueRef, ty: ty::t,
16951715
#fmt["preserving until end of scope %d", scope_id]);
16961716
}
16971717

1698-
let root_loc = alloca(bcx, type_of(bcx.ccx(), ty));
1718+
let root_loc = alloca_zeroed(bcx, type_of(bcx.ccx(), ty));
16991719
copy_val(bcx, INIT, root_loc, val, ty);
17001720
add_root_cleanup(bcx, scope_id, root_loc, ty);
17011721
}
@@ -2585,7 +2605,7 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
25852605
}
25862606

25872607
let ty = expr_ty(lv.bcx, e);
2588-
let root_loc = alloca(lv.bcx, type_of(cx.ccx(), ty));
2608+
let root_loc = alloca_zeroed(lv.bcx, type_of(cx.ccx(), ty));
25892609
let bcx = store_temp_expr(lv.bcx, INIT, root_loc, lv, ty, false);
25902610
add_root_cleanup(bcx, scope_id, root_loc, ty);
25912611
{bcx: bcx with lv}
@@ -2852,7 +2872,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
28522872
if lv.kind == owned || !ty::type_is_immediate(arg.ty) {
28532873
memmove_ty(bcx, alloc, val, arg.ty);
28542874
if move_out && ty::type_needs_drop(ccx.tcx, arg.ty) {
2855-
bcx = zero_alloca(bcx, val, arg.ty);
2875+
bcx = zero_mem(bcx, val, arg.ty);
28562876
}
28572877
} else { Store(bcx, val, alloc); }
28582878
val = alloc;
@@ -3422,7 +3442,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
34223442
e.id, scope_id];
34233443

34243444
let ty = expr_ty(bcx, e);
3425-
let root_loc = alloca(bcx, type_of(bcx.ccx(), ty));
3445+
let root_loc = alloca_zeroed(bcx, type_of(bcx.ccx(), ty));
34263446
let bcx = unrooted(bcx, e, save_in(root_loc));
34273447

34283448
if !bcx.sess().no_asm_comments() {
@@ -3674,7 +3694,7 @@ fn lval_result_to_dps(lv: lval_result, ty: ty::t,
36743694
} else if last_use {
36753695
*cell = Load(bcx, val);
36763696
if ty::type_needs_drop(ccx.tcx, ty) {
3677-
bcx = zero_alloca(bcx, val, ty);
3697+
bcx = zero_mem(bcx, val, ty);
36783698
}
36793699
} else {
36803700
if kind == owned { val = Load(bcx, val); }
@@ -3982,23 +4002,13 @@ fn init_local(bcx: block, local: @ast::local) -> block {
39824002
bcx = move_val(sub.bcx, INIT, llptr, sub, ty);
39834003
}
39844004
}
3985-
_ { bcx = zero_alloca(bcx, llptr, ty); }
4005+
_ { bcx = zero_mem(bcx, llptr, ty); }
39864006
}
39874007
// Make a note to drop this slot on the way out.
39884008
add_clean(bcx, llptr, ty);
39894009
ret alt::bind_irrefutable_pat(bcx, local.node.pat, llptr, false);
39904010
}
39914011

3992-
fn zero_alloca(cx: block, llptr: ValueRef, t: ty::t)
3993-
-> block {
3994-
let _icx = cx.insn_ctxt("zero_alloca");
3995-
let bcx = cx;
3996-
let ccx = cx.ccx();
3997-
let llty = type_of(ccx, t);
3998-
Store(bcx, C_null(llty), llptr);
3999-
ret bcx;
4000-
}
4001-
40024012
fn trans_stmt(cx: block, s: ast::stmt) -> block {
40034013
let _icx = cx.insn_ctxt("trans_stmt");
40044014
#debug["trans_stmt(%s)", stmt_to_str(s)];
@@ -4785,8 +4795,7 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
47854795
// drop their LHS
47864796
for fields.each {|field|
47874797
let ix = field_idx_strict(bcx.tcx(), sp, field.ident, fields);
4788-
bcx = zero_alloca(bcx, GEPi(bcx, valptr, [0u, ix]),
4789-
field.mt.ty);
4798+
bcx = zero_mem(bcx, GEPi(bcx, valptr, [0u, ix]), field.mt.ty);
47904799
}
47914800

47924801
// note we don't want to take *or* drop self.

branches/try/src/rustc/middle/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ fn build_closure(bcx0: block,
321321
capture::cap_drop {
322322
assert lv.kind == owned;
323323
bcx = drop_ty(bcx, lv.val, ty);
324-
bcx = zero_alloca(bcx, lv.val, ty);
324+
bcx = zero_mem(bcx, lv.val, ty);
325325
}
326326
}
327327
}

0 commit comments

Comments
 (0)