Skip to content

Commit 01815b3

Browse files
committed
Don't copy arguments passed by value with indirection to allocas.
1 parent ef53b7a commit 01815b3

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/librustc/middle/trans/_match.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,9 +2028,21 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>,
20282028
Some(path) => {
20292029
// Generate nicer LLVM for the common case of fn a pattern
20302030
// like `x: T`
2031-
mk_binding_alloca(
2032-
bcx, pat.id, path, BindArgument, arg_scope, arg,
2033-
|arg, bcx, llval, _| arg.store_to(bcx, llval))
2031+
let arg_ty = node_id_type(bcx, pat.id);
2032+
if type_of::arg_is_indirect(bcx.ccx(), arg_ty)
2033+
&& !bcx.ccx().sess.opts.extra_debuginfo {
2034+
// Don't copy an indirect argument to an alloca, the caller
2035+
// already put it in a temporary alloca and gave it up, unless
2036+
// we emit extra-debug-info, which requires local allocas :(.
2037+
let arg_val = arg.add_clean(bcx.fcx, arg_scope);
2038+
let mut llmap = bcx.fcx.llargs.borrow_mut();
2039+
llmap.get().insert(pat.id, Datum(arg_val, arg_ty, Lvalue));
2040+
bcx
2041+
} else {
2042+
mk_binding_alloca(
2043+
bcx, pat.id, path, BindArgument, arg_scope, arg,
2044+
|arg, bcx, llval, _| arg.store_to(bcx, llval))
2045+
}
20342046
}
20352047

20362048
None => {

0 commit comments

Comments
 (0)