Skip to content

Commit 52e1372

Browse files
committed
Abort instead of panic in asserting intrinsics, because they might not be panic safe
1 parent 1b8979c commit 52e1372

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/shims/intrinsics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
440440
"assert_uninit_valid" => {
441441
let ty = substs.type_at(0);
442442
let layout = this.layout_of(ty)?;
443-
// Return here because we panicked instead of returning normally from the intrinsic.
443+
// Abort here because the caller might not be panic safe.
444444
if layout.abi.is_uninhabited() {
445-
return this.start_panic(&format!("attempted to instantiate uninhabited type `{}`", ty), unwind);
445+
throw_machine_stop!(TerminationInfo::Abort(Some(format!("attempted to instantiate uninhabited type `{}`", ty))))
446446
}
447447
if intrinsic_name == "assert_zero_valid" && !layout.might_permit_raw_init(this, /*zero:*/ true).unwrap() {
448-
return this.start_panic(&format!("attempted to zero-initialize type `{}`, which is invalid", ty), unwind);
448+
throw_machine_stop!(TerminationInfo::Abort(Some(format!("attempted to zero-initialize type `{}`, which is invalid", ty))))
449449
}
450450
if intrinsic_name == "assert_uninit_valid" && !layout.might_permit_raw_init(this, /*zero:*/ false).unwrap() {
451-
return this.start_panic(&format!("attempted to leave type `{}` uninitialized, which is invalid", ty), unwind);
451+
throw_machine_stop!(TerminationInfo::Abort(Some(format!("attempted to leave type `{}` uninitialized, which is invalid", ty))))
452452
}
453453
}
454454

0 commit comments

Comments
 (0)