@@ -4458,16 +4458,15 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
44584458 }
44594459
44604460 let a: uint = 3 u; // retptr, task ptr, env come first
4461-
44624461 let b: int = 1 ;
44634462 let outgoing_arg_index: uint = 0 u;
44644463 let llout_arg_tys: TypeRef [ ] =
44654464 type_of_explicit_args ( cx. ccx , sp, outgoing_args) ;
44664465 for arg: option:: t[ @ast:: expr] in args {
44674466 let out_arg = outgoing_args. ( outgoing_arg_index) ;
44684467 let llout_arg_ty = llout_arg_tys. ( outgoing_arg_index) ;
4468+ let is_val = out_arg. mode == ty:: mo_val;
44694469 alt arg {
4470-
44714470 // Arg provided at binding time; thunk copies it from
44724471 // closure.
44734472 some( e) {
@@ -4478,7 +4477,14 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
44784477 abi:: closure_elt_bindings, b] ) ;
44794478 bcx = bound_arg. bcx ;
44804479 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 {
44824488 if type_is_immediate ( cx. ccx , e_ty) {
44834489 val = bcx. build . Load ( val) ;
44844490 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,
44874493 val = bcx. build . Load ( val) ;
44884494 }
44894495 }
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- }
44974496 llargs += ~[ val] ;
44984497 b += 1 ;
44994498 }
@@ -4502,7 +4501,7 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
45024501 none. {
45034502 let passed_arg: ValueRef = llvm:: LLVMGetParam ( llthunk, a) ;
45044503 if ty:: type_contains_params ( cx. ccx . tcx , out_arg. ty ) {
4505- assert ( out_arg . mode != ty :: mo_val ) ;
4504+ assert ( !is_val ) ;
45064505 passed_arg = bcx. build . PointerCast ( passed_arg, llout_arg_ty) ;
45074506 }
45084507 llargs += ~[ passed_arg] ;
0 commit comments