@@ -256,9 +256,29 @@ fn umin(cx: block, a: ValueRef, b: ValueRef) -> ValueRef {
256
256
}
257
257
258
258
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 {
259
267
let _icx = cx. insn_ctxt ( "alloca" ) ;
260
268
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;
262
282
}
263
283
264
284
fn arrayalloca ( cx : block , t : TypeRef , v : ValueRef ) -> ValueRef {
@@ -1386,14 +1406,14 @@ fn move_val(cx: block, action: copy_action, dst: ValueRef,
1386
1406
if src. kind == owned { src_val = Load ( cx, src_val) ; }
1387
1407
if action == DROP_EXISTING { cx = drop_ty ( cx, dst, t) ; }
1388
1408
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) ; }
1390
1410
// If we're here, it must be a temporary.
1391
1411
revoke_clean ( cx, src_val) ;
1392
1412
ret cx;
1393
1413
} else if type_is_structural_or_param ( t) {
1394
1414
if action == DROP_EXISTING { cx = drop_ty ( cx, dst, t) ; }
1395
1415
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) ; }
1397
1417
// If we're here, it must be a temporary.
1398
1418
revoke_clean ( cx, src_val) ;
1399
1419
ret cx;
@@ -1695,7 +1715,7 @@ fn root_value(bcx: block, val: ValueRef, ty: ty::t,
1695
1715
#fmt[ "preserving until end of scope %d" , scope_id] ) ;
1696
1716
}
1697
1717
1698
- let root_loc = alloca ( bcx, type_of ( bcx. ccx ( ) , ty) ) ;
1718
+ let root_loc = alloca_zeroed ( bcx, type_of ( bcx. ccx ( ) , ty) ) ;
1699
1719
copy_val ( bcx, INIT , root_loc, val, ty) ;
1700
1720
add_root_cleanup ( bcx, scope_id, root_loc, ty) ;
1701
1721
}
@@ -2585,7 +2605,7 @@ fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
2585
2605
}
2586
2606
2587
2607
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) ) ;
2589
2609
let bcx = store_temp_expr ( lv. bcx , INIT , root_loc, lv, ty, false ) ;
2590
2610
add_root_cleanup ( bcx, scope_id, root_loc, ty) ;
2591
2611
{ bcx: bcx with lv}
@@ -2852,7 +2872,7 @@ fn trans_arg_expr(cx: block, arg: ty::arg, lldestty: TypeRef, e: @ast::expr,
2852
2872
if lv. kind == owned || !ty:: type_is_immediate ( arg. ty ) {
2853
2873
memmove_ty ( bcx, alloc, val, arg. ty ) ;
2854
2874
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 ) ;
2856
2876
}
2857
2877
} else { Store ( bcx, val, alloc) ; }
2858
2878
val = alloc;
@@ -3422,7 +3442,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
3422
3442
e. id , scope_id] ;
3423
3443
3424
3444
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) ) ;
3426
3446
let bcx = unrooted ( bcx, e, save_in ( root_loc) ) ;
3427
3447
3428
3448
if !bcx. sess ( ) . no_asm_comments ( ) {
@@ -3674,7 +3694,7 @@ fn lval_result_to_dps(lv: lval_result, ty: ty::t,
3674
3694
} else if last_use {
3675
3695
* cell = Load ( bcx, val) ;
3676
3696
if ty:: type_needs_drop ( ccx. tcx , ty) {
3677
- bcx = zero_alloca ( bcx, val, ty) ;
3697
+ bcx = zero_mem ( bcx, val, ty) ;
3678
3698
}
3679
3699
} else {
3680
3700
if kind == owned { val = Load ( bcx, val) ; }
@@ -3982,23 +4002,13 @@ fn init_local(bcx: block, local: @ast::local) -> block {
3982
4002
bcx = move_val ( sub. bcx , INIT , llptr, sub, ty) ;
3983
4003
}
3984
4004
}
3985
- _ { bcx = zero_alloca ( bcx, llptr, ty) ; }
4005
+ _ { bcx = zero_mem ( bcx, llptr, ty) ; }
3986
4006
}
3987
4007
// Make a note to drop this slot on the way out.
3988
4008
add_clean ( bcx, llptr, ty) ;
3989
4009
ret alt:: bind_irrefutable_pat ( bcx, local. node . pat , llptr, false ) ;
3990
4010
}
3991
4011
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
-
4002
4012
fn trans_stmt ( cx : block , s : ast:: stmt ) -> block {
4003
4013
let _icx = cx. insn_ctxt ( "trans_stmt" ) ;
4004
4014
#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,
4785
4795
// drop their LHS
4786
4796
for fields. each { |field|
4787
4797
let ix = field_idx_strict( bcx. tcx( ) , sp, field. ident, fields) ;
4788
- bcx = zero_alloca ( bcx, GEPi ( bcx, valptr, [ 0 u, ix] ) ,
4789
- field. mt . ty ) ;
4798
+ bcx = zero_mem ( bcx, GEPi ( bcx, valptr, [ 0 u, ix] ) , field. mt . ty ) ;
4790
4799
}
4791
4800
4792
4801
// note we don't want to take *or* drop self.
0 commit comments