@@ -398,16 +398,18 @@ fn malloc_general_dyn(bcx: block, t: ty::t, heap: heap, size: ValueRef) ->
398
398
ret { box : box, body : body} ;
399
399
}
400
400
401
- fn malloc_general ( bcx : block , t : ty:: t , heap : heap ) ->
402
- { box : ValueRef , body : ValueRef } {
403
- malloc_general_dyn ( bcx, t, heap,
404
- llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
405
- }
406
401
fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
407
- malloc_general ( bcx, t, heap_shared)
402
+ malloc_general_dyn ( bcx, t, heap_shared,
403
+ llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
408
404
}
409
405
fn malloc_unique ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
410
- malloc_general ( bcx, t, heap_exchange)
406
+ malloc_general_dyn ( bcx, t, heap_exchange,
407
+ llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
408
+ }
409
+
410
+ fn malloc_unique_dyn ( bcx : block , t : ty:: t , size : ValueRef
411
+ ) -> { box : ValueRef , body : ValueRef } {
412
+ malloc_general_dyn ( bcx, t, heap_exchange, size)
411
413
}
412
414
413
415
// Type descriptor and type glue stuff
@@ -1485,19 +1487,6 @@ fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
1485
1487
}
1486
1488
}
1487
1489
1488
-
1489
- fn trans_boxed_expr ( bcx : block , contents : @ast:: expr ,
1490
- t : ty:: t , heap : heap ,
1491
- dest : dest ) -> block {
1492
- let _icx = bcx. insn_ctxt ( "trans_boxed_expr" ) ;
1493
- let { box, body} = malloc_general ( bcx, t, heap) ;
1494
- add_clean_free ( bcx, box, true ) ;
1495
- let bcx = trans_expr_save_in ( bcx, contents, body) ;
1496
- revoke_clean ( bcx, box) ;
1497
- ret store_in_dest ( bcx, box, dest) ;
1498
- }
1499
-
1500
-
1501
1490
fn trans_unary ( bcx : block , op : ast:: unop , e : @ast:: expr ,
1502
1491
un_expr : @ast:: expr , dest : dest ) -> block {
1503
1492
let _icx = bcx. insn_ctxt ( "trans_unary" ) ;
@@ -1520,25 +1509,35 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
1520
1509
alt op {
1521
1510
ast : : not {
1522
1511
let { bcx, val} = trans_temp_expr ( bcx, e) ;
1523
- store_in_dest ( bcx, Not ( bcx, val) , dest)
1512
+ ret store_in_dest ( bcx, Not ( bcx, val) , dest) ;
1524
1513
}
1525
1514
ast:: neg {
1526
1515
let { bcx, val} = trans_temp_expr ( bcx, e) ;
1527
1516
let neg = if ty:: type_is_fp ( e_ty) {
1528
1517
FNeg ( bcx, val)
1529
1518
} else { Neg ( bcx, val) } ;
1530
- store_in_dest ( bcx, neg, dest)
1519
+ ret store_in_dest ( bcx, neg, dest) ;
1531
1520
}
1532
1521
ast:: box ( _) {
1533
- trans_boxed_expr ( bcx, e, e_ty, heap_shared, dest)
1522
+ let mut { box, body} = malloc_boxed ( bcx, e_ty) ;
1523
+ add_clean_free ( bcx, box, false ) ;
1524
+ // Cast the body type to the type of the value. This is needed to
1525
+ // make enums work, since enums have a different LLVM type depending
1526
+ // on whether they're boxed or not
1527
+ let ccx = bcx. ccx ( ) ;
1528
+ let llety = T_ptr ( type_of ( ccx, e_ty) ) ;
1529
+ body = PointerCast ( bcx, body, llety) ;
1530
+ let bcx = trans_expr_save_in ( bcx, e, body) ;
1531
+ revoke_clean ( bcx, box) ;
1532
+ ret store_in_dest ( bcx, box, dest) ;
1534
1533
}
1535
1534
ast:: uniq ( _) {
1536
- trans_boxed_expr ( bcx, e, e_ty , heap_exchange , dest)
1535
+ ret uniq :: trans_uniq ( bcx, e, un_expr . id , dest) ;
1537
1536
}
1538
1537
ast:: deref {
1539
1538
bcx. sess ( ) . bug ( "deref expressions should have been \
1540
1539
translated using trans_lval(), not \
1541
- trans_unary()")
1540
+ trans_unary()") ;
1542
1541
}
1543
1542
}
1544
1543
}
0 commit comments