Skip to content

Commit 0ad97c0

Browse files
committed
librustc: Don't use Load/Store for structural values.
1 parent 5aedcb1 commit 0ad97c0

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/librustc/middle/trans/base.rs

+19-12
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ pub fn memcpy_ty(bcx: &Block, dst: ValueRef, src: ValueRef, t: ty::t) {
11221122
let llalign = llalign_of_min(ccx, llty);
11231123
call_memcpy(bcx, dst, src, llsz, llalign as u32);
11241124
} else {
1125-
Store(bcx, Load(bcx, src), dst);
1125+
store_ty(bcx, Load(bcx, src), dst, t);
11261126
}
11271127
}
11281128

@@ -1546,7 +1546,7 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) {
15461546

15471547
let retslot = Load(ret_cx, fcx.llretslotptr.get().unwrap());
15481548
let retptr = Value(retslot);
1549-
let retval = match retptr.get_dominating_store(ret_cx) {
1549+
match retptr.get_dominating_store(ret_cx) {
15501550
// If there's only a single store to the ret slot, we can directly return
15511551
// the value that was stored and omit the store and the alloca
15521552
Some(s) => {
@@ -1557,21 +1557,28 @@ pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) {
15571557
retptr.erase_from_parent();
15581558
}
15591559

1560-
if ty::type_is_bool(retty) {
1560+
let retval = if ty::type_is_bool(retty) {
15611561
Trunc(ret_cx, retval, Type::i1(fcx.ccx))
15621562
} else {
15631563
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));
15641580
}
15651581
}
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);
15751582
}
15761583
}
15771584

0 commit comments

Comments
 (0)