about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2015-11-05 16:50:36 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2015-11-05 17:17:47 +0200
commitcba6561de2a7f7f03dd32c506e25c2c3868ce6d3 (patch)
tree9571c8fbc59de8d784a21d1bd50c3760aa68cf0a
parent14db07465944d2be293176dbafb0eb9d0d41595a (diff)
downloadrust-cba6561de2a7f7f03dd32c506e25c2c3868ce6d3.tar.gz
rust-cba6561de2a7f7f03dd32c506e25c2c3868ce6d3.zip
Translate MIR Repeat (arrays)
-rw-r--r--src/librustc_trans/trans/mir/rvalue.rs10
-rw-r--r--src/test/run-pass/mir_trans_array.rs21
2 files changed, 29 insertions, 2 deletions
diff --git a/src/librustc_trans/trans/mir/rvalue.rs b/src/librustc_trans/trans/mir/rvalue.rs
index ad89ee79de4..f3515c04f3e 100644
--- a/src/librustc_trans/trans/mir/rvalue.rs
+++ b/src/librustc_trans/trans/mir/rvalue.rs
@@ -49,8 +49,14 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
                 unimplemented!()
             }
 
-            mir::Rvalue::Repeat(..) => {
-                unimplemented!()
+            mir::Rvalue::Repeat(ref elem, ref count) => {
+                let elem = self.trans_operand(bcx, elem);
+                let size = self.trans_operand(bcx, count);
+                let base = expr::get_dataptr(bcx, lldest);
+                tvec::iter_vec_raw(bcx, base, elem.ty, size.llval, |b, vref, _| {
+                    build::Store(b, elem.llval, vref);
+                    b
+                })
             }
 
             mir::Rvalue::Aggregate(_, ref operands) => {
diff --git a/src/test/run-pass/mir_trans_array.rs b/src/test/run-pass/mir_trans_array.rs
new file mode 100644
index 00000000000..e6ffb895825
--- /dev/null
+++ b/src/test/run-pass/mir_trans_array.rs
@@ -0,0 +1,21 @@
+// 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() -> [u64; 1024] {
+    let mut x = 10 + 20;
+    [x; 1024]
+}
+
+fn main(){
+    let x: &[u64] = &[30; 1024];
+    assert_eq!(&into_inner()[..], x);
+}