@@ -573,7 +573,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
573
573
mergeable_succ : bool ,
574
574
) -> MergingSucc {
575
575
let span = terminator. source_info . span ;
576
- let cond = self . codegen_operand ( bx, cond) . immediate ( ) ;
576
+ let mut cond = self . codegen_operand ( bx, cond) . immediate ( ) ;
577
577
let mut const_cond = bx. const_to_opt_u128 ( cond, false ) . map ( |c| c == 1 ) ;
578
578
579
579
// This case can currently arise only from functions marked
@@ -589,8 +589,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
589
589
return helper. funclet_br ( self , bx, target, mergeable_succ) ;
590
590
}
591
591
592
- // Pass the condition through llvm.expect for branch hinting.
593
- let cond = bx. expect ( cond, expected) ;
592
+ if bx. tcx ( ) . sess . opts . optimize != OptLevel :: No {
593
+ // Pass the condition through llvm.expect for branch hinting.
594
+ cond = bx. expect ( cond, expected) ;
595
+ }
594
596
595
597
// Create the failure block and the conditional branch to it.
596
598
let lltarget = helper. llbb_with_cleanup ( self , target) ;
@@ -609,30 +611,40 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
609
611
let location = self . get_caller_location ( bx, terminator. source_info ) . immediate ( ) ;
610
612
611
613
// Put together the arguments to the panic entry point.
612
- let ( lang_item, args) = match msg {
614
+ let ( lang_item, args, generic ) = match msg {
613
615
AssertKind :: BoundsCheck { ref len, ref index } => {
614
616
let len = self . codegen_operand ( bx, len) . immediate ( ) ;
615
617
let index = self . codegen_operand ( bx, index) . immediate ( ) ;
616
618
// It's `fn panic_bounds_check(index: usize, len: usize)`,
617
619
// and `#[track_caller]` adds an implicit third argument.
618
- ( LangItem :: PanicBoundsCheck , vec ! [ index, len, location] )
620
+ ( LangItem :: PanicBoundsCheck , vec ! [ index, len, location] , None )
619
621
}
620
622
AssertKind :: MisalignedPointerDereference { ref required, ref found } => {
621
623
let required = self . codegen_operand ( bx, required) . immediate ( ) ;
622
624
let found = self . codegen_operand ( bx, found) . immediate ( ) ;
623
625
// It's `fn panic_misaligned_pointer_dereference(required: usize, found: usize)`,
624
626
// and `#[track_caller]` adds an implicit third argument.
625
- ( LangItem :: PanicMisalignedPointerDereference , vec ! [ required, found, location] )
627
+ ( LangItem :: PanicMisalignedPointerDereference , vec ! [ required, found, location] , None )
628
+ }
629
+ AssertKind :: OccupiedNiche { ref found, ref start, ref end } => {
630
+ let found = self . codegen_operand ( bx, found) ;
631
+ let generic_arg = ty:: GenericArg :: from ( found. layout . ty ) ;
632
+ let found = found. immediate ( ) ;
633
+ let start = self . codegen_operand ( bx, start) . immediate ( ) ;
634
+ let end = self . codegen_operand ( bx, end) . immediate ( ) ;
635
+ // It's `fn panic_occupied_niche<T>(found: T, start: T, end: T)`,
636
+ // and `#[track_caller]` adds an implicit fourth argument.
637
+ ( LangItem :: PanicOccupiedNiche , vec ! [ found, start, end, location] , Some ( generic_arg) )
626
638
}
627
639
_ => {
628
640
let msg = bx. const_str ( msg. description ( ) ) ;
629
641
// It's `pub fn panic(expr: &str)`, with the wide reference being passed
630
642
// as two arguments, and `#[track_caller]` adds an implicit third argument.
631
- ( LangItem :: Panic , vec ! [ msg. 0 , msg. 1 , location] )
643
+ ( LangItem :: Panic , vec ! [ msg. 0 , msg. 1 , location] , None )
632
644
}
633
645
} ;
634
646
635
- let ( fn_abi, llfn) = common:: build_langcall ( bx, Some ( span) , lang_item) ;
647
+ let ( fn_abi, llfn) = common:: build_langcall ( bx, Some ( span) , lang_item, generic ) ;
636
648
637
649
// Codegen the actual panic invoke/call.
638
650
let merging_succ = helper. do_call ( self , bx, fn_abi, llfn, & args, None , unwind, & [ ] , false ) ;
@@ -651,7 +663,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
651
663
self . set_debug_loc ( bx, terminator. source_info ) ;
652
664
653
665
// Obtain the panic entry point.
654
- let ( fn_abi, llfn) = common:: build_langcall ( bx, Some ( span) , reason. lang_item ( ) ) ;
666
+ let ( fn_abi, llfn) = common:: build_langcall ( bx, Some ( span) , reason. lang_item ( ) , None ) ;
655
667
656
668
// Codegen the actual panic invoke/call.
657
669
let merging_succ = helper. do_call (
@@ -712,8 +724,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
712
724
let msg = bx. const_str ( & msg_str) ;
713
725
714
726
// Obtain the panic entry point.
715
- let ( fn_abi, llfn) =
716
- common:: build_langcall ( bx, Some ( source_info. span ) , LangItem :: PanicNounwind ) ;
727
+ let ( fn_abi, llfn) = common:: build_langcall (
728
+ bx,
729
+ Some ( source_info. span ) ,
730
+ LangItem :: PanicNounwind ,
731
+ None ,
732
+ ) ;
717
733
718
734
// Codegen the actual panic invoke/call.
719
735
helper. do_call (
@@ -1622,7 +1638,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1622
1638
1623
1639
self . set_debug_loc ( & mut bx, mir:: SourceInfo :: outermost ( self . mir . span ) ) ;
1624
1640
1625
- let ( fn_abi, fn_ptr) = common:: build_langcall ( & bx, None , reason. lang_item ( ) ) ;
1641
+ let ( fn_abi, fn_ptr) = common:: build_langcall ( & bx, None , reason. lang_item ( ) , None ) ;
1626
1642
let fn_ty = bx. fn_decl_backend_type ( & fn_abi) ;
1627
1643
1628
1644
let llret = bx. call ( fn_ty, None , Some ( & fn_abi) , fn_ptr, & [ ] , funclet. as_ref ( ) ) ;
0 commit comments