From 01815b392058dbf862f4287be307821cf00cc964 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 4 Feb 2014 20:53:58 +0200 Subject: [PATCH] Don't copy arguments passed by value with indirection to allocas. --- src/librustc/middle/trans/_match.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 135b16b22ab..ad2e96702b0 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -2028,9 +2028,21 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, Some(path) => { // Generate nicer LLVM for the common case of fn a pattern // like `x: T` - mk_binding_alloca( - bcx, pat.id, path, BindArgument, arg_scope, arg, - |arg, bcx, llval, _| arg.store_to(bcx, llval)) + let arg_ty = node_id_type(bcx, pat.id); + if type_of::arg_is_indirect(bcx.ccx(), arg_ty) + && !bcx.ccx().sess.opts.extra_debuginfo { + // Don't copy an indirect argument to an alloca, the caller + // already put it in a temporary alloca and gave it up, unless + // we emit extra-debug-info, which requires local allocas :(. + let arg_val = arg.add_clean(bcx.fcx, arg_scope); + let mut llmap = bcx.fcx.llargs.borrow_mut(); + llmap.get().insert(pat.id, Datum(arg_val, arg_ty, Lvalue)); + bcx + } else { + mk_binding_alloca( + bcx, pat.id, path, BindArgument, arg_scope, arg, + |arg, bcx, llval, _| arg.store_to(bcx, llval)) + } } None => {