Fix ivec self-append. Closes #816

This commit is contained in:
Brian Anderson 2011-08-22 15:04:28 -07:00
parent 0f1f5e67ea
commit 6841f3827a
2 changed files with 45 additions and 6 deletions

View file

@ -384,6 +384,12 @@ fn trans_append(cx: &@block_ctxt, t: ty::t, orig_lhs: ValueRef,
rs = reserve_space(bcx, llunitty, lhs, rhs_len); rs = reserve_space(bcx, llunitty, lhs, rhs_len);
let lhs_data = rs.val; let lhs_data = rs.val;
bcx = rs.bcx; 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. // Work out the end pointer.
let lhs_unscaled_idx = bcx.build.UDiv(rhs_len, llsize_of(llunitty)); let lhs_unscaled_idx = bcx.build.UDiv(rhs_len, llsize_of(llunitty));

View file

@ -1,13 +1,40 @@
// xfail-stage1
// xfail-stage2
// xfail-stage3
use std; use std;
import std::vec; 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. // Make sure we properly handle repeated self-appends.
let a: [int] = ~[0]; let a: [int] = [0];
let i = 20; let i = 20;
let expected_len = 1u; let expected_len = 1u;
while i > 0 { while i > 0 {
@ -18,3 +45,9 @@ fn main() {
expected_len *= 2u; expected_len *= 2u;
} }
} }
fn main() {
test_heap_to_heap();
test_stack_to_heap();
test_loop();
}