diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2019-10-29 17:31:54 -0400 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2019-11-11 15:14:34 -0500 |
| commit | fe88fc03c50be57e1dc12cf308c45dc9c8d6473a (patch) | |
| tree | eff576f45f27f9afa4c17e7736bc83128e4a7a42 /src | |
| parent | caf3cc1fc88430caa61a8f1ae0262c3489a6481a (diff) | |
| download | rust-fe88fc03c50be57e1dc12cf308c45dc9c8d6473a.tar.gz rust-fe88fc03c50be57e1dc12cf308c45dc9c8d6473a.zip | |
Fix up intrinsic implementation
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/intrinsics.rs | 2 | ||||
| -rw-r--r-- | src/libpanic_unwind/miri.rs | 8 | ||||
| -rw-r--r-- | src/librustc_codegen_ssa/mir/block.rs | 10 | ||||
| -rw-r--r-- | src/librustc_typeck/check/intrinsic.rs | 4 |
4 files changed, 21 insertions, 3 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index f4a1ff0dd00..0cfe5595af5 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -1352,7 +1352,7 @@ extern "rust-intrinsic" { /// Internal hook used by Miri to implement unwinding. /// Perma-unstable: do not use #[cfg(not(bootstrap))] - pub fn miri_start_panic(data: *mut (dyn crate::any::Any + Send)) -> !; + pub fn miri_start_panic(data: u128) -> !; } // Some functions are defined here because they accidentally got made diff --git a/src/libpanic_unwind/miri.rs b/src/libpanic_unwind/miri.rs index a2d52638e8b..3b4203c3c6d 100644 --- a/src/libpanic_unwind/miri.rs +++ b/src/libpanic_unwind/miri.rs @@ -1,9 +1,13 @@ +use core::any::Any; +use alloc::boxed::Box; + pub fn payload() -> *mut u8 { core::ptr::null_mut() } -pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 { - core::intrinsics::miri_start_panic(Box::into_raw(data)) +pub unsafe fn panic(data: Box<dyn Any + Send>) -> ! { + let raw_val = core::mem::transmute::<_, u128>(Box::into_raw(data)); + core::intrinsics::miri_start_panic(raw_val) } pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> { diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 13cd202158b..9361a7c3ea4 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -528,6 +528,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { _ => FnAbi::new(&bx, sig, &extra_args) }; + // This should never be reachable at runtime: + // We should only emit a call to this intrinsic in #[cfg(miri)] mode, + // which means that we will never actually use the generate object files + // (we will just be interpreting the MIR) + if intrinsic == Some("miri_start_panic") { + bx.abort(); + bx.unreachable(); + return; + } + // Emit a panic or a no-op for `panic_if_uninhabited`. if intrinsic == Some("panic_if_uninhabited") { let ty = instance.unwrap().substs.type_at(0); diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 1a1b98f582f..24b589df63a 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -384,6 +384,10 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem) { (1, vec![ tcx.mk_mut_ptr(param(0)), param(0) ], tcx.mk_unit()) } + "miri_start_panic" => { + (0, vec![tcx.types.u128], tcx.types.never) + } + ref other => { struct_span_err!(tcx.sess, it.span, E0093, "unrecognized intrinsic function: `{}`", |
