@@ -661,7 +661,7 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t, bool boxed) -> TypeRef {
661
661
fail;
662
662
}
663
663
case ( ty. ty_param ( _) ) {
664
- llty = T_typaram_ptr ( cx . tn ) ;
664
+ llty = T_i8 ( ) ;
665
665
}
666
666
case ( ty. ty_type ) { llty = T_ptr ( T_tydesc ( cx. tn ) ) ; }
667
667
}
@@ -1216,17 +1216,14 @@ fn trans_raw_malloc(@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize)
1216
1216
ret rslt;
1217
1217
}
1218
1218
1219
- fn trans_malloc_without_cleanup ( @block_ctxt cx , @ty. t t ) -> result {
1220
- auto llty = type_of ( cx. fcx . ccx , t) ;
1221
- auto llsize = llsize_of ( llvm. LLVMGetElementType ( llty) ) ;
1222
- ret trans_raw_malloc ( cx, llty, llsize) ;
1223
- }
1224
-
1225
- fn trans_malloc ( @block_ctxt cx , @ty. t t ) -> result {
1226
- auto scope_cx = find_scope_cx ( cx) ;
1227
- auto rslt = trans_malloc_without_cleanup ( cx, t) ;
1228
- scope_cx. cleanups += clean ( bind drop_ty ( _, rslt. val , t) ) ;
1229
- ret rslt;
1219
+ fn trans_malloc_boxed ( @block_ctxt cx , @ty. t t ) -> result {
1220
+ // Synthesize a fake box type structurally so we have something
1221
+ // to measure the size of.
1222
+ auto boxed_body = plain_ty ( ty. ty_tup ( vec ( plain_ty ( ty. ty_int ) , t) ) ) ;
1223
+ auto box_ptr = plain_ty ( ty. ty_box ( t) ) ;
1224
+ auto sz = size_of ( cx, boxed_body) ;
1225
+ auto llty = type_of ( cx. fcx . ccx , box_ptr) ;
1226
+ ret trans_raw_malloc ( sz. bcx , llty, sz. val ) ;
1230
1227
}
1231
1228
1232
1229
@@ -2256,7 +2253,11 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
2256
2253
case ( ast. box) {
2257
2254
auto e_ty = ty. expr_ty( e) ;
2258
2255
auto e_val = sub. val;
2259
- sub = trans_malloc( sub. bcx, node_ann_type( sub. bcx. fcx. ccx, a) ) ;
2256
+ auto box_ty = node_ann_type( sub. bcx. fcx. ccx, a) ;
2257
+ sub = trans_malloc_boxed( sub. bcx, e_ty) ;
2258
+ find_scope_cx( cx) . cleanups +=
2259
+ clean( bind drop_ty( _, sub. val, box_ty) ) ;
2260
+
2260
2261
auto box = sub. val;
2261
2262
auto rc = sub. bcx. build. GEP ( box,
2262
2263
vec( C_int ( 0 ) ,
@@ -4707,11 +4708,8 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
4707
4708
fields_ty) ) ) ;
4708
4709
let @ty. t boxed_body_ty = plain_ty( ty. ty_box( body_ty) ) ;
4709
4710
4710
- let TypeRef llboxed_body_ty = type_of( cx, boxed_body_ty) ;
4711
-
4712
4711
// Malloc a box for the body.
4713
- auto box = trans_raw_malloc( bcx, llboxed_body_ty,
4714
- llsize_of( llvm. LLVMGetElementType ( llboxed_body_ty) ) ) ;
4712
+ auto box = trans_malloc_boxed( bcx, body_ty) ;
4715
4713
bcx = box. bcx;
4716
4714
auto rc = GEP_tup_like ( bcx, boxed_body_ty, box. val,
4717
4715
vec( 0 , abi. box_rc_field_refcnt) ) ;
0 commit comments