Skip to content

Commit 02b66a1

Browse files
committed
libunwind_panic: adjust miri panic hack
1 parent 8f1bbd6 commit 02b66a1

File tree

4 files changed

+18
-59
lines changed

4 files changed

+18
-59
lines changed

src/libcore/intrinsics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1348,9 +1348,11 @@ extern "rust-intrinsic" {
13481348
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
13491349

13501350
/// Internal hook used by Miri to implement unwinding.
1351+
/// Compiles to a NOP during non-Miri codegen.
1352+
///
13511353
/// Perma-unstable: do not use
13521354
#[cfg(not(bootstrap))]
1353-
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> !;
1355+
pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
13541356
}
13551357

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

src/libpanic_unwind/lib.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ use core::raw;
3636
use core::panic::BoxMeUp;
3737

3838
cfg_if::cfg_if! {
39-
if #[cfg(miri)] {
40-
#[path = "miri.rs"]
41-
mod imp;
42-
} else if #[cfg(target_os = "emscripten")] {
39+
if #[cfg(target_os = "emscripten")] {
4340
#[path = "emcc.rs"]
4441
mod imp;
4542
} else if #[cfg(target_arch = "wasm32")] {
@@ -94,5 +91,14 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
9491
#[unwind(allowed)]
9592
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
9693
let payload = payload as *mut &mut dyn BoxMeUp;
97-
imp::panic(Box::from_raw((*payload).take_box()))
94+
let payload = (*payload).take_box();
95+
96+
// Miri panic support: cfg'd out of normal builds just to be sure.
97+
// When going through normal codegen, `miri_start_panic` is a NOP, so the
98+
// Miri-enabled sysroot still supports normal unwinding. But when executed in
99+
// Miri, this line initiates unwinding.
100+
#[cfg(miri)]
101+
core::intrinsics::miri_start_panic(payload);
102+
103+
imp::panic(Box::from_raw(payload))
98104
}

src/libpanic_unwind/miri.rs

-42
This file was deleted.

src/librustc_codegen_ssa/mir/block.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,11 @@ 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-
//
536-
// Note that we still need to be able to codegen *something* for this intrisnic:
537-
// Miri currently uses Xargo to build a special libstd. As a side effect,
538-
// we generate normal object files for libstd - while these are never used,
539-
// we still need to be able to build them.
531+
// For normal codegen, this Miri-specific intrinsic is just a NOP.
540532
if intrinsic == Some("miri_start_panic") {
541-
bx.abort();
542-
bx.unreachable();
533+
let target = destination.as_ref().unwrap().1;
534+
helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
535+
helper.funclet_br(self, &mut bx, target);
543536
return;
544537
}
545538

0 commit comments

Comments
 (0)