mod windows;
mod posix;
-use std::{convert::TryInto, iter};
+use std::{convert::{TryInto, TryFrom}, iter};
use rustc_hir::def_id::DefId;
use rustc::mir;
// Second: some functions that we forward to MIR implementations.
match link_name {
- // This matches calls to the *foreign* item `__rust_start_panic*, that is,
- // calls to `extern "Rust" { fn __rust_start_panic(...) }`.
+ // This matches calls to the foreign item `__rust_start_panic`, that is,
+ // calls to `extern "Rust" { fn __rust_start_panic(...) }`
+ // (and `__rust_panic_cleanup`, respectively).
// We forward this to the underlying *implementation* in the panic runtime crate.
// Normally, this will be either `libpanic_unwind` or `libpanic_abort`, but it could
// also be a custom user-provided implementation via `#![feature(panic_runtime)]`
- "__rust_start_panic" => {
+ "__rust_start_panic" | "__rust_panic_cleanup"=> {
// FIXME we might want to cache this... but it's not really performance-critical.
let panic_runtime = tcx
.crates()
.expect("No panic runtime found!");
let panic_runtime = tcx.crate_name(*panic_runtime);
let start_panic_instance =
- this.resolve_path(&[&*panic_runtime.as_str(), "__rust_start_panic"])?;
+ this.resolve_path(&[&*panic_runtime.as_str(), link_name])?;
return Ok(Some(&*this.load_mir(start_panic_instance.def, None)?));
}
_ => {}
MiriMemoryKind::Rust.into(),
);
// We just allocated this, the access is definitely in-bounds.
- this.memory.write_bytes(ptr.into(), iter::repeat(0u8).take(size as usize)).unwrap();
+ this.memory.write_bytes(ptr.into(), iter::repeat(0u8).take(usize::try_from(size).unwrap())).unwrap();
this.write_scalar(ptr, dest)?;
}
"__rust_dealloc" => {
this.write_scalar(new_ptr, dest)?;
}
- "__rust_maybe_catch_panic" => {
- this.handle_catch_panic(args, dest, ret)?;
- return Ok(false);
- }
-
"memcmp" => {
let left = this.read_scalar(args[0])?.not_undef()?;
let right = this.read_scalar(args[1])?.not_undef()?;
"strlen" => {
let ptr = this.read_scalar(args[0])?.not_undef()?;
let n = this.memory.read_c_str(ptr)?.len();
- this.write_scalar(Scalar::from_uint(n as u64, dest.layout.size), dest)?;
+ this.write_scalar(Scalar::from_uint(u64::try_from(n).unwrap(), dest.layout.size), dest)?;
}
// math functions
// Saturating cast to i16. Even those are outside the valid exponent range to
// `scalbn` below will do its over/underflow handling.
- let exp = if exp > i16::MAX as i32 {
+ let exp = if exp > i32::from(i16::MAX) {
i16::MAX
- } else if exp < i16::MIN as i32 {
+ } else if exp < i32::from(i16::MIN) {
i16::MIN
} else {
exp.try_into().unwrap()