Skip to content

Commit 009525d

Browse files
authored
Merge branch 'master' into hack_branch_for_miri_do_not_delete_until_merged
2 parents 022bd13 + d7ddad6 commit 009525d

File tree

7 files changed

+44
-49
lines changed

7 files changed

+44
-49
lines changed

README.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,6 @@ how to fix it, you could send a PR. :smile:
4040
cargo run --bin miri tests/run-pass-fullmir/vecs.rs # Or whatever test you like.
4141
```
4242

43-
## Debugging
44-
45-
Since the heart of miri (the main interpreter engine) lives in rustc, tracing
46-
the interpreter requires a version of rustc compiled with tracing. To this
47-
end, you will have to compile your own rustc:
48-
```
49-
git clone https://github.com/rust-lang/rust/ rustc
50-
cd rustc
51-
cp config.toml.example config.toml
52-
# Now edit `config.toml` and set `debug-assertions = true`
53-
./x.py build src/rustc
54-
rustup toolchain link custom build/x86_64-unknown-linux-gnu/stage2
55-
```
56-
The `build` step can take 30 to 60 minutes.
57-
58-
Now, in the miri directory, you can `rustup override set custom` and re-build
59-
everything. Finally, if you now set `RUST_LOG=rustc_mir::interpret=trace` as
60-
environment variable, you will get detailed step-by-step tracing information.
61-
6243
## Running miri on your own project('s test suite)
6344

6445
Install miri as a cargo subcommand with `cargo install --debug`.
@@ -68,8 +49,8 @@ through miri.
6849

6950
## Running miri with full libstd
7051

71-
Per default libstd does not contain the MIR of non-polymorphic functions. When
72-
miri hits a call to such a function, execution terminates. To fix this, it is
52+
Per default libstd does not contain the MIR of non-polymorphic functions. When
53+
miri hits a call to such a function, execution terminates. To fix this, it is
7354
possible to compile libstd with full MIR:
7455

7556
```sh
@@ -91,6 +72,37 @@ your toolchain changes (e.g., when you update the nightly).
9172
You can also set `-Zmiri-start-fn` to make miri start evaluation with the
9273
`start_fn` lang item, instead of starting at the `main` function.
9374

75+
## Development and Debugging
76+
77+
Since the heart of miri (the main interpreter engine) lives in rustc, working on
78+
miri will often require using a locally built rustc. This includes getting a
79+
trace of the execution, as distributed rustc has `trace!` disabled.
80+
81+
The first-time setup for a local rustc looks as follows:
82+
```
83+
git clone https://github.com/rust-lang/rust/ rustc
84+
cd rustc
85+
cp config.toml.example config.toml
86+
# Now edit `config.toml` and set `debug-assertions = true`
87+
./x.py build src/rustc
88+
# You may have to change the architecture in the next command
89+
rustup toolchain link custom build/x86_64-unknown-linux-gnu/stage2
90+
# Now cd to your miri directory
91+
rustup override set custom
92+
```
93+
The `build` step can take 30 minutes and more.
94+
95+
Now you can `cargo build` miri, and you can `cargo test --tests`. (`--tests`
96+
is needed to skip doctests because we have not built rustdoc for your custom
97+
toolchain.) You can also set `RUST_LOG=rustc_mir::interpret=trace` as
98+
environment variable to get a step-by-step trace.
99+
100+
If you changed something in rustc and want to re-build, run
101+
```
102+
./x.py build src/rustc --keep-stage 0
103+
```
104+
This avoids rebuilding the entire stage 0, which can save a lot of time.
105+
94106
## Contributing and getting help
95107

96108
Check out the issues on this GitHub repository for some ideas. There's lots that

src/operator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
3434
right: Scalar,
3535
right_ty: ty::Ty<'tcx>,
3636
) -> EvalResult<'tcx, Option<(Scalar, bool)>> {
37+
trace!("ptr_op: {:?} {:?} {:?}", left, bin_op, right);
38+
3739
use rustc::mir::BinOp::*;
3840
use rustc::ty::layout::Integer::*;
3941
let usize = Primitive::Int(match self.memory.pointer_size().bytes() {
@@ -81,7 +83,9 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'mir, 'tcx, super:
8183
(Scalar::Bits { .. }, Scalar::Bits { .. }) => {
8284
left.to_bits(left_layout.size)? == right.to_bits(right_layout.size)?
8385
},
86+
// FIXME: Test if both allocations are still live *or* if they are in the same allocation? (same for Ne below)
8487
(Scalar::Ptr(left), Scalar::Ptr(right)) => left == right,
88+
// FIXME: We should probably error out when comparing anything but NULL with a pointer (same for Ne below)
8589
_ => false,
8690
};
8791
Ok(Some((Scalar::from_bool(result), false)))

tests/compile-fail-fullmir/reallocate-bad-size.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ use std::alloc::*;
1010
fn main() {
1111
unsafe {
1212
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();
13-
let _y = Global.realloc(x, Layout::from_size_align_unchecked(2, 1), 1).unwrap();
13+
Global.realloc(x, Layout::from_size_align_unchecked(2, 1), 1).unwrap();
1414
}
1515
}

tests/compile-fail-fullmir/reallocate-change-alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::alloc::*;
88
fn main() {
99
unsafe {
1010
let x = Global.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();
11-
let _y = Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
11+
Global.realloc(x, Layout::from_size_align_unchecked(1, 1), 1).unwrap();
1212
let _z = *(x.as_ptr() as *mut u8); //~ ERROR constant evaluation error
1313
//~^ NOTE dangling pointer was dereferenced
1414
}

tests/compiletest.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullm
6262
config.compile_lib_path = rustc_lib_path();
6363
}
6464
flags.push(format!("--sysroot {}", sysroot.display()));
65+
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
6566
config.src_base = PathBuf::from(path.to_string());
6667
flags.push("-Zmir-emit-validate=1".to_owned());
6768
config.target_rustcflags = Some(flags.join(" "));
@@ -70,23 +71,6 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullm
7071
compiletest::run_tests(&config);
7172
}
7273

73-
fn rustc_pass(sysroot: &Path, path: &str) {
74-
eprintln!("{}", format!("## Running run-pass tests in {} against rustc", path).green().bold());
75-
let mut config = compiletest::Config::default().tempdir();
76-
config.mode = "run-pass".parse().expect("Invalid mode");
77-
config.src_base = PathBuf::from(path);
78-
if let Some(rustc_path) = rustc_test_suite() {
79-
config.rustc_path = rustc_path;
80-
config.run_lib_path = rustc_lib_path();
81-
config.compile_lib_path = rustc_lib_path();
82-
config.target_rustcflags = Some(format!("-Dwarnings --sysroot {}", sysroot.display()));
83-
} else {
84-
config.target_rustcflags = Some("-Dwarnings".to_owned());
85-
}
86-
config.host_rustcflags = Some("-Dwarnings".to_string());
87-
compiletest::run_tests(&config);
88-
}
89-
9074
fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: bool, opt: bool) {
9175
if need_fullmir && !have_fullmir() {
9276
eprintln!("{}", format!(
@@ -116,6 +100,7 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir:
116100
}
117101
let mut flags = Vec::new();
118102
flags.push(format!("--sysroot {}", sysroot.display()));
103+
flags.push("-Dwarnings -Dunused".to_owned()); // overwrite the -Aunused in compiletest-rs
119104
if have_fullmir() {
120105
flags.push("-Zmiri-start-fn".to_owned());
121106
}
@@ -190,12 +175,6 @@ fn run_pass_miri(opt: bool) {
190175
miri_pass(&sysroot, "tests/run-pass-fullmir", &host, &host, true, opt);
191176
}
192177

193-
fn run_pass_rustc() {
194-
let sysroot = get_sysroot();
195-
rustc_pass(&sysroot, "tests/run-pass");
196-
rustc_pass(&sysroot, "tests/run-pass-fullmir");
197-
}
198-
199178
fn compile_fail_miri() {
200179
let sysroot = get_sysroot();
201180
let host = get_host();
@@ -211,10 +190,7 @@ fn test() {
211190
// introduces. We still get parallelism within our tests because `compiletest`
212191
// uses `libtest` which runs jobs in parallel.
213192

214-
run_pass_rustc();
215-
216193
run_pass_miri(false);
217-
218194
// FIXME: Disabled for now, as the optimizer is pretty broken and crashes...
219195
// See https://github.com/rust-lang/rust/issues/50411
220196
//run_pass_miri(true);

tests/run-pass/box_box_trait.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ impl Drop for DroppableStruct {
1313
trait MyTrait { fn dummy(&self) { } }
1414
impl MyTrait for Box<DroppableStruct> {}
1515

16+
#[allow(dead_code)]
1617
struct Whatever { w: Box<MyTrait+'static> }
18+
1719
impl Whatever {
1820
fn new(w: Box<MyTrait+'static>) -> Whatever {
1921
Whatever { w: w }

tests/run-pass/pointers.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ fn main() {
5757
assert_eq!(match_ref_mut(), 42);
5858
// FIXME: improve this test... how?
5959
assert!(dangling_pointer() != std::ptr::null());
60+
assert!(match dangling_pointer() as usize { 0 => false, _ => true });
6061
}

0 commit comments

Comments
 (0)