@@ -4458,16 +4458,15 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4458
4458
}
4459
4459
4460
4460
let a: uint = 3 u; // retptr, task ptr, env come first
4461
-
4462
4461
let b: int = 1 ;
4463
4462
let outgoing_arg_index: uint = 0 u;
4464
4463
let llout_arg_tys: TypeRef [ ] =
4465
4464
type_of_explicit_args ( cx. ccx , sp, outgoing_args) ;
4466
4465
for arg: option:: t[ @ast:: expr] in args {
4467
4466
let out_arg = outgoing_args. ( outgoing_arg_index) ;
4468
4467
let llout_arg_ty = llout_arg_tys. ( outgoing_arg_index) ;
4468
+ let is_val = out_arg. mode == ty:: mo_val;
4469
4469
alt arg {
4470
-
4471
4470
// Arg provided at binding time; thunk copies it from
4472
4471
// closure.
4473
4472
some( e) {
@@ -4478,7 +4477,14 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4478
4477
abi:: closure_elt_bindings, b] ) ;
4479
4478
bcx = bound_arg. bcx ;
4480
4479
let val = bound_arg. val ;
4481
- if out_arg. mode == ty:: mo_val {
4480
+ // If the type is parameterized, then we need to cast the
4481
+ // type we actually have to the parameterized out type.
4482
+ if ty:: type_contains_params ( cx. ccx . tcx , out_arg. ty ) {
4483
+ let ty = if is_val
4484
+ { T_ptr ( llout_arg_ty) } else { llout_arg_ty } ;
4485
+ val = bcx. build . PointerCast ( val, ty) ;
4486
+ }
4487
+ if is_val {
4482
4488
if type_is_immediate ( cx. ccx , e_ty) {
4483
4489
val = bcx. build . Load ( val) ;
4484
4490
bcx = copy_ty ( bcx, val, e_ty) . bcx ;
@@ -4487,13 +4493,6 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4487
4493
val = bcx. build . Load ( val) ;
4488
4494
}
4489
4495
}
4490
- // If the type is parameterized, then we need to cast the
4491
- // type we actually have to the parameterized out type.
4492
- if ty:: type_contains_params ( cx. ccx . tcx , out_arg. ty ) {
4493
- // FIXME: (#642) This works for boxes and alias params
4494
- // but does not work for bare functions.
4495
- val = bcx. build . PointerCast ( val, llout_arg_ty) ;
4496
- }
4497
4496
llargs += ~[ val] ;
4498
4497
b += 1 ;
4499
4498
}
@@ -4502,7 +4501,7 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
4502
4501
none. {
4503
4502
let passed_arg: ValueRef = llvm:: LLVMGetParam ( llthunk, a) ;
4504
4503
if ty:: type_contains_params ( cx. ccx . tcx , out_arg. ty ) {
4505
- assert ( out_arg . mode != ty :: mo_val ) ;
4504
+ assert ( !is_val ) ;
4506
4505
passed_arg = bcx. build . PointerCast ( passed_arg, llout_arg_ty) ;
4507
4506
}
4508
4507
llargs += ~[ passed_arg] ;
0 commit comments