1
Fork 0

Fix up intrinsic implementation

This commit is contained in:
Aaron Hill 2019-10-29 17:31:54 -04:00
parent caf3cc1fc8
commit fe88fc03c5
No known key found for this signature in database
GPG key ID: B4087E510E98B164
4 changed files with 21 additions and 3 deletions

View file

@ -1352,7 +1352,7 @@ extern "rust-intrinsic" {
/// Internal hook used by Miri to implement unwinding. /// Internal hook used by Miri to implement unwinding.
/// Perma-unstable: do not use /// Perma-unstable: do not use
#[cfg(not(bootstrap))] #[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 // Some functions are defined here because they accidentally got made

View file

@ -1,9 +1,13 @@
use core::any::Any;
use alloc::boxed::Box;
pub fn payload() -> *mut u8 { pub fn payload() -> *mut u8 {
core::ptr::null_mut() core::ptr::null_mut()
} }
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 { pub unsafe fn panic(data: Box<dyn Any + Send>) -> ! {
core::intrinsics::miri_start_panic(Box::into_raw(data)) 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> { pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {

View file

@ -528,6 +528,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
_ => FnAbi::new(&bx, sig, &extra_args) _ => 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`. // Emit a panic or a no-op for `panic_if_uninhabited`.
if intrinsic == Some("panic_if_uninhabited") { if intrinsic == Some("panic_if_uninhabited") {
let ty = instance.unwrap().substs.type_at(0); let ty = instance.unwrap().substs.type_at(0);

View file

@ -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()) (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 => { ref other => {
struct_span_err!(tcx.sess, it.span, E0093, struct_span_err!(tcx.sess, it.span, E0093,
"unrecognized intrinsic function: `{}`", "unrecognized intrinsic function: `{}`",