提交 6841f382 编写于 作者: B Brian Anderson

Fix ivec self-append. Closes #816

上级 0f1f5e67
......@@ -384,6 +384,12 @@ fn trans_append(cx: &@block_ctxt, t: ty::t, orig_lhs: ValueRef,
rs = reserve_space(bcx, llunitty, lhs, rhs_len);
let lhs_data = rs.val;
bcx = rs.bcx;
// If rhs is lhs then our rhs pointer may have changed
rhs_len_and_data = get_len_and_data(bcx, rhs, unit_ty);
rhs_data = rhs_len_and_data.data;
bcx = rhs_len_and_data.bcx;
// Work out the end pointer.
let lhs_unscaled_idx = bcx.build.UDiv(rhs_len, llsize_of(llunitty));
......
// xfail-stage1
// xfail-stage2
// xfail-stage3
use std;
import std::vec;
fn main() {
fn test_heap_to_heap() {
// a spills onto the heap
let a = [0, 1, 2, 3, 4];
a += a;
assert vec::len(a) == 10u;
assert a[0] == 0;
assert a[1] == 1;
assert a[2] == 2;
assert a[3] == 3;
assert a[4] == 4;
assert a[5] == 0;
assert a[6] == 1;
assert a[7] == 2;
assert a[8] == 3;
assert a[9] == 4;
}
fn test_stack_to_heap() {
// a is entirely on the stack
let a = [0, 1, 2];
// a spills to the heap
a += a;
assert vec::len(a) == 6u;
assert a[0] == 0;
assert a[1] == 1;
assert a[2] == 2;
assert a[3] == 0;
assert a[4] == 1;
assert a[5] == 2;
}
fn test_loop() {
// Make sure we properly handle repeated self-appends.
let a: [int] = ~[0];
let a: [int] = [0];
let i = 20;
let expected_len = 1u;
while i > 0 {
......@@ -18,3 +45,9 @@ fn main() {
expected_len *= 2u;
}
}
fn main() {
test_heap_to_heap();
test_stack_to_heap();
test_loop();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册