Skip to content

Commit cceea84

Browse files
committed
Sync from rust 44cfafe
2 parents 162365e + 1b57cb6 commit cceea84

File tree

1 file changed

+30
-31
lines changed

1 file changed

+30
-31
lines changed

src/intrinsics/mod.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ mod simd;
2121
pub(crate) use cpuid::codegen_cpuid_call;
2222
pub(crate) use llvm::codegen_llvm_intrinsic_call;
2323

24-
use rustc_middle::ty::layout::HasParamEnv;
24+
use rustc_middle::ty;
25+
use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
2526
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
2627
use rustc_middle::ty::subst::SubstsRef;
2728
use rustc_span::symbol::{kw, sym, Symbol};
@@ -634,37 +635,35 @@ fn codegen_regular_intrinsic_call<'tcx>(
634635
intrinsic_args!(fx, args => (); intrinsic);
635636

636637
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
645643
.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+
}
668667
}
669668
}
670669

0 commit comments

Comments
 (0)