use Constant for repetition count in mir::Repeat
This commit is contained in:
parent
cba6561de2
commit
db89a75a80
5 changed files with 26 additions and 6 deletions
|
@ -44,8 +44,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
|
|||
}
|
||||
ExprKind::Repeat { value, count } => {
|
||||
let value_operand = unpack!(block = this.as_operand(block, value));
|
||||
let count_operand = unpack!(block = this.as_operand(block, count));
|
||||
block.and(Rvalue::Repeat(value_operand, count_operand))
|
||||
let count = this.as_constant(count);
|
||||
block.and(Rvalue::Repeat(value_operand, count))
|
||||
}
|
||||
ExprKind::Borrow { region, borrow_kind, arg } => {
|
||||
let arg_lvalue = unpack!(block = this.as_lvalue(block, arg));
|
||||
|
|
|
@ -546,7 +546,7 @@ pub enum Rvalue<'tcx> {
|
|||
Use(Operand<'tcx>),
|
||||
|
||||
// [x; 32]
|
||||
Repeat(Operand<'tcx>, Operand<'tcx>),
|
||||
Repeat(Operand<'tcx>, Constant<'tcx>),
|
||||
|
||||
// &x or &mut x
|
||||
Ref(Region, BorrowKind, Lvalue<'tcx>),
|
||||
|
|
|
@ -134,7 +134,7 @@ pub trait Visitor<'tcx> {
|
|||
|
||||
Rvalue::Repeat(ref value, ref len) => {
|
||||
self.visit_operand(value);
|
||||
self.visit_operand(len);
|
||||
self.visit_constant(len);
|
||||
}
|
||||
|
||||
Rvalue::Ref(r, bk, ref path) => {
|
||||
|
|
|
@ -51,9 +51,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
|
|||
|
||||
mir::Rvalue::Repeat(ref elem, ref count) => {
|
||||
let elem = self.trans_operand(bcx, elem);
|
||||
let size = self.trans_operand(bcx, count);
|
||||
let size = self.trans_constant(bcx, count);
|
||||
let base = expr::get_dataptr(bcx, lldest);
|
||||
tvec::iter_vec_raw(bcx, base, elem.ty, size.llval, |b, vref, _| {
|
||||
tvec::iter_vec_raw(bcx, base, elem.ty, size, |b, vref, _| {
|
||||
build::Store(b, elem.llval, vref);
|
||||
b
|
||||
})
|
||||
|
|
20
src/test/run-pass/mir_trans_array_2.rs
Normal file
20
src/test/run-pass/mir_trans_array_2.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_mir]
|
||||
fn into_inner(x: u64) -> [u64; 1024] {
|
||||
[x; 2*4*8*16]
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let x: &[u64] = &[42; 1024];
|
||||
assert_eq!(&into_inner(42)[..], x);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue