@@ -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 ;
@@ -680,7 +680,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
680680 & mut self ,
681681 helper : & TerminatorCodegenHelper < ' tcx > ,
682682 bx : & mut Bx ,
683- intrinsic : Option < Symbol > ,
683+ intrinsic : Option < ty :: IntrinsicDef > ,
684684 instance : Option < Instance < ' tcx > > ,
685685 source_info : mir:: SourceInfo ,
686686 target : Option < mir:: BasicBlock > ,
@@ -690,7 +690,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
690690 // Emit a panic or a no-op for `assert_*` intrinsics.
691691 // These are intrinsics that compile to panics so that we can get a message
692692 // which mentions the offending type, even from a const context.
693- let panic_intrinsic = intrinsic. and_then ( |s | ValidityRequirement :: from_intrinsic ( s ) ) ;
693+ let panic_intrinsic = intrinsic. and_then ( |i | ValidityRequirement :: from_intrinsic ( i . name ) ) ;
694694 if let Some ( requirement) = panic_intrinsic {
695695 let ty = instance. unwrap ( ) . args . type_at ( 0 ) ;
696696
@@ -826,14 +826,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
826826 // The arguments we'll be passing. Plus one to account for outptr, if used.
827827 let arg_count = fn_abi. args . len ( ) + fn_abi. ret . is_indirect ( ) as usize ;
828828
829- if intrinsic == Some ( sym:: caller_location) {
829+ if matches ! ( intrinsic, Some ( ty :: IntrinsicDef { name : sym:: caller_location, .. } ) ) {
830830 return if let Some ( target) = target {
831831 let location =
832832 self . get_caller_location ( bx, mir:: SourceInfo { span : fn_span, ..source_info } ) ;
833833
834834 let mut llargs = Vec :: with_capacity ( arg_count) ;
835- let ret_dest =
836- self . make_return_dest ( bx, destination, & fn_abi. ret , & mut llargs, true , true ) ;
835+ let ret_dest = self . make_return_dest (
836+ bx,
837+ destination,
838+ & fn_abi. ret ,
839+ & mut llargs,
840+ intrinsic,
841+ Some ( target) ,
842+ ) ;
837843 assert_eq ! ( llargs, [ ] ) ;
838844 if let ReturnDest :: IndirectOperand ( tmp, _) = ret_dest {
839845 location. val . store ( bx, tmp) ;
@@ -846,16 +852,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
846852 }
847853
848854 let instance = match intrinsic {
849- None | Some ( sym:: drop_in_place) => instance,
855+ None | Some ( ty :: IntrinsicDef { name : sym:: drop_in_place, .. } ) => instance,
850856 Some ( intrinsic) => {
851857 let mut llargs = Vec :: with_capacity ( 1 ) ;
852858 let ret_dest = self . make_return_dest (
853859 bx,
854860 destination,
855861 & fn_abi. ret ,
856862 & mut llargs,
857- true ,
858- target. is_some ( ) ,
863+ Some ( intrinsic ) ,
864+ target,
859865 ) ;
860866 let dest = match ret_dest {
861867 _ if fn_abi. ret . is_indirect ( ) => llargs[ 0 ] ,
@@ -873,7 +879,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
873879 // The indices passed to simd_shuffle in the
874880 // third argument must be constant. This is
875881 // checked by the type-checker.
876- if i == 2 && intrinsic == sym:: simd_shuffle {
882+ if i == 2 && intrinsic. name == sym:: simd_shuffle {
877883 if let mir:: Operand :: Constant ( constant) = & arg. node {
878884 let ( llval, ty) = self . simd_shuffle_indices ( bx, constant) ;
879885 return OperandRef {
@@ -903,14 +909,33 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
903909 MergingSucc :: False
904910 } ;
905911 }
906- Err ( instance) => Some ( instance) ,
912+ Err ( instance) => {
913+ if intrinsic. must_be_overridden {
914+ span_bug ! (
915+ span,
916+ "intrinsic {} must be overridden by codegen backend, but isn't" ,
917+ intrinsic. name,
918+ ) ;
919+ }
920+ Some ( instance)
921+ }
907922 }
908923 }
909924 } ;
910925
911926 let mut llargs = Vec :: with_capacity ( arg_count) ;
912927 let destination = target. as_ref ( ) . map ( |& target| {
913- ( self . make_return_dest ( bx, destination, & fn_abi. ret , & mut llargs, false , true ) , target)
928+ (
929+ self . make_return_dest (
930+ bx,
931+ destination,
932+ & fn_abi. ret ,
933+ & mut llargs,
934+ None ,
935+ Some ( target) ,
936+ ) ,
937+ target,
938+ )
914939 } ) ;
915940
916941 // Split the rust-call tupled arguments off.
@@ -1643,10 +1668,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16431668 dest : mir:: Place < ' tcx > ,
16441669 fn_ret : & ArgAbi < ' tcx , Ty < ' tcx > > ,
16451670 llargs : & mut Vec < Bx :: Value > ,
1646- is_intrinsic : bool ,
1647- has_target : bool ,
1671+ intrinsic : Option < ty :: IntrinsicDef > ,
1672+ target : Option < BasicBlock > ,
16481673 ) -> ReturnDest < ' tcx , Bx :: Value > {
1649- if !has_target {
1674+ if target . is_none ( ) {
16501675 return ReturnDest :: Nothing ;
16511676 }
16521677 // If the return is ignored, we can just return a do-nothing `ReturnDest`.
@@ -1667,7 +1692,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16671692 tmp. storage_live ( bx) ;
16681693 llargs. push ( tmp. llval ) ;
16691694 ReturnDest :: IndirectOperand ( tmp, index)
1670- } else if is_intrinsic {
1695+ } else if intrinsic . is_some ( ) {
16711696 // Currently, intrinsics always need a location to store
16721697 // the result, so we create a temporary `alloca` for the
16731698 // result.
0 commit comments