@@ -21,7 +21,8 @@ mod simd;
21
21
pub ( crate ) use cpuid:: codegen_cpuid_call;
22
22
pub ( crate ) use llvm:: codegen_llvm_intrinsic_call;
23
23
24
- use rustc_middle:: ty:: layout:: HasParamEnv ;
24
+ use rustc_middle:: ty;
25
+ use rustc_middle:: ty:: layout:: { HasParamEnv , ValidityRequirement } ;
25
26
use rustc_middle:: ty:: print:: { with_no_trimmed_paths, with_no_visible_paths} ;
26
27
use rustc_middle:: ty:: subst:: SubstsRef ;
27
28
use rustc_span:: symbol:: { kw, sym, Symbol } ;
@@ -634,37 +635,35 @@ fn codegen_regular_intrinsic_call<'tcx>(
634
635
intrinsic_args ! ( fx, args => ( ) ; intrinsic) ;
635
636
636
637
let ty = substs. type_at ( 0 ) ;
637
- let layout = fx. layout_of ( ty) ;
638
- let do_panic = match intrinsic {
639
- sym:: assert_inhabited => layout. abi . is_uninhabited ( ) ,
640
- sym:: assert_zero_valid => !fx
641
- . tcx
642
- . permits_zero_init ( fx. param_env ( ) . and ( ty) )
643
- . expect ( "expected to have layout during codegen" ) ,
644
- sym:: assert_mem_uninitialized_valid => !fx
638
+
639
+ let requirement = ValidityRequirement :: from_intrinsic ( intrinsic) ;
640
+
641
+ if let Some ( requirement) = requirement {
642
+ let do_panic = !fx
645
643
. tcx
646
- . permits_uninit_init ( fx. param_env ( ) . and ( ty) )
647
- . expect ( "expected to have layout during codegen" ) ,
648
- _ => unreachable ! ( ) ,
649
- } ;
650
- if do_panic {
651
- let msg_str = with_no_visible_paths ! ( {
652
- with_no_trimmed_paths!( {
653
- if layout. abi. is_uninhabited( ) {
654
- // Use this error even for the other intrinsics as it is more precise.
655
- format!( "attempted to instantiate uninhabited type `{}`" , ty)
656
- } else if intrinsic == sym:: assert_zero_valid {
657
- format!( "attempted to zero-initialize type `{}`, which is invalid" , ty)
658
- } else {
659
- format!(
660
- "attempted to leave type `{}` uninitialized, which is invalid" ,
661
- ty
662
- )
663
- }
664
- } )
665
- } ) ;
666
- crate :: base:: codegen_panic_nounwind ( fx, & msg_str, source_info) ;
667
- return ;
644
+ . check_validity_requirement ( ( requirement, fx. param_env ( ) . and ( ty) ) )
645
+ . expect ( "expect to have layout during codegen" ) ;
646
+
647
+ if do_panic {
648
+ let layout = fx. layout_of ( ty) ;
649
+ let msg_str = with_no_visible_paths ! ( {
650
+ with_no_trimmed_paths!( {
651
+ if layout. abi. is_uninhabited( ) {
652
+ // Use this error even for the other intrinsics as it is more precise.
653
+ format!( "attempted to instantiate uninhabited type `{}`" , ty)
654
+ } else if intrinsic == sym:: assert_zero_valid {
655
+ format!( "attempted to zero-initialize type `{}`, which is invalid" , ty)
656
+ } else {
657
+ format!(
658
+ "attempted to leave type `{}` uninitialized, which is invalid" ,
659
+ ty
660
+ )
661
+ }
662
+ } )
663
+ } ) ;
664
+ crate :: base:: codegen_panic_nounwind ( fx, & msg_str, source_info) ;
665
+ return ;
666
+ }
668
667
}
669
668
}
670
669
0 commit comments