@@ -463,6 +463,55 @@ impl FunctionCx<'a, 'll, 'tcx> {
463463 return ;
464464 }
465465
466+ if ( intrinsic == Some ( "init" ) || intrinsic == Some ( "uninit" ) ) &&
467+ bx. cx . layout_of ( sig. output ( ) ) . abi . is_uninhabited ( )
468+ {
469+ let loc = bx. sess ( ) . codemap ( ) . lookup_char_pos ( span. lo ( ) ) ;
470+ let filename = Symbol :: intern ( & loc. file . name . to_string ( ) ) . as_str ( ) ;
471+ let filename = C_str_slice ( bx. cx , filename) ;
472+ let line = C_u32 ( bx. cx , loc. line as u32 ) ;
473+ let col = C_u32 ( bx. cx , loc. col . to_usize ( ) as u32 + 1 ) ;
474+ let align = tcx. data_layout . aggregate_align
475+ . max ( tcx. data_layout . i32_align )
476+ . max ( tcx. data_layout . pointer_align ) ;
477+
478+ let str = if intrinsic == Some ( "init" ) {
479+ "Attempted to instantiate an uninhabited type (e.g. `!`) \
480+ using mem::zeroed()"
481+ } else {
482+ "Attempted to instantiate an uninhabited type (e.g. `!`) \
483+ using mem::uninitialized()"
484+ } ;
485+ let msg_str = Symbol :: intern ( str) . as_str ( ) ;
486+ let msg_str = C_str_slice ( bx. cx , msg_str) ;
487+ let msg_file_line_col = C_struct ( bx. cx ,
488+ & [ msg_str, filename, line, col] ,
489+ false ) ;
490+ let msg_file_line_col = consts:: addr_of ( bx. cx ,
491+ msg_file_line_col,
492+ align,
493+ Some ( "panic_loc" ) ) ;
494+
495+ // Obtain the panic entry point.
496+ let def_id =
497+ common:: langcall ( bx. tcx ( ) , Some ( span) , "" , lang_items:: PanicFnLangItem ) ;
498+ let instance = ty:: Instance :: mono ( bx. tcx ( ) , def_id) ;
499+ let fn_ty = FnType :: of_instance ( bx. cx , & instance) ;
500+ let llfn = callee:: get_fn ( bx. cx , instance) ;
501+
502+ // Codegen the actual panic invoke/call.
503+ do_call (
504+ self ,
505+ bx,
506+ fn_ty,
507+ llfn,
508+ & [ msg_file_line_col] ,
509+ destination. as_ref ( ) . map ( |( _, bb) | ( ReturnDest :: Nothing , * bb) ) ,
510+ cleanup,
511+ ) ;
512+ return ;
513+ }
514+
466515 let extra_args = & args[ sig. inputs ( ) . len ( ) ..] ;
467516 let extra_args = extra_args. iter ( ) . map ( |op_arg| {
468517 let op_ty = op_arg. ty ( self . mir , bx. tcx ( ) ) ;
0 commit comments