@@ -1122,7 +1122,7 @@ pub fn memcpy_ty(bcx: &Block, dst: ValueRef, src: ValueRef, t: ty::t) {
1122
1122
let llalign = llalign_of_min ( ccx, llty) ;
1123
1123
call_memcpy ( bcx, dst, src, llsz, llalign as u32 ) ;
1124
1124
} else {
1125
- Store ( bcx, Load ( bcx, src) , dst) ;
1125
+ store_ty ( bcx, Load ( bcx, src) , dst, t ) ;
1126
1126
}
1127
1127
}
1128
1128
@@ -1546,7 +1546,7 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) {
1546
1546
1547
1547
let retslot = Load ( ret_cx, fcx. llretslotptr . get ( ) . unwrap ( ) ) ;
1548
1548
let retptr = Value ( retslot) ;
1549
- let retval = match retptr. get_dominating_store ( ret_cx) {
1549
+ match retptr. get_dominating_store ( ret_cx) {
1550
1550
// If there's only a single store to the ret slot, we can directly return
1551
1551
// the value that was stored and omit the store and the alloca
1552
1552
Some ( s) => {
@@ -1557,21 +1557,28 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) {
1557
1557
retptr. erase_from_parent ( ) ;
1558
1558
}
1559
1559
1560
- if ty:: type_is_bool ( retty) {
1560
+ let retval = if ty:: type_is_bool ( retty) {
1561
1561
Trunc ( ret_cx, retval, Type :: i1 ( fcx. ccx ) )
1562
1562
} else {
1563
1563
retval
1564
+ } ;
1565
+
1566
+ if fcx. caller_expects_out_pointer {
1567
+ store_ty ( ret_cx, retval, get_param ( fcx. llfn , 0 ) , retty) ;
1568
+ return RetVoid ( ret_cx) ;
1569
+ } else {
1570
+ return Ret ( ret_cx, retval) ;
1571
+ }
1572
+ }
1573
+ // Otherwise, copy the return value to the ret slot
1574
+ None => {
1575
+ if fcx. caller_expects_out_pointer {
1576
+ memcpy_ty ( ret_cx, get_param ( fcx. llfn , 0 ) , retslot, retty) ;
1577
+ return RetVoid ( ret_cx) ;
1578
+ } else {
1579
+ return Ret ( ret_cx, load_ty ( ret_cx, retslot, retty) ) ;
1564
1580
}
1565
1581
}
1566
- // Otherwise, load the return value from the ret slot
1567
- None => load_ty ( ret_cx, retslot, retty)
1568
- } ;
1569
-
1570
- if fcx. caller_expects_out_pointer {
1571
- store_ty ( ret_cx, retval, get_param ( fcx. llfn , 0 ) , retty) ;
1572
- RetVoid ( ret_cx) ;
1573
- } else {
1574
- Ret ( ret_cx, retval) ;
1575
1582
}
1576
1583
}
1577
1584
0 commit comments