Skip to content

Commit ab7ebb6

Browse files
committed
rustc: Fix dominance issue when translating generic interior vectors
1 parent a68a5c9 commit ab7ebb6

File tree

1 file changed

+64
-21
lines changed

1 file changed

+64
-21
lines changed

src/comp/middle/trans.rs

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,25 +3538,66 @@ mod ivec {
35383538
post_copy_cx.build.Br(copy_loop_header_cx.llbb);
35393539
ret res(next_cx, C_nil());
35403540
}
3541-
fn alloc(&@block_ctxt bcx, ty::t unit_ty, ValueRef llalen) -> ValueRef {
3541+
3542+
type alloc_result = rec(@block_ctxt bcx,
3543+
ValueRef llptr,
3544+
ValueRef llunitsz,
3545+
ValueRef llalen);
3546+
3547+
fn alloc(&@block_ctxt cx, ty::t unit_ty) -> alloc_result {
3548+
auto dynamic = ty::type_has_dynamic_size(cx.fcx.lcx.ccx.tcx, unit_ty);
3549+
3550+
auto bcx;
3551+
if (dynamic) {
3552+
bcx = llallocas_block_ctxt(cx.fcx);
3553+
} else {
3554+
bcx = cx;
3555+
}
3556+
3557+
auto llunitsz;
3558+
auto rslt = size_of(bcx, unit_ty);
3559+
bcx = rslt.bcx;
3560+
llunitsz = rslt.val;
3561+
if (dynamic) { bcx.fcx.llallocas = bcx.llbb; }
3562+
3563+
auto llalen = bcx.build.Mul(llunitsz,
3564+
C_uint(abi::ivec_default_length));
3565+
3566+
auto llptr;
35423567
auto llunitty = type_of_or_i8(bcx, unit_ty);
3543-
if (ty::type_has_dynamic_size(bcx.fcx.lcx.ccx.tcx, unit_ty)) {
3544-
auto llarraysz =
3545-
bcx.build.Add(llsize_of(T_opaque_ivec()), llalen);
3568+
if (dynamic) {
3569+
auto llarraysz = bcx.build.Add(llsize_of(T_opaque_ivec()),
3570+
llalen);
35463571
auto llvecptr = array_alloca(bcx, T_i8(), llarraysz);
3547-
ret bcx.build.PointerCast(llvecptr, T_ptr(T_opaque_ivec()));
3572+
llptr = bcx.build.PointerCast(llvecptr, T_ptr(T_opaque_ivec()));
3573+
} else {
3574+
llptr = alloca(bcx, T_ivec(llunitty));
35483575
}
3549-
ret alloca(bcx, T_ivec(llunitty));
3576+
3577+
auto bcx_result;
3578+
if (dynamic) {
3579+
bcx_result = cx;
3580+
} else {
3581+
bcx_result = bcx;
3582+
}
3583+
3584+
ret rec(bcx=bcx_result,
3585+
llptr=llptr,
3586+
llunitsz=llunitsz,
3587+
llalen=llalen);
35503588
}
3551-
fn trans_add(&@block_ctxt cx, ty::t vec_ty, ValueRef lhs, ValueRef rhs) ->
3552-
result {
3589+
3590+
fn trans_add(&@block_ctxt cx, ty::t vec_ty, ValueRef lhs, ValueRef rhs)
3591+
-> result {
35533592
auto bcx = cx;
35543593
auto unit_ty = ty::sequence_element_type(bcx.fcx.lcx.ccx.tcx, vec_ty);
3555-
auto rslt = size_of(bcx, unit_ty);
3556-
auto unit_sz = rslt.val;
3557-
auto llalen =
3558-
bcx.build.Mul(unit_sz, C_uint(abi::ivec_default_length));
3559-
auto llvecptr = alloc(bcx, unit_ty, llalen);
3594+
3595+
auto ares = alloc(bcx, unit_ty);
3596+
bcx = ares.bcx;
3597+
auto llvecptr = ares.llptr;
3598+
auto unit_sz = ares.llunitsz;
3599+
auto llalen = ares.llalen;
3600+
35603601
auto llunitty = type_of_or_i8(bcx, unit_ty);
35613602
auto llheappartty = T_ivec_heap_part(llunitty);
35623603
auto lhs_len_and_data = get_len_and_data(bcx, lhs, unit_ty);
@@ -3631,7 +3672,7 @@ mod ivec {
36313672
heap_cx.build.InBoundsGEP(stub_ptr_heap,
36323673
stub_a));
36333674
auto heap_sz = heap_cx.build.Add(llsize_of(llheappartty), lllen);
3634-
rslt = trans_raw_malloc(heap_cx, T_ptr(llheappartty), heap_sz);
3675+
auto rslt = trans_raw_malloc(heap_cx, T_ptr(llheappartty), heap_sz);
36353676
auto heap_part = rslt.val;
36363677
heap_cx = rslt.bcx;
36373678
heap_cx.build.Store(heap_part,
@@ -5405,12 +5446,14 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann) ->
54055446
case (ty::ty_ivec(?mt)) { unit_ty = mt.ty; }
54065447
case (_) { bcx.fcx.lcx.ccx.sess.bug("non-ivec type in trans_ivec"); }
54075448
}
5408-
auto rslt = size_of(bcx, unit_ty);
5409-
auto unit_sz = rslt.val;
5410-
bcx = rslt.bcx;
5411-
auto llalen = bcx.build.Mul(unit_sz, C_uint(abi::ivec_default_length));
54125449
auto llunitty = type_of_or_i8(bcx, unit_ty);
5413-
auto llvecptr = ivec::alloc(bcx, unit_ty, llalen);
5450+
5451+
auto ares = ivec::alloc(bcx, unit_ty);
5452+
bcx = ares.bcx;
5453+
auto llvecptr = ares.llptr;
5454+
auto unit_sz = ares.llunitsz;
5455+
auto llalen = ares.llalen;
5456+
54145457
auto lllen = bcx.build.Mul(C_uint(vec::len(args)), unit_sz);
54155458
// Allocate the vector pieces and store length and allocated length.
54165459

@@ -5449,7 +5492,7 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann) ->
54495492
llfirsteltptr = C_null(T_ptr(llunitty));
54505493
} else {
54515494
auto llheapsz = bcx.build.Add(llsize_of(llheapty), lllen);
5452-
rslt = trans_raw_malloc(bcx, T_ptr(llheapty), llheapsz);
5495+
auto rslt = trans_raw_malloc(bcx, T_ptr(llheapty), llheapsz);
54535496
bcx = rslt.bcx;
54545497
auto llheapptr = rslt.val;
54555498
bcx.build.Store(llheapptr,
@@ -5467,7 +5510,7 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann) ->
54675510

54685511
auto i = 0u;
54695512
for (@ast::expr e in args) {
5470-
rslt = trans_expr(bcx, e);
5513+
auto rslt = trans_expr(bcx, e);
54715514
bcx = rslt.bcx;
54725515
auto llsrc = rslt.val;
54735516
auto lleltptr;

0 commit comments

Comments
 (0)