@@ -466,15 +466,17 @@ fn alloca(cx: &@block_ctxt, t: TypeRef) -> ValueRef {
466
466
}
467
467
468
468
fn array_alloca ( cx : & @block_ctxt , t : TypeRef , n : ValueRef ) -> ValueRef {
469
+ let builder = new_builder ( cx. fcx . lldynamicallocas ) ;
469
470
alt bcx_fcx( cx) . llobstacktoken {
470
471
none. {
472
+ let dynastack_mark = bcx_ccx ( cx) . upcalls . dynastack_mark ;
473
+ let lltaskptr = bcx_fcx ( cx) . lltaskptr ;
471
474
bcx_fcx ( cx) . llobstacktoken =
472
- some ( cx. build . Call ( bcx_ccx ( cx) . upcalls . dynastack_mark ,
473
- ~[ bcx_fcx ( cx) . lltaskptr ] ) ) ;
475
+ some ( builder. Call ( dynastack_mark, ~[ lltaskptr] ) ) ;
474
476
}
475
477
some ( _) { /* no-op */ }
476
478
}
477
- ret new_builder ( cx . fcx . lldynamicallocas ) . ArrayAlloca ( t, n) ;
479
+ ret builder . ArrayAlloca ( t, n) ;
478
480
}
479
481
480
482
@@ -1266,6 +1268,8 @@ fn make_copy_glue(cx: &@block_ctxt, v: ValueRef, t: &ty::t) {
1266
1268
bcx = duplicate_heap_parts_if_necessary ( cx, v, t) . bcx ;
1267
1269
bcx = iter_structural_ty ( bcx, v, t, bind copy_ty ( _, _, _) ) . bcx ;
1268
1270
} else { bcx = cx; }
1271
+
1272
+ trans_fn_cleanups ( bcx) ;
1269
1273
bcx. build . RetVoid ( ) ;
1270
1274
}
1271
1275
@@ -1371,7 +1375,9 @@ fn make_free_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
1371
1375
}
1372
1376
_ { rslt( cx, C_nil ( ) ) }
1373
1377
} ;
1374
- rs. bcx . build . RetVoid ( ) ;
1378
+
1379
+ let bcx = trans_fn_cleanups ( rs. bcx ) ;
1380
+ bcx. build . RetVoid ( ) ;
1375
1381
}
1376
1382
1377
1383
fn maybe_free_ivec_heap_part ( cx : & @block_ctxt , v0 : ValueRef , unit_ty : ty:: t )
@@ -1439,7 +1445,9 @@ fn make_drop_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
1439
1445
} else { rslt( cx, C_nil ( ) ) }
1440
1446
}
1441
1447
} ;
1442
- rs. bcx . build . RetVoid ( ) ;
1448
+
1449
+ let bcx = trans_fn_cleanups ( rs. bcx ) ;
1450
+ bcx. build . RetVoid ( ) ;
1443
1451
}
1444
1452
1445
1453
fn trans_res_drop ( cx : @block_ctxt , rs : ValueRef , did : & ast:: def_id ,
@@ -3719,7 +3727,8 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
3719
3727
3720
3728
if !r. bcx . build . is_terminated ( ) {
3721
3729
// if terminated is true, no need for the ret-fail
3722
- r. bcx . build . RetVoid ( ) ;
3730
+ let bcx = trans_fn_cleanups ( r. bcx ) ;
3731
+ bcx. build . RetVoid ( ) ;
3723
3732
}
3724
3733
3725
3734
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
@@ -5439,6 +5448,7 @@ fn trans_ret(cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result {
5439
5448
parent_none. { more_cleanups = false ; }
5440
5449
}
5441
5450
}
5451
+ bcx = trans_fn_cleanups ( bcx) ;
5442
5452
bcx. build . RetVoid ( ) ;
5443
5453
ret rslt( new_sub_block_ctxt ( bcx, "ret.unreachable" ) , C_nil ( ) ) ;
5444
5454
}
@@ -5600,6 +5610,18 @@ fn trans_block_cleanups(cx: &@block_ctxt, cleanup_cx: &@block_ctxt) ->
5600
5610
ret bcx;
5601
5611
}
5602
5612
5613
+ fn trans_fn_cleanups ( bcx : & @block_ctxt ) -> @block_ctxt {
5614
+ alt bcx_fcx ( bcx) . llobstacktoken {
5615
+ some ( lltoken_) {
5616
+ let lltoken = lltoken_; // satisfy alias checker
5617
+ bcx. build . Call ( bcx_ccx ( bcx) . upcalls . dynastack_free ,
5618
+ ~[ bcx_fcx ( bcx) . lltaskptr , lltoken] ) ;
5619
+ }
5620
+ none. { /* nothing to do */ }
5621
+ }
5622
+ ret bcx;
5623
+ }
5624
+
5603
5625
iter block_locals ( b: & ast:: blk) -> @ast:: local {
5604
5626
// FIXME: putting from inside an iter block doesn't work, so we can't
5605
5627
// use the index here.
@@ -6048,6 +6070,7 @@ fn trans_closure(bcx_maybe: &option::t<@block_ctxt>,
6048
6070
if !is_terminated ( bcx) {
6049
6071
// FIXME: until LLVM has a unit type, we are moving around
6050
6072
// C_nil values rather than their void type.
6073
+ bcx = trans_fn_cleanups ( bcx) ;
6051
6074
bcx. build . RetVoid ( ) ;
6052
6075
}
6053
6076
@@ -6204,6 +6227,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
6204
6227
i += 1 u;
6205
6228
}
6206
6229
bcx = trans_block_cleanups ( bcx, find_scope_cx ( bcx) ) ;
6230
+ bcx = trans_fn_cleanups ( bcx) ;
6207
6231
bcx. build . RetVoid ( ) ;
6208
6232
finish_fn ( fcx, lltop) ;
6209
6233
}
0 commit comments