@@ -345,20 +345,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
345
345
& args1[ ..]
346
346
} ;
347
347
let ( drop_fn, fn_abi) = match ty. kind {
348
+ // FIXME(eddyb) perhaps move some of this logic into
349
+ // `Instance::resolve_drop_in_place`?
348
350
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, & [ ] ) ;
355
356
let vtable = args[ 1 ] ;
356
357
args = & args[ ..1 ] ;
357
358
( meth:: DESTRUCTOR . get_fn ( & mut bx, vtable, & fn_abi) , fn_abi)
358
359
}
359
360
_ => {
360
361
( bx. get_fn_addr ( drop_fn) ,
361
- FnAbi :: of_instance ( & bx, drop_fn) )
362
+ FnAbi :: of_instance ( & bx, drop_fn, & [ ] ) )
362
363
}
363
364
} ;
364
365
helper. maybe_sideeffect ( self . mir , & mut bx, & [ target] ) ;
@@ -439,7 +440,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
439
440
// Obtain the panic entry point.
440
441
let def_id = common:: langcall ( bx. tcx ( ) , Some ( span) , "" , lang_item) ;
441
442
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, & [ ] ) ;
443
444
let llfn = bx. get_fn_addr ( instance) ;
444
445
445
446
// Codegen the actual panic invoke/call.
@@ -474,6 +475,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474
475
_ => bug ! ( "{} is not callable" , callee. layout. ty) ,
475
476
} ;
476
477
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`.
477
490
let sig = callee. layout . ty . fn_sig ( bx. tcx ( ) ) ;
478
491
let sig = bx. tcx ( ) . normalize_erasing_late_bound_regions (
479
492
ty:: ParamEnv :: reveal_all ( ) ,
@@ -514,18 +527,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
514
527
self . monomorphize ( & op_ty)
515
528
} ) . collect :: < Vec < _ > > ( ) ;
516
529
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)
529
533
} ;
530
534
531
535
// 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> {
541
545
let def_id =
542
546
common:: langcall ( bx. tcx ( ) , Some ( span) , "" , lang_items:: PanicFnLangItem ) ;
543
547
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, & [ ] ) ;
545
549
let llfn = bx. get_fn_addr ( instance) ;
546
550
547
551
if let Some ( ( _, target) ) = destination. as_ref ( ) {
0 commit comments