about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBjörn Steinbrink <bsteinbr@gmail.com>2013-07-08 07:42:56 +0200
committerBjörn Steinbrink <steinbrink@saltation.de>2013-07-08 13:17:46 +0200
commit4a485f8cec524c8f3f57e4fd3248d5093ed3dc5f (patch)
tree8f07767105cbbed46a2635b4609b227c7a7302db
parent48ad726f2abc90fe62cdf239bc1c9318261a6926 (diff)
downloadrust-4a485f8cec524c8f3f57e4fd3248d5093ed3dc5f.tar.gz
rust-4a485f8cec524c8f3f57e4fd3248d5093ed3dc5f.zip
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.
-rw-r--r--src/librustc/middle/trans/callee.rs13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs
index 05fe0bed3b6..2a5e8f2ddc0 100644
--- a/src/librustc/middle/trans/callee.rs
+++ b/src/librustc/middle/trans/callee.rs
@@ -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())
                 }