-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider using Miri #1
Comments
Oh wow, I didn't know the Rust's team bot runs my package :) Looking at the creater run
I can see that the failure comes from here: Lines 454 to 458 in 390a615
I mostly stopped using
Lines 179 to 183 in 390a615
Line 18 in 390a615
Try this simple code to see if your compiler issue reproduces. type Byte = u8;
type Cell = isize;
#[repr(packed(1))]
struct CountedString {
len: Byte,
data: [Byte; 0],
}
fn test() {
let buffer: [u8; 6] = [5, b'h', b'e', b'l', b'l', b'o'];
let counted_string_address: Cell = (&buffer).as_ptr() as Cell;
let counted_string: &CountedString = unsafe {
std::mem::transmute::<Cell, *const CountedString>(counted_string_address)
.as_ref()
.unwrap()
};
let counted_string_as_slice: &[u8] = unsafe {
std::slice::from_raw_parts(counted_string.data.as_ptr(), counted_string.len as usize)
};
let counted_string_as_rust_string = std::str::from_utf8(counted_string_as_slice).unwrap();
println!("{}", counted_string_as_rust_string);
}
This crate is an implementation for a programming language that isn't safe :P
I wasn't familiar with miri until now, looks interesting, I'll check it when I'll have some free time. |
When compiled with my patch that code crashes with a SIGILL at runtime.
Well yes, but presumably you want your interpreter to not crash :P
By default, Miri has a more picky aliasing model (we're not sure what the aliasing model is for Rust yet, so the default is the one that's more paranoid). So Miri immediately complains about the Miri immediately complains about an alignment issue; it looks like you're trying to treat an allocation which was allocated as a All UB is fatal to Miri, because in almost all cases successfully executing UB in the interpreter would corrupts its internal data structures. Engineering an interpreter with the depths of checks that Miri has that can keep going past invalid execution is a bit beyond us at the moment. |
This crate executes multiple kinds of UB. I ran into it doing a crater run for this PR: rust-lang/rust#121282 which improves the optimization of transmutes from integer to pointer types.
I haven't been able to diagnose exactly why that PR breaks this crate, because in running Miri on this crate I run into other problems that I'm not sure how to fix.
To get started with Miri, you'll need a nightly toolchain because Miri isn't available on stable yet.
Then you can run
cargo +nightly miri test
, for this repo I suggest you start by adding the environment variable to disable aliasing analysis, because that will let you skip some of the more complicated forms of UB. For example,MIRIFLAGS=-Zmiri-disable-stacked-borrows cargo +nightly miri test
. Miri has decent documentation in its README: https://github.com/rust-lang/miriThe text was updated successfully, but these errors were encountered: