@@ -50,15 +50,30 @@ pub fn trans_free<'a>(cx: &'a Block<'a>, v: ValueRef) -> &'a Block<'a> {
50
50
Some ( expr:: Ignore ) ) . bcx
51
51
}
52
52
53
- pub fn trans_exchange_free < ' a > ( cx : & ' a Block < ' a > , v : ValueRef )
54
- -> & ' a Block < ' a > {
53
+ fn trans_exchange_free < ' a > ( cx : & ' a Block < ' a > , v : ValueRef , size : u64 ,
54
+ align : u64 ) -> & ' a Block < ' a > {
55
55
let _icx = push_ctxt ( "trans_exchange_free" ) ;
56
+ let ccx = cx. ccx ( ) ;
56
57
callee:: trans_lang_call ( cx,
57
58
langcall ( cx, None , "" , ExchangeFreeFnLangItem ) ,
58
- [ PointerCast ( cx, v, Type :: i8p ( cx . ccx ( ) ) ) ] ,
59
+ [ PointerCast ( cx, v, Type :: i8p ( ccx) ) , C_uint ( ccx , size as uint ) , C_uint ( ccx , align as uint ) ] ,
59
60
Some ( expr:: Ignore ) ) . bcx
60
61
}
61
62
63
+ pub fn trans_exchange_free_ty < ' a > ( bcx : & ' a Block < ' a > , ptr : ValueRef ,
64
+ content_ty : ty:: t ) -> & ' a Block < ' a > {
65
+ let sizing_type = sizing_type_of ( bcx. ccx ( ) , content_ty) ;
66
+ let content_size = llsize_of_alloc ( bcx. ccx ( ) , sizing_type) ;
67
+
68
+ // `Box<ZeroSizeType>` does not allocate.
69
+ if content_size != 0 {
70
+ let content_align = llalign_of_min ( bcx. ccx ( ) , sizing_type) ;
71
+ trans_exchange_free ( bcx, ptr, content_size, content_align)
72
+ } else {
73
+ bcx
74
+ }
75
+ }
76
+
62
77
pub fn take_ty < ' a > ( bcx : & ' a Block < ' a > , v : ValueRef , t : ty:: t )
63
78
-> & ' a Block < ' a > {
64
79
// NB: v is an *alias* of type t here, not a direct value.
@@ -87,17 +102,15 @@ fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t {
87
102
ty:: ty_vec( _, None ) | ty:: ty_str => t,
88
103
_ => {
89
104
let llty = sizing_type_of ( ccx, typ) ;
90
- // Unique boxes do not allocate for zero-size types. The standard
91
- // library may assume that `free` is never called on the pointer
92
- // returned for `Box<ZeroSizeType>`.
105
+ // `Box<ZeroSizeType>` does not allocate.
93
106
if llsize_of_alloc ( ccx, llty) == 0 {
94
107
ty:: mk_i8 ( )
95
108
} else {
96
109
ty:: mk_uniq ( tcx, ty:: mk_i8 ( ) )
97
110
}
98
- }
99
- }
100
111
}
112
+ }
113
+ }
101
114
_ => t
102
115
}
103
116
}
@@ -285,20 +298,22 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
285
298
ty:: ty_vec( mt, None ) => {
286
299
with_cond ( bcx, not_null, |bcx| {
287
300
let bcx = tvec:: make_drop_glue_unboxed ( bcx, llbox, mt. ty ) ;
288
- trans_exchange_free ( bcx, llbox)
301
+ // FIXME: #13994: the old `Box<[T]>` will not support sized deallocation
302
+ trans_exchange_free ( bcx, llbox, 0 , 8 )
289
303
} )
290
304
}
291
305
ty:: ty_str => {
292
306
with_cond ( bcx, not_null, |bcx| {
293
307
let unit_ty = ty:: sequence_element_type ( bcx. tcx ( ) , t) ;
294
308
let bcx = tvec:: make_drop_glue_unboxed ( bcx, llbox, unit_ty) ;
295
- trans_exchange_free ( bcx, llbox)
309
+ // FIXME: #13994: the old `Box<str>` will not support sized deallocation
310
+ trans_exchange_free ( bcx, llbox, 0 , 8 )
296
311
} )
297
312
}
298
313
_ => {
299
314
with_cond ( bcx, not_null, |bcx| {
300
315
let bcx = drop_ty ( bcx, llbox, content_ty) ;
301
- trans_exchange_free ( bcx, llbox)
316
+ trans_exchange_free_ty ( bcx, llbox, content_ty )
302
317
} )
303
318
}
304
319
}
@@ -340,7 +355,8 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
340
355
Call ( bcx, dtor, [ PointerCast ( bcx, cdata, Type :: i8p ( bcx. ccx ( ) ) ) ] , [ ] ) ;
341
356
342
357
// Free the environment itself
343
- trans_exchange_free ( bcx, env)
358
+ // FIXME: #13994: pass align and size here
359
+ trans_exchange_free ( bcx, env, 0 , 8 )
344
360
} )
345
361
}
346
362
_ => {
0 commit comments