Avoid unused allocas for immediate return values
There's no need to allocate a return slot for anykind of immediate return value, not just not for nils. Also, when the return value is ignored, we only have to copy it to a temporary alloca if it's actually required to call drop_ty on it.
This commit is contained in:
parent
48ad726f2a
commit
4a485f8cec
@ -672,15 +672,8 @@ pub fn trans_call_inner(in_cx: block,
|
||||
expr::Ignore => {
|
||||
// drop the value if it is not being saved.
|
||||
unsafe {
|
||||
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
|
||||
if ty::type_is_nil(ret_ty) {
|
||||
// When implementing the for-loop sugar syntax, the
|
||||
// type of the for-loop is nil, but the function
|
||||
// it's invoking returns a bool. This is a special
|
||||
// case to ignore instead of invoking the Store
|
||||
// below into a scratch pointer of a mismatched
|
||||
// type.
|
||||
} else if ty::type_is_immediate(bcx.tcx(), ret_ty) {
|
||||
if ty::type_needs_drop(bcx.tcx(), ret_ty) {
|
||||
if ty::type_is_immediate(bcx.tcx(), ret_ty) {
|
||||
let llscratchptr = alloc_ty(bcx, ret_ty);
|
||||
Store(bcx, llresult, llscratchptr);
|
||||
bcx = glue::drop_ty(bcx, llscratchptr, ret_ty);
|
||||
@ -734,7 +727,7 @@ pub fn trans_ret_slot(bcx: block, fn_ty: ty::t, dest: expr::Dest)
|
||||
match dest {
|
||||
expr::SaveIn(dst) => dst,
|
||||
expr::Ignore => {
|
||||
if ty::type_is_nil(retty) {
|
||||
if ty::type_is_immediate(bcx.tcx(), retty) {
|
||||
unsafe {
|
||||
llvm::LLVMGetUndef(Type::nil().ptr_to().to_ref())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user