@@ -1269,8 +1269,7 @@ fn make_copy_glue(cx: &@block_ctxt, v: ValueRef, t: &ty::t) {
1269
1269
bcx = iter_structural_ty ( bcx, v, t, bind copy_ty ( _, _, _) ) . bcx ;
1270
1270
} else { bcx = cx; }
1271
1271
1272
- bcx = trans_fn_cleanups ( bcx) ;
1273
- bcx. build . RetVoid ( ) ;
1272
+ build_return ( bcx) ;
1274
1273
}
1275
1274
1276
1275
fn incr_refcnt_of_boxed ( cx : & @block_ctxt , box_ptr : ValueRef ) -> result {
@@ -1376,8 +1375,7 @@ fn make_free_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
1376
1375
_ { rslt( cx, C_nil ( ) ) }
1377
1376
} ;
1378
1377
1379
- let bcx = trans_fn_cleanups ( rs. bcx ) ;
1380
- bcx. build . RetVoid ( ) ;
1378
+ build_return ( rs. bcx ) ;
1381
1379
}
1382
1380
1383
1381
fn maybe_free_ivec_heap_part ( cx : & @block_ctxt , v0 : ValueRef , unit_ty : ty:: t )
@@ -1446,8 +1444,7 @@ fn make_drop_glue(cx: &@block_ctxt, v0: ValueRef, t: &ty::t) {
1446
1444
}
1447
1445
} ;
1448
1446
1449
- let bcx = trans_fn_cleanups ( rs. bcx ) ;
1450
- bcx. build . RetVoid ( ) ;
1447
+ build_return ( rs. bcx ) ;
1451
1448
}
1452
1449
1453
1450
fn trans_res_drop ( cx : @block_ctxt , rs : ValueRef , did : & ast:: def_id ,
@@ -3727,8 +3724,7 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr,
3727
3724
3728
3725
if !r. bcx . build . is_terminated ( ) {
3729
3726
// if terminated is true, no need for the ret-fail
3730
- let bcx = trans_fn_cleanups ( r. bcx ) ;
3731
- bcx. build . RetVoid ( ) ;
3727
+ build_return ( r. bcx ) ;
3732
3728
}
3733
3729
3734
3730
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
@@ -4407,7 +4403,7 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4407
4403
lltargetfn = bcx. build . PointerCast ( lltargetfn, T_ptr ( T_ptr ( lltargetty) ) ) ;
4408
4404
lltargetfn = bcx. build . Load ( lltargetfn) ;
4409
4405
llvm:: LLVMSetTailCall ( bcx. build . FastCall ( lltargetfn, llargs) , 1 ) ;
4410
- bcx . build . RetVoid ( ) ;
4406
+ build_return ( bcx ) ;
4411
4407
finish_fn ( fcx, lltop) ;
4412
4408
ret { val : llthunk, ty : llthunk_ty} ;
4413
4409
}
@@ -5448,11 +5444,14 @@ fn trans_ret(cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result {
5448
5444
parent_none. { more_cleanups = false ; }
5449
5445
}
5450
5446
}
5451
- bcx = trans_fn_cleanups ( bcx) ;
5452
- bcx. build . RetVoid ( ) ;
5447
+ build_return ( bcx) ;
5453
5448
ret rslt( new_sub_block_ctxt ( bcx, "ret.unreachable" ) , C_nil ( ) ) ;
5454
5449
}
5455
5450
5451
+ fn build_return ( bcx : & @block_ctxt ) {
5452
+ bcx. build . Br ( bcx_fcx ( bcx) . llreturn ) ;
5453
+ }
5454
+
5456
5455
fn trans_be ( cx : & @block_ctxt , e : & @ast:: expr ) -> result {
5457
5456
// FIXME: This should be a typestate precondition
5458
5457
@@ -5610,16 +5609,15 @@ fn trans_block_cleanups(cx: &@block_ctxt, cleanup_cx: &@block_ctxt) ->
5610
5609
ret bcx;
5611
5610
}
5612
5611
5613
- fn trans_fn_cleanups ( bcx : & @block_ctxt ) -> @ block_ctxt {
5614
- alt bcx_fcx ( bcx ) . llobstacktoken {
5612
+ fn trans_fn_cleanups ( fcx : & @fn_ctxt , build : & lib :: llvm :: builder ) {
5613
+ alt fcx . llobstacktoken {
5615
5614
some ( lltoken_) {
5616
5615
let lltoken = lltoken_; // satisfy alias checker
5617
- bcx . build . Call ( bcx_ccx ( bcx ) . upcalls . dynastack_free ,
5618
- ~ [ bcx_fcx ( bcx ) . lltaskptr , lltoken] ) ;
5616
+ build. Call ( fcx_ccx ( fcx ) . upcalls . dynastack_free , ~ [ fcx . lltaskptr ,
5617
+ lltoken] ) ;
5619
5618
}
5620
5619
none. { /* nothing to do */ }
5621
5620
}
5622
- ret bcx;
5623
5621
}
5624
5622
5625
5623
iter block_locals ( b: & ast:: blk) -> @ast:: local {
@@ -5778,11 +5776,13 @@ fn mk_standard_basic_blocks(llfn: ValueRef) ->
5778
5776
{ sa : BasicBlockRef ,
5779
5777
ca : BasicBlockRef ,
5780
5778
dt : BasicBlockRef ,
5781
- da : BasicBlockRef } {
5779
+ da : BasicBlockRef ,
5780
+ rt : BasicBlockRef } {
5782
5781
ret { sa : llvm:: LLVMAppendBasicBlock ( llfn, str:: buf ( "static_allocas" ) ) ,
5783
5782
ca : llvm:: LLVMAppendBasicBlock ( llfn, str:: buf ( "copy_args" ) ) ,
5784
5783
dt : llvm:: LLVMAppendBasicBlock ( llfn, str:: buf ( "derived_tydescs" ) ) ,
5785
- da : llvm:: LLVMAppendBasicBlock ( llfn, str:: buf ( "dynamic_allocas" ) ) } ;
5784
+ da : llvm:: LLVMAppendBasicBlock ( llfn, str:: buf ( "dynamic_allocas" ) ) ,
5785
+ rt : llvm:: LLVMAppendBasicBlock ( llfn, str:: buf ( "return" ) ) } ;
5786
5786
}
5787
5787
5788
5788
@@ -5816,6 +5816,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: &span, llfndecl: ValueRef,
5816
5816
mutable llderivedtydescs_first : llbbs. dt ,
5817
5817
mutable llderivedtydescs : llbbs. dt ,
5818
5818
mutable lldynamicallocas : llbbs. da ,
5819
+ mutable llreturn : llbbs. rt ,
5819
5820
mutable llobstacktoken : none :: < ValueRef > ,
5820
5821
mutable llself: none :: < val_self_pair > ,
5821
5822
mutable lliterbody : none :: < ValueRef > ,
@@ -5998,12 +5999,16 @@ fn populate_fn_ctxt_from_llself(fcx: @fn_ctxt, llself: val_self_pair) {
5998
5999
5999
6000
6000
6001
// Ties up the llstaticallocas -> llcopyargs -> llderivedtydescs ->
6001
- // lldynamicallocas -> lltop edges.
6002
+ // lldynamicallocas -> lltop edges, and builds the return block .
6002
6003
fn finish_fn ( fcx : & @fn_ctxt , lltop : BasicBlockRef ) {
6003
6004
new_builder ( fcx. llstaticallocas ) . Br ( fcx. llcopyargs ) ;
6004
6005
new_builder ( fcx. llcopyargs ) . Br ( fcx. llderivedtydescs_first ) ;
6005
6006
new_builder ( fcx. llderivedtydescs ) . Br ( fcx. lldynamicallocas ) ;
6006
6007
new_builder ( fcx. lldynamicallocas ) . Br ( lltop) ;
6008
+
6009
+ let ret_builder = new_builder ( fcx. llreturn ) ;
6010
+ trans_fn_cleanups ( fcx, ret_builder) ;
6011
+ ret_builder. RetVoid ( ) ;
6007
6012
}
6008
6013
6009
6014
// trans_closure: Builds an LLVM function out of a source function.
@@ -6070,8 +6075,7 @@ fn trans_closure(bcx_maybe: &option::t<@block_ctxt>,
6070
6075
if !is_terminated ( bcx) {
6071
6076
// FIXME: until LLVM has a unit type, we are moving around
6072
6077
// C_nil values rather than their void type.
6073
- bcx = trans_fn_cleanups ( bcx) ;
6074
- bcx. build . RetVoid ( ) ;
6078
+ build_return ( bcx) ;
6075
6079
}
6076
6080
6077
6081
// Insert the mandatory first few basic blocks before lltop.
@@ -6137,7 +6141,7 @@ fn trans_res_ctor(cx: @local_ctxt, sp: &span, dtor: &ast::_fn,
6137
6141
let flag = GEP_tup_like ( bcx, tup_t, llretptr, ~[ 0 , 0 ] ) ;
6138
6142
bcx = flag. bcx ;
6139
6143
bcx. build . Store ( C_int ( 1 ) , flag. val ) ;
6140
- bcx . build . RetVoid ( ) ;
6144
+ build_return ( bcx ) ;
6141
6145
finish_fn ( fcx, lltop) ;
6142
6146
}
6143
6147
@@ -6227,8 +6231,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
6227
6231
i += 1 u;
6228
6232
}
6229
6233
bcx = trans_block_cleanups ( bcx, find_scope_cx ( bcx) ) ;
6230
- bcx = trans_fn_cleanups ( bcx) ;
6231
- bcx. build . RetVoid ( ) ;
6234
+ build_return ( bcx) ;
6232
6235
finish_fn ( fcx, lltop) ;
6233
6236
}
6234
6237
@@ -6433,7 +6436,7 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
6433
6436
} ;
6434
6437
bcx. build . FastCall ( main_llfn, args) ;
6435
6438
}
6436
- bcx . build . RetVoid ( ) ;
6439
+ build_return ( bcx ) ;
6437
6440
6438
6441
let lltop = bcx. llbb ;
6439
6442
finish_fn ( fcx, lltop) ;
@@ -6473,7 +6476,7 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span,
6473
6476
llargvarg] ;
6474
6477
bcx. build . FastCall ( main_llfn, args) ;
6475
6478
}
6476
- bcx . build . RetVoid ( ) ;
6479
+ build_return ( bcx ) ;
6477
6480
6478
6481
let lltop = bcx. llbb ;
6479
6482
finish_fn ( fcx, lltop) ;
@@ -6754,7 +6757,7 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str],
6754
6757
for d: { val: ValueRef , ty: ty:: t} in drop_args {
6755
6758
bcx = drop_ty ( bcx, d. val , d. ty ) . bcx ;
6756
6759
}
6757
- bcx . build . RetVoid ( ) ;
6760
+ build_return ( bcx ) ;
6758
6761
finish_fn ( fcx, lltop) ;
6759
6762
}
6760
6763
0 commit comments