@@ -5666,64 +5666,44 @@ fn trans_bind(&@block_ctxt cx, &@ast::expr f,
5666
5666
5667
5667
fn trans_arg_expr( & @block_ctxt cx, & ty:: arg arg, TypeRef lldestty0,
5668
5668
& @ast:: expr e) -> result {
5669
- auto val;
5670
- auto bcx = cx;
5671
- auto e_ty = ty:: expr_ty( cx. fcx. lcx. ccx. tcx, e) ;
5672
- if ( ty:: type_is_structural( cx. fcx. lcx. ccx. tcx, e_ty) ) {
5673
- auto re = trans_expr( bcx, e) ;
5674
- val = re. val;
5675
- bcx = re. bcx;
5676
- } else if ( arg. mode != ty:: mo_val) {
5677
- let lval_result lv;
5678
- if ( ty:: is_lval( e) ) {
5679
- lv = trans_lval( bcx, e) ;
5680
- } else {
5681
- auto r = trans_expr( bcx, e) ;
5682
- if ( type_is_immediate( cx. fcx. lcx. ccx, e_ty) ) {
5683
- lv = lval_val( r. bcx, r. val) ;
5684
- } else { lv = lval_mem( r. bcx, r. val) ; }
5685
- }
5686
- bcx = lv. res. bcx;
5687
- if ( lv. is_mem) {
5688
- val = lv. res. val;
5689
- } else {
5690
- // Non-mem but we're trying to alias; synthesize an
5691
- // alloca, spill to it and pass its address.
5692
- val = do_spill( lv. res. bcx, lv. res. val) ;
5693
- }
5694
- } else { auto re = trans_expr( bcx, e) ; val = re. val; bcx = re. bcx; }
5695
- auto is_bot = ty:: type_is_bot( cx. fcx. lcx. ccx. tcx, e_ty) ;
5696
-
5697
- // Make a copy here if the type is structural and we're passing by value.
5698
- if ( arg. mode == ty:: mo_val && !is_bot) {
5699
- if ( ty:: type_owns_heap_mem( cx. fcx. lcx. ccx. tcx, e_ty) ) {
5700
- auto rslt = alloc_ty( bcx, e_ty) ;
5701
- bcx = rslt. bcx;
5702
- auto dst = rslt. val;
5703
- rslt = copy_val( bcx, INIT , dst, val, e_ty) ;
5704
- bcx = rslt. bcx;
5705
- val = dst;
5706
- } else {
5707
- bcx = copy_ty( bcx, val, e_ty) . bcx;
5708
- }
5709
- }
5710
-
5669
+ auto ccx = cx. fcx. lcx. ccx;
5670
+ auto e_ty = ty:: expr_ty( ccx. tcx, e) ;
5671
+ auto is_bot = ty:: type_is_bot( ccx. tcx, e_ty) ;
5672
+ auto lv = trans_lval( cx, e) ;
5673
+ auto bcx = lv. res. bcx;
5674
+ auto val = lv. res. val;
5711
5675
if ( is_bot) {
5712
5676
// For values of type _|_, we generate an
5713
5677
// "undef" value, as such a value should never
5714
5678
// be inspected. It's important for the value
5715
5679
// to have type lldestty0 (the callee's expected type).
5716
5680
val = llvm:: LLVMGetUndef ( lldestty0) ;
5717
- } else if ( ty:: type_contains_params( cx. fcx. lcx. ccx. tcx, arg. ty) ) {
5681
+ } else if ( arg. mode == ty:: mo_val) {
5682
+ if ( ty:: type_owns_heap_mem( ccx. tcx, e_ty) ) {
5683
+ auto dst = alloc_ty( bcx, e_ty) ;
5684
+ val = dst. val;
5685
+ bcx = move_val_if_temp( dst. bcx, INIT , val, lv, e_ty) . bcx;
5686
+ } else {
5687
+ if ( lv. is_mem) { val = load_if_immediate( bcx, val, e_ty) ; }
5688
+ // FIXME for non-is-mem lvals, we should be able to just drop the
5689
+ // cleanup. However, this currently leads to a memory-corrupting
5690
+ // stage2/rustc . Find out why.
5691
+ bcx = copy_ty( bcx, val, e_ty) . bcx;
5692
+ }
5693
+ } else if ( type_is_immediate( ccx, e_ty) && !lv. is_mem) {
5694
+ val = do_spill( bcx, val) ;
5695
+ }
5696
+
5697
+ if ( !is_bot && ty:: type_contains_params( ccx. tcx, arg. ty) ) {
5718
5698
auto lldestty = lldestty0;
5719
5699
if ( arg. mode == ty:: mo_val
5720
- && ty:: type_is_structural( cx . fcx . lcx . ccx. tcx, e_ty) ) {
5700
+ && ty:: type_is_structural( ccx. tcx, e_ty) ) {
5721
5701
lldestty = T_ptr ( lldestty) ;
5722
5702
}
5723
5703
val = bcx. build. PointerCast ( val, lldestty) ;
5724
5704
}
5725
5705
if ( arg. mode == ty:: mo_val
5726
- && ty:: type_is_structural( cx . fcx . lcx . ccx. tcx, e_ty) ) {
5706
+ && ty:: type_is_structural( ccx. tcx, e_ty) ) {
5727
5707
// Until here we've been treating structures by pointer;
5728
5708
// we are now passing it as an arg, so need to load it.
5729
5709
val = bcx. build. Load ( val) ;
0 commit comments