@@ -244,15 +244,13 @@ fn trans_foreign_call(cx: block, externs: hashmap<~str, ValueRef>,
244
244
245
245
fn trans_free ( cx : block , v : ValueRef ) -> block {
246
246
let _icx = cx. insn_ctxt ( ~"trans_free") ;
247
- Call ( cx, cx. ccx ( ) . upcalls . free , ~[ PointerCast ( cx, v, T_ptr ( T_i8 ( ) ) ) ] ) ;
248
- cx
247
+ trans_rtcall ( cx, ~"free", ~[ PointerCast ( cx, v, T_ptr ( T_i8 ( ) ) ) ] , ignore)
249
248
}
250
249
251
250
fn trans_unique_free ( cx : block , v : ValueRef ) -> block {
252
251
let _icx = cx. insn_ctxt ( ~"trans_unique_free") ;
253
- Call ( cx, cx. ccx ( ) . upcalls . exchange_free ,
254
- ~[ PointerCast ( cx, v, T_ptr ( T_i8 ( ) ) ) ] ) ;
255
- ret cx;
252
+ trans_rtcall ( cx, ~"exchange_free", ~[ PointerCast ( cx, v, T_ptr ( T_i8 ( ) ) ) ] ,
253
+ ignore)
256
254
}
257
255
258
256
fn umax ( cx : block , a : ValueRef , b : ValueRef ) -> ValueRef {
@@ -356,15 +354,13 @@ fn opaque_box_body(bcx: block,
356
354
// malloc_raw_dyn: allocates a box to contain a given type, but with a
357
355
// potentially dynamic size.
358
356
fn malloc_raw_dyn ( bcx : block , t : ty:: t , heap : heap ,
359
- size : ValueRef ) -> ValueRef {
357
+ size : ValueRef ) -> result {
360
358
let _icx = bcx. insn_ctxt ( ~"malloc_raw") ;
361
359
let ccx = bcx. ccx ( ) ;
362
360
363
- let ( mk_fn, upcall) = alt heap {
364
- heap_shared { ( ty:: mk_imm_box, ccx. upcalls . malloc ) }
365
- heap_exchange {
366
- ( ty:: mk_imm_uniq, ccx. upcalls . exchange_malloc )
367
- }
361
+ let ( mk_fn, rtcall) = alt heap {
362
+ heap_shared { ( ty:: mk_imm_box, ~"malloc") }
363
+ heap_exchange { ( ty:: mk_imm_uniq, ~"exchange_malloc") }
368
364
} ;
369
365
370
366
// Grab the TypeRef type of box_ptr_ty.
@@ -376,37 +372,42 @@ fn malloc_raw_dyn(bcx: block, t: ty::t, heap: heap,
376
372
lazily_emit_all_tydesc_glue ( ccx, static_ti) ;
377
373
378
374
// Allocate space:
379
- let rval = Call ( bcx, upcall, ~[ static_ti. tydesc , size] ) ;
380
- ret PointerCast ( bcx, rval, llty) ;
375
+ let tydesc = PointerCast ( bcx, static_ti. tydesc , T_ptr ( T_i8 ( ) ) ) ;
376
+ let rval = alloca_zeroed ( bcx, T_ptr ( T_i8 ( ) ) ) ;
377
+ let bcx = trans_rtcall ( bcx, rtcall, ~[ tydesc, size] , save_in ( rval) ) ;
378
+ let retval = { bcx: bcx, val: PointerCast ( bcx, Load ( bcx, rval) , llty) } ;
379
+ ret retval;
381
380
}
382
381
383
382
// malloc_raw: expects an unboxed type and returns a pointer to
384
383
// enough space for a box of that type. This includes a rust_opaque_box
385
384
// header.
386
- fn malloc_raw ( bcx : block , t : ty:: t , heap : heap ) -> ValueRef {
385
+ fn malloc_raw ( bcx : block , t : ty:: t , heap : heap ) -> result {
387
386
malloc_raw_dyn ( bcx, t, heap, llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
388
387
}
389
388
390
389
// malloc_general_dyn: usefully wraps malloc_raw_dyn; allocates a box,
391
390
// and pulls out the body
392
- fn malloc_general_dyn ( bcx : block , t : ty:: t , heap : heap , size : ValueRef ) ->
393
- { box : ValueRef , body : ValueRef } {
391
+ fn malloc_general_dyn ( bcx : block , t : ty:: t , heap : heap , size : ValueRef )
392
+ -> { bcx : block , box : ValueRef , body : ValueRef } {
394
393
let _icx = bcx. insn_ctxt ( ~"malloc_general") ;
395
- let llbox = malloc_raw_dyn ( bcx, t, heap, size) ;
394
+ let { bcx : bcx , val : llbox } = malloc_raw_dyn ( bcx, t, heap, size) ;
396
395
let non_gc_box = non_gc_box_cast ( bcx, llbox) ;
397
396
let body = GEPi ( bcx, non_gc_box, ~[ 0 u, abi:: box_field_body] ) ;
398
- ret { box : llbox, body : body} ;
397
+ ret { bcx : bcx , box : llbox, body : body} ;
399
398
}
400
399
401
- fn malloc_general ( bcx : block , t : ty:: t , heap : heap ) ->
402
- { box : ValueRef , body : ValueRef } {
400
+ fn malloc_general ( bcx : block , t : ty:: t , heap : heap )
401
+ -> { bcx : block , box : ValueRef , body : ValueRef } {
403
402
malloc_general_dyn ( bcx, t, heap,
404
403
llsize_of ( bcx. ccx ( ) , type_of ( bcx. ccx ( ) , t) ) )
405
404
}
406
- fn malloc_boxed ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
405
+ fn malloc_boxed ( bcx : block , t : ty:: t )
406
+ -> { bcx : block, box : ValueRef , body : ValueRef } {
407
407
malloc_general ( bcx, t, heap_shared)
408
408
}
409
- fn malloc_unique ( bcx : block , t : ty:: t ) -> { box : ValueRef , body : ValueRef } {
409
+ fn malloc_unique ( bcx : block , t : ty:: t )
410
+ -> { bcx : block, box : ValueRef , body : ValueRef } {
410
411
malloc_general ( bcx, t, heap_exchange)
411
412
}
412
413
@@ -1464,7 +1465,7 @@ fn trans_boxed_expr(bcx: block, contents: @ast::expr,
1464
1465
t : ty:: t , heap : heap ,
1465
1466
dest : dest ) -> block {
1466
1467
let _icx = bcx. insn_ctxt ( ~"trans_boxed_expr") ;
1467
- let { box, body} = malloc_general ( bcx, t, heap) ;
1468
+ let { bcx , box, body} = malloc_general ( bcx, t, heap) ;
1468
1469
add_clean_free ( bcx, box, heap) ;
1469
1470
let bcx = trans_expr_save_in ( bcx, contents, body) ;
1470
1471
revoke_clean ( bcx, box) ;
@@ -3942,12 +3943,13 @@ fn trans_fail_value(bcx: block, sp_opt: option<span>,
3942
3943
let V_str = PointerCast(bcx, V_fail_str, T_ptr(T_i8()));
3943
3944
let V_filename = PointerCast(bcx, V_filename, T_ptr(T_i8()));
3944
3945
let args = ~[V_str, V_filename, C_int(ccx, V_line)];
3945
- let bcx = trans_rtcall(bcx, ~" fail", args) ;
3946
+ let bcx = trans_rtcall(bcx, ~" fail", args, ignore ) ;
3946
3947
Unreachable ( bcx) ;
3947
3948
ret bcx;
3948
3949
}
3949
3950
3950
- fn trans_rtcall ( bcx : block , name : ~str , args : ~[ ValueRef ] ) -> block {
3951
+ fn trans_rtcall ( bcx : block , name : ~str , args : ~[ ValueRef ] , dest : dest )
3952
+ -> block {
3951
3953
let did = bcx. ccx ( ) . rtcalls [ name] ;
3952
3954
let fty = if did. crate == ast:: local_crate {
3953
3955
ty:: node_id_to_type ( bcx. ccx ( ) . tcx , did. node )
@@ -3958,7 +3960,7 @@ fn trans_rtcall(bcx: block, name: ~str, args: ~[ValueRef]) -> block {
3958
3960
ret trans_call_inner (
3959
3961
bcx, none, fty, rty,
3960
3962
|bcx| lval_static_fn_inner ( bcx, did, 0 , ~[ ] , none) ,
3961
- arg_vals ( args) , ignore ) ;
3963
+ arg_vals ( args) , dest ) ;
3962
3964
}
3963
3965
3964
3966
fn trans_break_cont ( bcx : block , to_end : bool )
@@ -5396,8 +5398,12 @@ fn gather_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
5396
5398
// supported. Also probably want to check type signature so we don't crash
5397
5399
// in some obscure place in LLVM if the user provides the wrong signature
5398
5400
// for an rtcall.
5399
- if !ccx. rtcalls . contains_key ( ~"fail") {
5400
- fail ~"no definition for runtime call fail";
5401
+ let expected_rtcalls =
5402
+ ~[ ~"exchange_free", ~"exchange_malloc", ~"fail", ~"free", ~"malloc"] ;
5403
+ for vec:: each( expected_rtcalls) |name| {
5404
+ if !ccx. rtcalls . contains_key ( name) {
5405
+ fail #fmt( "no definition for runtime call %s" , name) ;
5406
+ }
5401
5407
}
5402
5408
}
5403
5409
0 commit comments