@@ -345,20 +345,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
345345 & args1[ ..]
346346 } ;
347347 let ( drop_fn, fn_abi) = match ty. kind {
348+ // FIXME(eddyb) perhaps move some of this logic into
349+ // `Instance::resolve_drop_in_place`?
348350 ty:: Dynamic ( ..) => {
349- let sig = drop_fn. fn_sig ( self . cx . tcx ( ) ) ;
350- let sig = self . cx . tcx ( ) . normalize_erasing_late_bound_regions (
351- ty:: ParamEnv :: reveal_all ( ) ,
352- & sig,
353- ) ;
354- let fn_abi = FnAbi :: new_vtable ( & bx, sig, & [ ] ) ;
351+ let virtual_drop = Instance {
352+ def : ty:: InstanceDef :: Virtual ( drop_fn. def_id ( ) , 0 ) ,
353+ substs : drop_fn. substs ,
354+ } ;
355+ let fn_abi = FnAbi :: of_instance ( & bx, virtual_drop, & [ ] ) ;
355356 let vtable = args[ 1 ] ;
356357 args = & args[ ..1 ] ;
357358 ( meth:: DESTRUCTOR . get_fn ( & mut bx, vtable, & fn_abi) , fn_abi)
358359 }
359360 _ => {
360361 ( bx. get_fn_addr ( drop_fn) ,
361- FnAbi :: of_instance ( & bx, drop_fn) )
362+ FnAbi :: of_instance ( & bx, drop_fn, & [ ] ) )
362363 }
363364 } ;
364365 helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
@@ -439,7 +440,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
439440 // Obtain the panic entry point.
440441 let def_id = common:: langcall ( bx. tcx ( ) , Some ( span) , "" , lang_item) ;
441442 let instance = ty:: Instance :: mono ( bx. tcx ( ) , def_id) ;
442- let fn_abi = FnAbi :: of_instance ( & bx, instance) ;
443+ let fn_abi = FnAbi :: of_instance ( & bx, instance, & [ ] ) ;
443444 let llfn = bx. get_fn_addr ( instance) ;
444445
445446 // Codegen the actual panic invoke/call.
@@ -474,6 +475,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474475 _ => bug ! ( "{} is not callable" , callee. layout. ty) ,
475476 } ;
476477 let def = instance. map ( |i| i. def ) ;
478+
479+ if let Some ( ty:: InstanceDef :: DropGlue ( _, None ) ) = def {
480+ // Empty drop glue; a no-op.
481+ let & ( _, target) = destination. as_ref ( ) . unwrap ( ) ;
482+ helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
483+ helper. funclet_br ( self , & mut bx, target) ;
484+ return ;
485+ }
486+
487+ // FIXME(eddyb) avoid computing this if possible, when `instance` is
488+ // available - right now `sig` is only needed for getthing the `abi`
489+ // and figuring out how many extra args were passed to a C-variadic `fn`.
477490 let sig = callee. layout . ty . fn_sig ( bx. tcx ( ) ) ;
478491 let sig = bx. tcx ( ) . normalize_erasing_late_bound_regions (
479492 ty:: ParamEnv :: reveal_all ( ) ,
@@ -514,18 +527,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
514527 self . monomorphize ( & op_ty)
515528 } ) . collect :: < Vec < _ > > ( ) ;
516529
517- let fn_abi = match def {
518- Some ( ty:: InstanceDef :: Virtual ( ..) ) => {
519- FnAbi :: new_vtable ( & bx, sig, & extra_args)
520- }
521- Some ( ty:: InstanceDef :: DropGlue ( _, None ) ) => {
522- // Empty drop glue; a no-op.
523- let & ( _, target) = destination. as_ref ( ) . unwrap ( ) ;
524- helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
525- helper. funclet_br ( self , & mut bx, target) ;
526- return ;
527- }
528- _ => FnAbi :: new ( & bx, sig, & extra_args)
530+ let fn_abi = match instance {
531+ Some ( instance) => FnAbi :: of_instance ( & bx, instance, & extra_args) ,
532+ None => FnAbi :: new ( & bx, sig, & extra_args)
529533 } ;
530534
531535 // Emit a panic or a no-op for `panic_if_uninhabited`.
@@ -541,7 +545,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
541545 let def_id =
542546 common:: langcall ( bx. tcx ( ) , Some ( span) , "" , lang_items:: PanicFnLangItem ) ;
543547 let instance = ty:: Instance :: mono ( bx. tcx ( ) , def_id) ;
544- let fn_abi = FnAbi :: of_instance ( & bx, instance) ;
548+ let fn_abi = FnAbi :: of_instance ( & bx, instance, & [ ] ) ;
545549 let llfn = bx. get_fn_addr ( instance) ;
546550
547551 if let Some ( ( _, target) ) = destination. as_ref ( ) {
0 commit comments