@@ -274,47 +274,26 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
274274 fx. bcx . switch_to_block ( failure) ;
275275 fx. bcx . ins ( ) . nop ( ) ;
276276
277- let location = fx
278- . get_caller_location ( bb_data. terminator ( ) . source_info . span )
279- . load_scalar ( fx) ;
280-
281- let args;
282- let lang_item = match msg {
277+ match msg {
283278 AssertKind :: BoundsCheck { ref len, ref index } => {
284279 let len = trans_operand ( fx, len) . load_scalar ( fx) ;
285280 let index = trans_operand ( fx, index) . load_scalar ( fx) ;
286- args = [ index, len, location] ;
287- rustc_hir:: LangItem :: PanicBoundsCheck
281+ let location = fx
282+ . get_caller_location ( bb_data. terminator ( ) . source_info . span )
283+ . load_scalar ( fx) ;
284+
285+ codegen_panic_inner (
286+ fx,
287+ rustc_hir:: LangItem :: PanicBoundsCheck ,
288+ & [ index, len, location] ,
289+ bb_data. terminator ( ) . source_info . span ,
290+ ) ;
288291 }
289292 _ => {
290293 let msg_str = msg. description ( ) ;
291- let msg_ptr = fx. anonymous_str ( "assert" , msg_str) ;
292- let msg_len = fx
293- . bcx
294- . ins ( )
295- . iconst ( fx. pointer_type , i64:: try_from ( msg_str. len ( ) ) . unwrap ( ) ) ;
296- args = [ msg_ptr, msg_len, location] ;
297- rustc_hir:: LangItem :: Panic
294+ codegen_panic ( fx, msg_str, bb_data. terminator ( ) . source_info . span ) ;
298295 }
299- } ;
300-
301- let def_id = fx. tcx . lang_items ( ) . require ( lang_item) . unwrap_or_else ( |s| {
302- fx. tcx
303- . sess
304- . span_fatal ( bb_data. terminator ( ) . source_info . span , & s)
305- } ) ;
306-
307- let instance = Instance :: mono ( fx. tcx , def_id) . polymorphize ( fx. tcx ) ;
308- let symbol_name = fx. tcx . symbol_name ( instance) . name ;
309-
310- fx. lib_call (
311- & * symbol_name,
312- vec ! [ fx. pointer_type, fx. pointer_type, fx. pointer_type] ,
313- vec ! [ ] ,
314- & args,
315- ) ;
316-
317- crate :: trap:: trap_unreachable ( fx, "panic lang item returned" ) ;
296+ }
318297 }
319298
320299 TerminatorKind :: SwitchInt {
@@ -997,3 +976,45 @@ pub(crate) fn trans_operand<'tcx>(
997976 Operand :: Constant ( const_) => crate :: constant:: trans_constant ( fx, const_) ,
998977 }
999978}
979+
980+ pub ( crate ) fn codegen_panic < ' tcx > (
981+ fx : & mut FunctionCx < ' _ , ' tcx , impl Backend > ,
982+ msg_str : & str ,
983+ span : Span ,
984+ ) {
985+ let location = fx. get_caller_location ( span) . load_scalar ( fx) ;
986+
987+ let msg_ptr = fx. anonymous_str ( "assert" , msg_str) ;
988+ let msg_len = fx
989+ . bcx
990+ . ins ( )
991+ . iconst ( fx. pointer_type , i64:: try_from ( msg_str. len ( ) ) . unwrap ( ) ) ;
992+ let args = [ msg_ptr, msg_len, location] ;
993+
994+ codegen_panic_inner ( fx, rustc_hir:: LangItem :: Panic , & args, span) ;
995+ }
996+
997+ pub ( crate ) fn codegen_panic_inner < ' tcx > (
998+ fx : & mut FunctionCx < ' _ , ' tcx , impl Backend > ,
999+ lang_item : rustc_hir:: LangItem ,
1000+ args : & [ Value ] ,
1001+ span : Span ,
1002+ ) {
1003+ let def_id = fx
1004+ . tcx
1005+ . lang_items ( )
1006+ . require ( lang_item)
1007+ . unwrap_or_else ( |s| fx. tcx . sess . span_fatal ( span, & s) ) ;
1008+
1009+ let instance = Instance :: mono ( fx. tcx , def_id) . polymorphize ( fx. tcx ) ;
1010+ let symbol_name = fx. tcx . symbol_name ( instance) . name ;
1011+
1012+ fx. lib_call (
1013+ & * symbol_name,
1014+ vec ! [ fx. pointer_type, fx. pointer_type, fx. pointer_type] ,
1015+ vec ! [ ] ,
1016+ args,
1017+ ) ;
1018+
1019+ crate :: trap:: trap_unreachable ( fx, "panic lang item returned" ) ;
1020+ }
0 commit comments