@@ -230,7 +230,7 @@ pub fn lazily_emit_tydesc_glue(ccx: @mut CrateContext,
230
230
field : uint ,
231
231
ti : @mut tydesc_info ) {
232
232
let _icx = push_ctxt ( "lazily_emit_tydesc_glue" ) ;
233
- let llfnty = Type :: glue_fn ( ) ;
233
+ let llfnty = Type :: glue_fn ( type_of :: type_of ( ccx , ti . ty ) . ptr_to ( ) ) ;
234
234
235
235
if lazily_emit_simplified_tydesc_glue ( ccx, field, ti) {
236
236
return ;
@@ -323,7 +323,20 @@ pub fn call_tydesc_glue_full(bcx: block,
323
323
}
324
324
} ;
325
325
326
- let llrawptr = PointerCast ( bcx, v, Type :: i8p ( ) ) ;
326
+ // When static type info is available, avoid casting parameter unless the
327
+ // glue is using a simplified type, because the function already has the
328
+ // right type. Otherwise cast to generic pointer.
329
+ let llrawptr = if static_ti. is_none ( ) || static_glue_fn. is_none ( ) {
330
+ PointerCast ( bcx, v, Type :: i8p ( ) )
331
+ } else {
332
+ let ty = static_ti. get ( ) . ty ;
333
+ let simpl = simplified_glue_type ( ccx. tcx , field, ty) ;
334
+ if simpl != ty {
335
+ PointerCast ( bcx, v, type_of ( ccx, simpl) . ptr_to ( ) )
336
+ } else {
337
+ v
338
+ }
339
+ } ;
327
340
328
341
let llfn = {
329
342
match static_glue_fn {
@@ -709,13 +722,14 @@ pub fn make_generic_glue_inner(ccx: @mut CrateContext,
709
722
// requirement since in many contexts glue is invoked indirectly and
710
723
// the caller has no idea if it's dealing with something that can be
711
724
// passed by value.
725
+ //
726
+ // llfn is expected be declared to take a parameter of the appropriate
727
+ // type, so we don't need to explicitly cast the function parameter.
712
728
713
729
let bcx = top_scope_block ( fcx, None ) ;
714
730
let lltop = bcx. llbb ;
715
731
let rawptr0_arg = fcx. arg_pos ( 0 u) ;
716
732
let llrawptr0 = unsafe { llvm:: LLVMGetParam ( llfn, rawptr0_arg as c_uint ) } ;
717
- let llty = type_of ( ccx, t) ;
718
- let llrawptr0 = PointerCast ( bcx, llrawptr0, llty. ptr_to ( ) ) ;
719
733
let bcx = helper ( bcx, llrawptr0, t) ;
720
734
721
735
finish_fn ( fcx, lltop, bcx) ;
0 commit comments