Skip to content

Commit 96c95f1

Browse files
committed
Auto merge of #29583 - dotdash:mir_small_agg, r=nikomatsakis
Fix handling of small aggregate function arguments and assignments of temporaries to lvalues.
2 parents 3a0409d + 3235b22 commit 96c95f1

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

src/librustc_trans/trans/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: Block<'bcx, 'tcx>,
169169
idx += 2;
170170
let lltemp = base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index));
171171
build::Store(bcx, lldata, expr::get_dataptr(bcx, lltemp));
172-
build::Store(bcx, llextra, expr::get_dataptr(bcx, lltemp));
172+
build::Store(bcx, llextra, expr::get_meta(bcx, lltemp));
173173
lltemp
174174
} else {
175175
// otherwise, arg is passed by value, so make a
176176
// temporary and store it there
177177
let llarg = llvm::get_param(fcx.llfn, idx);
178178
idx += 1;
179179
let lltemp = base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index));
180-
build::Store(bcx, llarg, lltemp);
180+
base::store_ty(bcx, llarg, lltemp, arg_ty);
181181
lltemp
182182
};
183183
LvalueRef::new(llval, LvalueTy::from_ty(arg_ty))

src/librustc_trans/trans/mir/operand.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
9292
bcx.val_to_string(lldest),
9393
operand);
9494

95-
match *operand {
96-
mir::Operand::Consume(ref lvalue) => {
97-
let tr_lvalue = self.trans_lvalue(bcx, lvalue);
98-
let lvalue_ty = tr_lvalue.ty.to_ty(bcx.tcx());
99-
debug!("trans_operand_into: tr_lvalue={} @ {:?}",
100-
bcx.val_to_string(tr_lvalue.llval),
101-
lvalue_ty);
102-
base::memcpy_ty(bcx, lldest, tr_lvalue.llval, lvalue_ty);
103-
}
104-
105-
mir::Operand::Constant(..) => {
106-
unimplemented!()
107-
}
108-
}
95+
let o = self.trans_operand(bcx, operand);
96+
match datum::appropriate_rvalue_mode(bcx.ccx(), o.ty) {
97+
datum::ByValue => base::store_ty(bcx, o.llval, lldest, o.ty),
98+
datum::ByRef => base::memcpy_ty(bcx, lldest, o.llval, o.ty),
99+
};
109100
}
110101
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(rustc_attrs)]
12+
13+
#[rustc_mir]
14+
fn foo((x, y): (i8, i8)) {
15+
}
16+
17+
fn main() {
18+
foo((0, 1));
19+
}

0 commit comments

Comments
 (0)