Skip to content

Commit c6ad186

Browse files
committed
Use panic_nounwind and panic_cannot_unwind where necessary
These were either regular unwinding panics or aborts in the past but got changed somewhat recently.
1 parent 6c58be8 commit c6ad186

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

src/base.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
466466
*destination,
467467
);
468468
}
469-
TerminatorKind::Resume | TerminatorKind::Abort => {
469+
TerminatorKind::Abort => {
470+
codegen_panic_cannot_unwind(fx, source_info);
471+
}
472+
TerminatorKind::Resume => {
470473
// FIXME implement unwinding
471474
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
472475
}
@@ -931,7 +934,28 @@ pub(crate) fn codegen_panic<'tcx>(
931934
codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, source_info.span);
932935
}
933936

934-
pub(crate) fn codegen_panic_inner<'tcx>(
937+
pub(crate) fn codegen_panic_nounwind<'tcx>(
938+
fx: &mut FunctionCx<'_, '_, 'tcx>,
939+
msg_str: &str,
940+
source_info: mir::SourceInfo,
941+
) {
942+
let msg_ptr = fx.anonymous_str(msg_str);
943+
let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
944+
let args = [msg_ptr, msg_len];
945+
946+
codegen_panic_inner(fx, rustc_hir::LangItem::PanicNounwind, &args, source_info.span);
947+
}
948+
949+
pub(crate) fn codegen_panic_cannot_unwind<'tcx>(
950+
fx: &mut FunctionCx<'_, '_, 'tcx>,
951+
source_info: mir::SourceInfo,
952+
) {
953+
let args = [];
954+
955+
codegen_panic_inner(fx, rustc_hir::LangItem::PanicCannotUnwind, &args, source_info.span);
956+
}
957+
958+
fn codegen_panic_inner<'tcx>(
935959
fx: &mut FunctionCx<'_, '_, 'tcx>,
936960
lang_item: rustc_hir::LangItem,
937961
args: &[Value],
@@ -948,11 +972,7 @@ pub(crate) fn codegen_panic_inner<'tcx>(
948972

949973
fx.lib_call(
950974
&*symbol_name,
951-
vec![
952-
AbiParam::new(fx.pointer_type),
953-
AbiParam::new(fx.pointer_type),
954-
AbiParam::new(fx.pointer_type),
955-
],
975+
args.iter().map(|&arg| AbiParam::new(fx.bcx.func.dfg.value_type(arg))).collect(),
956976
vec![],
957977
args,
958978
);

src/intrinsics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
649649
let layout = fx.layout_of(substs.type_at(0));
650650
if layout.abi.is_uninhabited() {
651651
with_no_trimmed_paths!({
652-
crate::base::codegen_panic(
652+
crate::base::codegen_panic_nounwind(
653653
fx,
654654
&format!("attempted to instantiate uninhabited type `{}`", layout.ty),
655655
source_info,
@@ -660,7 +660,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
660660

661661
if intrinsic == sym::assert_zero_valid && !fx.tcx.permits_zero_init(layout) {
662662
with_no_trimmed_paths!({
663-
crate::base::codegen_panic(
663+
crate::base::codegen_panic_nounwind(
664664
fx,
665665
&format!(
666666
"attempted to zero-initialize type `{}`, which is invalid",
@@ -676,7 +676,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
676676
&& !fx.tcx.permits_uninit_init(layout)
677677
{
678678
with_no_trimmed_paths!({
679-
crate::base::codegen_panic(
679+
crate::base::codegen_panic_nounwind(
680680
fx,
681681
&format!(
682682
"attempted to leave type `{}` uninitialized, which is invalid",

0 commit comments

Comments
 (0)