@@ -25,6 +25,7 @@ use middle::trans::datum::*;
25
25
use middle:: trans:: expr:: { Dest , Ignore , SaveIn } ;
26
26
use middle:: trans:: expr;
27
27
use middle:: trans:: glue;
28
+ use middle:: trans:: machine;
28
29
use middle:: trans:: machine:: { nonzero_llsize_of, llsize_of_alloc} ;
29
30
use middle:: trans:: type_:: Type ;
30
31
use middle:: trans:: type_of;
@@ -59,6 +60,7 @@ pub fn make_drop_glue_unboxed<'a>(
59
60
-> & ' a Block < ' a > {
60
61
let not_null = IsNotNull ( bcx, vptr) ;
61
62
with_cond ( bcx, not_null, |bcx| {
63
+ let ccx = bcx. ccx ( ) ;
62
64
let tcx = bcx. tcx ( ) ;
63
65
let _icx = push_ctxt ( "tvec::make_drop_glue_unboxed" ) ;
64
66
@@ -73,8 +75,11 @@ pub fn make_drop_glue_unboxed<'a>(
73
75
if should_deallocate {
74
76
let not_null = IsNotNull ( bcx, dataptr) ;
75
77
with_cond ( bcx, not_null, |bcx| {
76
- // FIXME: #13994: the old `Box<[T]>` will not support sized deallocation
77
- glue:: trans_exchange_free ( bcx, dataptr, 0 , 8 )
78
+ let llty = type_of:: type_of ( ccx, unit_ty) ;
79
+ let llsize = machine:: llsize_of ( ccx, llty) ;
80
+ let llalign = C_uint ( ccx, machine:: llalign_of_min ( ccx, llty) as uint ) ;
81
+ let size = Mul ( bcx, llsize, get_len ( bcx, vptr) ) ;
82
+ glue:: trans_exchange_free_dyn ( bcx, dataptr, size, llalign)
78
83
} )
79
84
} else {
80
85
bcx
@@ -281,15 +286,16 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>,
281
286
debug ! ( " vt={}, count={:?}" , vt. to_string( ccx) , count) ;
282
287
let vec_ty = node_id_type ( bcx, uniq_expr. id ) ;
283
288
284
- let unit_sz = nonzero_llsize_of ( ccx, type_of:: type_of ( ccx, vt. unit_ty ) ) ;
289
+ let llty = type_of:: type_of ( ccx, vt. unit_ty ) ;
290
+ let unit_sz = nonzero_llsize_of ( ccx, llty) ;
285
291
let llcount = if count < 4 u {
286
292
C_int ( ccx, 4 )
287
293
} else {
288
294
C_uint ( ccx, count)
289
295
} ;
290
296
let alloc = Mul ( bcx, llcount, unit_sz) ;
291
- let llty_ptr = type_of :: type_of ( ccx , vt . unit_ty ) . ptr_to ( ) ;
292
- let align = C_uint ( ccx, 8 ) ;
297
+ let llty_ptr = llty . ptr_to ( ) ;
298
+ let align = C_uint ( ccx, machine :: llalign_of_min ( ccx , llty ) as uint ) ;
293
299
let Result { bcx : bcx, val : dataptr } = malloc_raw_dyn ( bcx,
294
300
llty_ptr,
295
301
vec_ty,
@@ -299,16 +305,15 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>,
299
305
// Create a temporary scope lest execution should fail while
300
306
// constructing the vector.
301
307
let temp_scope = fcx. push_custom_cleanup_scope ( ) ;
302
- // FIXME: #13994: the old `Box<[T]> will not support sized deallocation,
303
- // this is a placeholder
304
- fcx. schedule_free_value ( cleanup:: CustomScope ( temp_scope) ,
305
- dataptr, cleanup:: HeapExchange , vt. unit_ty ) ;
306
308
307
- debug ! ( " alloc_uniq_vec() returned dataptr={}, len={}" ,
308
- bcx . val_to_string ( dataptr) , count ) ;
309
+ fcx . schedule_free_slice ( cleanup :: CustomScope ( temp_scope ) ,
310
+ dataptr, alloc , align , cleanup :: HeapExchange ) ;
309
311
310
- let bcx = write_content ( bcx, & vt, uniq_expr,
311
- content_expr, SaveIn ( dataptr) ) ;
312
+ debug ! ( " alloc_uniq_vec() returned dataptr={}, len={}" ,
313
+ bcx. val_to_string( dataptr) , count) ;
314
+
315
+ let bcx = write_content ( bcx, & vt, uniq_expr,
316
+ content_expr, SaveIn ( dataptr) ) ;
312
317
313
318
fcx. pop_custom_cleanup_scope ( temp_scope) ;
314
319
0 commit comments