Skip to content

Commit fe88fc0

Browse files
committed
Fix up intrinsic implementation
1 parent caf3cc1 commit fe88fc0

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

src/libcore/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ extern "rust-intrinsic" {
13521352
/// Internal hook used by Miri to implement unwinding.
13531353
/// Perma-unstable: do not use
13541354
#[cfg(not(bootstrap))]
1355-
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + Send)) -> !;
1355+
pub fn miri_start_panic(data: u128) -> !;
13561356
}
13571357

13581358
// Some functions are defined here because they accidentally got made

src/libpanic_unwind/miri.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
use core::any::Any;
2+
use alloc::boxed::Box;
3+
14
pub fn payload() -> *mut u8 {
25
core::ptr::null_mut()
36
}
47

5-
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
6-
core::intrinsics::miri_start_panic(Box::into_raw(data))
8+
pub unsafe fn panic(data: Box<dyn Any + Send>) -> ! {
9+
let raw_val = core::mem::transmute::<_, u128>(Box::into_raw(data));
10+
core::intrinsics::miri_start_panic(raw_val)
711
}
812

913
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
528528
_ => FnAbi::new(&bx, sig, &extra_args)
529529
};
530530

531+
// This should never be reachable at runtime:
532+
// We should only emit a call to this intrinsic in #[cfg(miri)] mode,
533+
// which means that we will never actually use the generate object files
534+
// (we will just be interpreting the MIR)
535+
if intrinsic == Some("miri_start_panic") {
536+
bx.abort();
537+
bx.unreachable();
538+
return;
539+
}
540+
531541
// Emit a panic or a no-op for `panic_if_uninhabited`.
532542
if intrinsic == Some("panic_if_uninhabited") {
533543
let ty = instance.unwrap().substs.type_at(0);

src/librustc_typeck/check/intrinsic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
384384
(1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_unit())
385385
}
386386

387+
"miri_start_panic" => {
388+
(0, vec![tcx.types.u128], tcx.types.never)
389+
}
390+
387391
ref other => {
388392
struct_span_err!(tcx.sess, it.span, E0093,
389393
"unrecognized intrinsic function: `{}`",

0 commit comments

Comments
 (0)