Skip to content

Commit 848e1d8

Browse files
committed
More work on miri_start_panic
1 parent fe88fc0 commit 848e1d8

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/libcore/intrinsics.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,12 @@ 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: u128) -> !;
1355+
// Note that the type is data is pretty arbitrary:
1356+
// we just need something that's guarnateed to be a fat
1357+
// pointer. Using `*mut [()]` instead of the actual type
1358+
// `*mut (Any + Send)` allows us to avoid making `Any` and `Send`
1359+
// lang items
1360+
pub fn miri_start_panic(data: *mut [()]) -> !;
13561361
}
13571362

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

src/libpanic_unwind/miri.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,19 @@ pub fn payload() -> *mut u8 {
66
}
77

88
pub unsafe fn panic(data: Box<dyn Any + Send>) -> ! {
9-
let raw_val = core::mem::transmute::<_, u128>(Box::into_raw(data));
9+
let raw_val: *mut [()] = core::mem::transmute::<*mut (dyn Any + Send), _>(Box::into_raw(data));
1010
core::intrinsics::miri_start_panic(raw_val)
1111
}
1212

1313
pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
1414
Box::from_raw(ptr)
1515
}
1616

17+
18+
// This is required by the compiler to exist (e.g., it's a lang item),
19+
// but is never used by Miri. Therefore, we just use a stub here
20+
#[lang = "eh_personality"]
21+
#[cfg(not(test))]
22+
fn rust_eh_personality() {
23+
unsafe { core::intrinsics::abort() }
24+
}

src/librustc_typeck/check/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) {
385385
}
386386

387387
"miri_start_panic" => {
388-
(0, vec![tcx.types.u128], tcx.types.never)
388+
(0, vec![tcx.mk_mut_ptr(tcx.mk_slice(tcx.mk_unit()))], tcx.types.never)
389389
}
390390

391391
ref other => {

0 commit comments

Comments
 (0)