@@ -12,12 +12,12 @@ use crate::MemFlags;
1212use rustc_ast as ast;
1313use rustc_ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
1414use rustc_hir:: lang_items:: LangItem ;
15- use rustc_middle:: mir:: { self , AssertKind , SwitchTargets , UnwindTerminateReason } ;
15+ use rustc_middle:: mir:: { self , AssertKind , BasicBlock , SwitchTargets , UnwindTerminateReason } ;
1616use rustc_middle:: ty:: layout:: { HasTyCtxt , LayoutOf , ValidityRequirement } ;
1717use rustc_middle:: ty:: print:: { with_no_trimmed_paths, with_no_visible_paths} ;
1818use rustc_middle:: ty:: { self , Instance , Ty } ;
1919use rustc_session:: config:: OptLevel ;
20- use rustc_span:: { source_map:: Spanned , sym, Span , Symbol } ;
20+ use rustc_span:: { source_map:: Spanned , sym, Span } ;
2121use rustc_target:: abi:: call:: { ArgAbi , FnAbi , PassMode , Reg } ;
2222use rustc_target:: abi:: { self , HasDataLayout , WrappingRange } ;
2323use rustc_target:: spec:: abi:: Abi ;
@@ -672,7 +672,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
672672 & mut self ,
673673 helper : & TerminatorCodegenHelper < ' tcx > ,
674674 bx : & mut Bx ,
675- intrinsic : Option < Symbol > ,
675+ intrinsic : Option < ty :: IntrinsicDef > ,
676676 instance : Option < Instance < ' tcx > > ,
677677 source_info : mir:: SourceInfo ,
678678 target : Option < mir:: BasicBlock > ,
@@ -682,7 +682,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
682682 // Emit a panic or a no-op for `assert_*` intrinsics.
683683 // These are intrinsics that compile to panics so that we can get a message
684684 // which mentions the offending type, even from a const context.
685- let panic_intrinsic = intrinsic. and_then ( |s | ValidityRequirement :: from_intrinsic ( s ) ) ;
685+ let panic_intrinsic = intrinsic. and_then ( |i | ValidityRequirement :: from_intrinsic ( i . name ) ) ;
686686 if let Some ( requirement) = panic_intrinsic {
687687 let ty = instance. unwrap ( ) . args . type_at ( 0 ) ;
688688
@@ -818,14 +818,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
818818 // The arguments we'll be passing. Plus one to account for outptr, if used.
819819 let arg_count = fn_abi. args . len ( ) + fn_abi. ret . is_indirect ( ) as usize ;
820820
821- if intrinsic == Some ( sym:: caller_location) {
821+ if matches ! ( intrinsic, Some ( ty :: IntrinsicDef { name : sym:: caller_location, .. } ) ) {
822822 return if let Some ( target) = target {
823823 let location =
824824 self . get_caller_location ( bx, mir:: SourceInfo { span : fn_span, ..source_info } ) ;
825825
826826 let mut llargs = Vec :: with_capacity ( arg_count) ;
827- let ret_dest =
828- self . make_return_dest ( bx, destination, & fn_abi. ret , & mut llargs, true , true ) ;
827+ let ret_dest = self . make_return_dest (
828+ bx,
829+ destination,
830+ & fn_abi. ret ,
831+ & mut llargs,
832+ intrinsic,
833+ Some ( target) ,
834+ ) ;
829835 assert_eq ! ( llargs, [ ] ) ;
830836 if let ReturnDest :: IndirectOperand ( tmp, _) = ret_dest {
831837 location. val . store ( bx, tmp) ;
@@ -838,16 +844,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
838844 }
839845
840846 let instance = match intrinsic {
841- None | Some ( sym:: drop_in_place) => instance,
847+ None | Some ( ty :: IntrinsicDef { name : sym:: drop_in_place, .. } ) => instance,
842848 Some ( intrinsic) => {
843849 let mut llargs = Vec :: with_capacity ( 1 ) ;
844850 let ret_dest = self . make_return_dest (
845851 bx,
846852 destination,
847853 & fn_abi. ret ,
848854 & mut llargs,
849- true ,
850- target. is_some ( ) ,
855+ Some ( intrinsic ) ,
856+ target,
851857 ) ;
852858 let dest = match ret_dest {
853859 _ if fn_abi. ret . is_indirect ( ) => llargs[ 0 ] ,
@@ -866,7 +872,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
866872 // third argument must be constant. This is
867873 // checked by const-qualification, which also
868874 // promotes any complex rvalues to constants.
869- if i == 2 && intrinsic == sym:: simd_shuffle {
875+ if i == 2 && intrinsic. name == sym:: simd_shuffle {
870876 if let mir:: Operand :: Constant ( constant) = & arg. node {
871877 let ( llval, ty) = self . simd_shuffle_indices ( bx, constant) ;
872878 return OperandRef {
@@ -896,14 +902,33 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
896902 MergingSucc :: False
897903 } ;
898904 }
899- Err ( instance) => Some ( instance) ,
905+ Err ( instance) => {
906+ if intrinsic. must_be_overridden {
907+ span_bug ! (
908+ span,
909+ "intrinsic {} must be overridden by codegen backend, but isn't" ,
910+ intrinsic. name,
911+ ) ;
912+ }
913+ Some ( instance)
914+ }
900915 }
901916 }
902917 } ;
903918
904919 let mut llargs = Vec :: with_capacity ( arg_count) ;
905920 let destination = target. as_ref ( ) . map ( |& target| {
906- ( self . make_return_dest ( bx, destination, & fn_abi. ret , & mut llargs, false , true ) , target)
921+ (
922+ self . make_return_dest (
923+ bx,
924+ destination,
925+ & fn_abi. ret ,
926+ & mut llargs,
927+ None ,
928+ Some ( target) ,
929+ ) ,
930+ target,
931+ )
907932 } ) ;
908933
909934 // Split the rust-call tupled arguments off.
@@ -1636,10 +1661,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16361661 dest : mir:: Place < ' tcx > ,
16371662 fn_ret : & ArgAbi < ' tcx , Ty < ' tcx > > ,
16381663 llargs : & mut Vec < Bx :: Value > ,
1639- is_intrinsic : bool ,
1640- has_target : bool ,
1664+ intrinsic : Option < ty :: IntrinsicDef > ,
1665+ target : Option < BasicBlock > ,
16411666 ) -> ReturnDest < ' tcx , Bx :: Value > {
1642- if !has_target {
1667+ if target . is_none ( ) {
16431668 return ReturnDest :: Nothing ;
16441669 }
16451670 // If the return is ignored, we can just return a do-nothing `ReturnDest`.
@@ -1660,7 +1685,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16601685 tmp. storage_live ( bx) ;
16611686 llargs. push ( tmp. llval ) ;
16621687 ReturnDest :: IndirectOperand ( tmp, index)
1663- } else if is_intrinsic {
1688+ } else if intrinsic . is_some ( ) {
16641689 // Currently, intrinsics always need a location to store
16651690 // the result, so we create a temporary `alloca` for the
16661691 // result.
0 commit comments