Skip to content

Commit 4a98f64

Browse files
committed
Merge remote-tracking branch 'origin/master' into rustup
2 parents a34b9c7 + 09a3f72 commit 4a98f64

File tree

7 files changed

+79
-33
lines changed

7 files changed

+79
-33
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ before_script:
1818
if [ "$TRAVIS_EVENT_TYPE" = cron ]; then
1919
RUST_TOOLCHAIN=nightly
2020
else
21-
RUST_TOOLCHAIN=$(cat rust-toolchain)
21+
RUST_TOOLCHAIN=$(cat rust-version)
2222
fi
23-
- rm rust-toolchain
2423
# install Rust
2524
- curl https://build.travis-ci.org/files/rustup-init.sh -sSf | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN"
2625
- export PATH=$HOME/.cargo/bin:$PATH

README.md

Lines changed: 72 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@ undergraduate research course at the [University of Saskatchewan][usask].
77

88
## Building Miri
99

10-
I recommend that you install [rustup][rustup] to obtain Rust. Miri comes with a
11-
`rust-toolchain` file so rustup will automatically pick a suitable nightly
12-
version. Then all you have to do is:
10+
I recommend that you install [rustup][rustup] to obtain Rust. Then all you have
11+
to do is:
1312

1413
```sh
15-
cargo build
14+
cargo +nightly build
1615
```
1716

17+
This uses the very latest Rust version. If you experience any problem, refer to
18+
the `rust-version` file which contains a particular Rust nightly version that
19+
has been tested against the version of miri you are using. Make sure to use
20+
that particular `nightly-YYYY-MM-DD` whenever the instructions just say
21+
`nightly`.
22+
23+
To avoid repeating the nightly version all the time, you can use
24+
`rustup override set nightly` (or `rustup override set nightly-YYYY-MM-DD`),
25+
which means `nightly` Rust will automatically be used whenever you are working
26+
in this directory.
27+
1828
## Running Miri
1929

2030
```sh
21-
cargo run tests/run-pass/vecs.rs # Or whatever test you like.
31+
cargo +nightly run tests/run-pass/vecs.rs # Or whatever test you like.
2232
```
2333

2434
## Running Miri with full libstd
@@ -28,40 +38,77 @@ Miri hits a call to such a function, execution terminates. To fix this, it is
2838
possible to compile libstd with full MIR:
2939

3040
```sh
31-
rustup component add rust-src
32-
cargo install xargo
33-
xargo/build.sh
41+
rustup component add --toolchain nightly rust-src
42+
cargo +nightly install xargo
43+
rustup run nightly xargo/build.sh
3444
```
3545

3646
Now you can run Miri against the libstd compiled by xargo:
3747

3848
```sh
39-
MIRI_SYSROOT=~/.xargo/HOST cargo run tests/run-pass-fullmir/hashmap.rs
49+
MIRI_SYSROOT=~/.xargo/HOST cargo +nightly run tests/run-pass-fullmir/hashmap.rs
4050
```
4151

42-
Notice that you will have to re-run the last step of the preparations above when
43-
your toolchain changes (e.g., when you update the nightly).
44-
45-
You can also set `-Zmiri-start-fn` to make Miri start evaluation with the
46-
`start_fn` lang item, instead of starting at the `main` function.
52+
Notice that you will have to re-run the last step of the preparations above
53+
(`xargo/build.sh`) when your toolchain changes (e.g., when you update the
54+
nightly).
4755

4856
## Running Miri on your own project('s test suite)
4957

50-
Install Miri as a cargo subcommand with `cargo install --all-features`, and install
51-
a full libstd as described above.
58+
Install Miri as a cargo subcommand with `cargo install +nightly --all-features
59+
--path .`. Be aware that if you used `rustup override set` to fix a particular
60+
Rust version for the miri directory, that will *not* apply to your own project
61+
directory! You have to use a consistent Rust version for building miri and your
62+
project for this to work, so remember to either always specify the nightly
63+
version manually, overriding it in your project directory as well, or use
64+
`rustup default nightly` (or `rustup default nightly-YYYY-MM-DD`) to globally
65+
make `nightly` the default toolchain.
5266

53-
Then, inside your own project, use `MIRI_SYSROOT=~/.xargo/HOST cargo +nightly
54-
miri` to run your project, if it is a bin project, or run
55-
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test` to run all tests in your
56-
project through Miri.
67+
We assume that you have prepared a MIR-enabled libstd as described above. Now
68+
compile your project and its dependencies against that libstd:
5769

58-
## Miri `-Z` flags
70+
1. Run `cargo clean` to eliminate any cached dependencies that were built against
71+
the non-MIR `libstd`.
72+
2. To run all tests in your project through, Miri, use
73+
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test`.
74+
3. If you have a binary project, you can run it through Miri using
75+
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri`.
76+
77+
### Common Problems
78+
79+
When using the above instructions, you may encounter a number of confusing compiler
80+
errors.
81+
82+
#### "constant evaluation error: no mir for `<function>`"
5983

60-
Miri adds some extra `-Z` flags to control its behavior:
84+
You may have forgotten to set `MIRI_SYSROOT` when calling `cargo miri`, and
85+
your program called into `std` or `core`. Be sure to set `MIRI_SYSROOT=~/.xargo/HOST`.
86+
87+
#### "found possibly newer version of crate `std` which `<dependency>` depends on"
88+
89+
Your build directory may contain artifacts from an earlier build that did/did not
90+
have `MIRI_SYSROOT` set. Run `cargo clean` before switching from non-Miri to Miri
91+
builds and vice-versa.
92+
93+
#### "found crate `std` compiled by an incompatible version of rustc"
94+
95+
You may be running `cargo miri` with a different compiler version than the one
96+
used to build the MIR-enabled `std`. Be sure to consistently use the same toolchain,
97+
which should be the toolchain specified in the `rust-version` file.
98+
99+
## Miri `-Z` flags
61100

62-
* `-Zmiri-start-fn`: This makes interpretation start with `lang_start` (defined
63-
in libstd) instead of starting with `main`. Requires full MIR!
64-
* `-Zmiri-disable-validation` disables enforcing the validity invariant.
101+
Several `-Z` flags are relevant for miri:
102+
103+
* `-Zmir-opt-level` controls how many MIR optimizations are performed. miri
104+
overrides the default to be `0`; be advised that using any higher level can
105+
make miri miss bugs in your program because they got optimized away.
106+
* `-Zalways-encode-mir` makes rustc dump MIR even for completely monomorphic
107+
functions. This is needed so that miri can execute such functions, so miri
108+
sets this flag per default.
109+
* `-Zmiri-disable-validation` is a custom `-Z` flag added by miri. It disables
110+
enforcing the validity invariant, which is enforced by default. This is
111+
mostly useful for debugging; it means miri will miss bugs in your program.
65112

66113
## Development and Debugging
67114

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ branches:
1616
install:
1717
# install Rust
1818
- set PATH=C:\Program Files\Git\mingw64\bin;C:\msys64\mingw%MSYS2_BITS%\bin;%PATH%
19-
- set /p RUST_TOOLCHAIN=<rust-toolchain
19+
- set /p RUST_TOOLCHAIN=<rust-version
2020
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
2121
- rustup-init.exe -y --default-host %TARGET% --default-toolchain %RUST_TOOLCHAIN%
2222
- set PATH=%USERPROFILE%\.cargo\bin;%PATH%
File renamed without changes.

src/fn_call.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
132132

133133
"free" => {
134134
let ptr = self.read_scalar(args[0])?.not_undef()?.erase_tag(); // raw ptr operation, no tag
135-
if !ptr.is_null() {
135+
if !ptr.is_null_ptr(&self) {
136136
self.memory_mut().deallocate(
137137
ptr.to_ptr()?.with_default_tag(),
138138
None,
@@ -355,7 +355,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
355355
let mut success = None;
356356
{
357357
let name_ptr = self.read_scalar(args[0])?.not_undef()?.erase_tag(); // raw ptr operation
358-
if !name_ptr.is_null() {
358+
if !name_ptr.is_null_ptr(&self) {
359359
let name = self.memory().read_c_str(name_ptr.to_ptr()?
360360
.with_default_tag())?.to_owned();
361361
if !name.is_empty() && !name.contains(&b'=') {
@@ -379,7 +379,7 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo
379379
let name_ptr = self.read_scalar(args[0])?.not_undef()?.erase_tag(); // raw ptr operation
380380
let value_ptr = self.read_scalar(args[1])?.to_ptr()?.erase_tag(); // raw ptr operation
381381
let value = self.memory().read_c_str(value_ptr.with_default_tag())?;
382-
if !name_ptr.is_null() {
382+
if !name_ptr.is_null_ptr(&self) {
383383
let name = self.memory().read_c_str(name_ptr.to_ptr()?.with_default_tag())?;
384384
if !name.is_empty() && !name.contains(&b'=') {
385385
new = Some((name.to_owned(), value.to_owned()));

src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a, 'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'a, 'mir, '
231231
let a = self.read_value(args[0])?;
232232
let b = self.read_value(args[1])?;
233233
// check x % y != 0
234-
if !self.binary_op_val(mir::BinOp::Rem, a, b)?.0.is_null() {
234+
if self.binary_op_val(mir::BinOp::Rem, a, b)?.0.to_bytes()? != 0 {
235235
return err!(ValidationFailure(format!("exact_div: {:?} cannot be divided by {:?}", a, b)));
236236
}
237237
self.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?;

src/tls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'tcx> TlsData<'tcx> {
121121
for (&key, &mut TlsEntry { ref mut data, dtor }) in
122122
thread_local.range_mut((start, Unbounded))
123123
{
124-
if !data.is_null() {
124+
if !data.is_null_ptr(cx) {
125125
if let Some(dtor) = dtor {
126126
let ret = Some((dtor, *data, key));
127127
*data = Scalar::ptr_null(cx);

0 commit comments

Comments
 (0)