@@ -581,7 +581,7 @@ fn T_ivec(TypeRef t) -> TypeRef {
581
581
fn T_opaque_ivec ( ) -> TypeRef {
582
582
ret T_struct ( [ T_int ( ) , // Length ("fill"; if zero, heapified)
583
583
T_int ( ) , // Alloc
584
- T_array ( T_i8 ( ) , abi :: ivec_default_size ) ] ) ; // Body elements
584
+ T_array ( T_i8 ( ) , 0 u ) ] ) ; // Body elements
585
585
}
586
586
587
587
fn T_ivec_heap_part ( TypeRef t) -> TypeRef {
@@ -3728,16 +3728,16 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3728
3728
C_int ( 0 ) ] ) ;
3729
3729
auto heap_len = on_heap_cx. build. Load ( heap_len_ptr) ;
3730
3730
auto new_heap_len = on_heap_cx. build. Add ( heap_len, len_needed) ;
3731
- auto heap_no_resize_needed = on_heap_cx. build. ICmp ( lib:: llvm:: LLVMIntULT ,
3731
+ auto heap_len_unscaled = on_heap_cx. build. UDiv ( heap_len,
3732
+ llsize_of( llunitty) ) ;
3733
+ auto heap_no_resize_needed = on_heap_cx. build. ICmp ( lib:: llvm:: LLVMIntULE ,
3732
3734
new_heap_len, alen) ;
3733
3735
auto heap_no_resize_cx = new_sub_block_ctxt( cx, "heap_no_resize") ;
3734
3736
auto heap_resize_cx = new_sub_block_ctxt( cx, "heap_resize") ;
3735
3737
on_heap_cx. build. CondBr ( heap_no_resize_needed, heap_no_resize_cx. llbb,
3736
3738
heap_resize_cx. llbb) ;
3737
3739
3738
3740
// Case (1): We're on the heap and don't need to resize.
3739
- auto heap_len_unscaled = heap_no_resize_cx. build. UDiv ( heap_len,
3740
- llsize_of( llunitty) ) ;
3741
3741
auto heap_data_no_resize = heap_no_resize_cx. build. InBoundsGEP ( heap_ptr,
3742
3742
[ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) , heap_len_unscaled] ) ;
3743
3743
heap_no_resize_cx. build. Br ( next_cx. llbb) ;
@@ -3754,21 +3754,21 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3754
3754
heap_resize_cx. build. InBoundsGEP ( stub_ptr,
3755
3755
[ C_int ( 0 ) , C_uint ( abi:: ivec_heap_stub_elt_ptr) ] ) ) ;
3756
3756
auto heap_data_resize = heap_resize_cx. build. InBoundsGEP ( heap_ptr_resize,
3757
- [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) , C_int ( 0 ) ] ) ;
3757
+ [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) , heap_len_unscaled ] ) ;
3758
3758
heap_resize_cx. build. Br ( next_cx. llbb) ;
3759
3759
3760
3760
// We're on the stack. Check whether we need to spill to the heap.
3761
3761
auto new_stack_len = on_stack_cx. build. Add ( stack_len, len_needed) ;
3762
- auto stack_no_spill_needed = on_stack_cx. build. ICmp ( lib:: llvm:: LLVMIntULT ,
3762
+ auto stack_no_spill_needed = on_stack_cx. build. ICmp ( lib:: llvm:: LLVMIntULE ,
3763
3763
new_stack_len, alen) ;
3764
+ auto stack_len_unscaled = on_stack_cx. build. UDiv ( stack_len,
3765
+ llsize_of( llunitty) ) ;
3764
3766
auto stack_no_spill_cx = new_sub_block_ctxt( cx, "stack_no_spill") ;
3765
3767
auto stack_spill_cx = new_sub_block_ctxt( cx, "stack_spill") ;
3766
3768
on_stack_cx. build. CondBr ( stack_no_spill_needed, stack_no_spill_cx. llbb,
3767
3769
stack_spill_cx. llbb) ;
3768
3770
3769
3771
// Case (3): We're on the stack and don't need to spill.
3770
- auto stack_len_unscaled = stack_no_spill_cx. build. UDiv ( stack_len,
3771
- llsize_of( llunitty) ) ;
3772
3772
auto stack_data_no_spill = stack_no_spill_cx. build. InBoundsGEP ( v,
3773
3773
[ C_int ( 0 ) , C_uint ( abi:: ivec_elt_elems) , stack_len_unscaled] ) ;
3774
3774
stack_no_spill_cx. build. Br ( next_cx. llbb) ;
@@ -3789,7 +3789,7 @@ fn reserve_ivec_space(&@block_ctxt cx, TypeRef llunitty, ValueRef v,
3789
3789
auto heap_len_ptr_spill = stack_spill_cx. build. InBoundsGEP ( heap_ptr_spill,
3790
3790
[ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_len) ] ) ;
3791
3791
auto heap_data_spill = stack_spill_cx. build. InBoundsGEP ( heap_ptr_spill,
3792
- [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) , C_int ( 0 ) ] ) ;
3792
+ [ C_int ( 0 ) , C_uint ( abi:: ivec_heap_elt_elems) , stack_len_unscaled ] ) ;
3793
3793
3794
3794
stack_spill_cx. build. Br ( next_cx. llbb) ;
3795
3795
@@ -5840,10 +5840,14 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5840
5840
auto unit_align = rslt. val;
5841
5841
bcx = rslt. bcx;
5842
5842
5843
+ auto llalen = bcx. build. Mul ( unit_align, C_uint ( abi:: ivec_default_length) ) ;
5844
+
5843
5845
auto llunitty = type_of_or_i8( bcx, unit_ty) ;
5844
5846
auto llvecptr;
5845
5847
if ( ty:: type_has_dynamic_size( bcx. fcx. lcx. ccx. tcx, unit_ty) ) {
5846
- llvecptr = alloca( bcx, T_opaque_ivec ( ) ) ;
5848
+ auto array_size = bcx. build. Add ( llsize_of( T_opaque_ivec ( ) ) , llalen) ;
5849
+ llvecptr = array_alloca( bcx, T_i8 ( ) , array_size) ;
5850
+ llvecptr = bcx. build. PointerCast ( llvecptr, T_ptr ( T_opaque_ivec ( ) ) ) ;
5847
5851
} else {
5848
5852
llvecptr = alloca( bcx, T_ivec ( llunitty) ) ;
5849
5853
}
@@ -5852,12 +5856,11 @@ fn trans_ivec(@block_ctxt bcx, &vec[@ast::expr] args, &ast::ann ann)
5852
5856
5853
5857
// Allocate the vector pieces and store length and allocated length.
5854
5858
auto llfirsteltptr;
5855
- if ( vec:: len( args) > 0 u && vec:: len( args) < abi:: ivec_default_size ) {
5859
+ if ( vec:: len( args) > 0 u && vec:: len( args) < abi:: ivec_default_length ) {
5856
5860
// Interior case.
5857
5861
bcx. build. Store ( lllen, bcx. build. InBoundsGEP ( llvecptr,
5858
5862
[ C_int( 0 ) , C_uint ( abi : : ivec_elt_len) ] ) ) ;
5859
- bcx. build. Store ( C_uint ( abi:: ivec_default_size) ,
5860
- bcx. build. InBoundsGEP ( llvecptr,
5863
+ bcx. build. Store ( llalen, bcx. build. InBoundsGEP ( llvecptr,
5861
5864
[ C_int ( 0 ) , C_uint ( abi:: ivec_elt_alen) ] ) ) ;
5862
5865
llfirsteltptr = bcx. build. InBoundsGEP ( llvecptr,
5863
5866
[ C_int ( 0 ) , C_uint ( abi:: ivec_elt_elems) , C_int ( 0 ) ] ) ;
0 commit comments