From c84c1527e2d486437efa5e3851a2b4b421c99133 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 09:23:27 +0100 Subject: [PATCH 1/8] factor grabbing of cargo options into separate function and make it better --- src/bin/cargo-miri.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 2dc6eee5de..436b6a9430 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -53,14 +53,32 @@ fn show_error(msg: String) -> ! { std::process::exit(1) } -fn list_targets(mut args: impl Iterator) -> impl Iterator { +fn get_arg_flag_value(name: &str) -> Option { + // stop searching at `--` + let mut args = std::env::args().skip_while(|val| !(val.starts_with(name) || val == "--")); + + match args.next() { + Some(ref p) if p == "--" => None, + Some(ref p) if p == name => args.next(), + Some(p) => { + // Make sure this really starts with `$name=`, we didn't test for the `=` yet. + let v = &p[name.len()..]; // strip leading `$name` + if v.starts_with('=') { + Some(v[1..].to_owned()) // strip leading `=` + } else { + None + } + }, + None => None, + } +} + +fn list_targets() -> impl Iterator { // We need to get the manifest, and then the metadata, to enumerate targets. - let manifest_path_arg = args.find(|val| { - val.starts_with("--manifest-path=") - }); + let manifest_path = get_arg_flag_value("--manifest-path").map(PathBuf::from); let mut metadata = if let Ok(metadata) = cargo_metadata::metadata( - manifest_path_arg.as_ref().map(AsRef::as_ref), + manifest_path.as_ref().map(AsRef::as_ref), ) { metadata @@ -68,10 +86,6 @@ fn list_targets(mut args: impl Iterator) -> impl Iterator Date: Mon, 10 Dec 2018 09:32:54 +0100 Subject: [PATCH 2/8] cargo miri: support foreign targets --- Cargo.toml | 3 ++- src/bin/cargo-miri.rs | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index becb5c69e5..ca670df0f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ required-features = ["rustc_tests"] byteorder = { version = "1.1", features = ["i128"]} cargo_metadata = { version = "0.6", optional = true } directories = { version = "1.0", optional = true } +rustc_version = { version = "0.2.3", optional = true } env_logger = "0.5" log = "0.4" @@ -44,7 +45,7 @@ vergen = "3" [features] default = ["cargo_miri"] -cargo_miri = ["cargo_metadata", "directories"] +cargo_miri = ["cargo_metadata", "directories", "rustc_version"] rustc_tests = [] [dev-dependencies] diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 436b6a9430..68da028a81 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -190,17 +190,28 @@ path = "lib.rs" "#).unwrap(); File::create(dir.join("lib.rs")).unwrap(); // Run xargo - if !Command::new("xargo").arg("build").arg("-q") + let target = get_arg_flag_value("--target"); + let mut command = Command::new("xargo"); + command.arg("build").arg("-q") .current_dir(&dir) .env("RUSTFLAGS", miri::miri_default_args().join(" ")) - .env("XARGO_HOME", dir.to_str().unwrap()) - .status().unwrap().success() + .env("XARGO_HOME", dir.to_str().unwrap()); + if let Some(ref target) = target { + command.arg("--target").arg(&target); + } + if !command.status().unwrap().success() { show_error(format!("Failed to run xargo")); } - // That should be it! - let sysroot = dir.join("HOST"); + // That should be it! But we need to figure out where xargo built stuff. + // Unfortunately, it puts things into a different directory when the + // architecture matches the host. + let is_host = match target { + None => true, + Some(target) => target == rustc_version::version_meta().unwrap().host, + }; + let sysroot = if is_host { dir.join("HOST") } else { PathBuf::from(dir) }; std::env::set_var("MIRI_SYSROOT", &sysroot); if !ask_user { println!("A libstd for miri is now available in `{}`", sysroot.display()); From f044205b5fab8b48a583f613f995519d6895e8ea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 10:04:55 +0100 Subject: [PATCH 3/8] the test suite assumes a libstd with full MIR; run test suite on xargo-built foreign libstds --- .travis.yml | 29 ++++++------- .../.gitignore | 0 .../Cargo.lock | 0 .../Cargo.toml | 0 .../run-test.py | 0 .../src/main.rs | 0 .../stderr.ref | 0 .../stdout.ref | 0 .../tests/foo.rs | 0 .../copy_nonoverlapping.rs | 0 .../deallocate-bad-alignment.rs | 0 .../deallocate-bad-size.rs | 0 .../deallocate-twice.rs | 0 .../memleak_rc.rs | 0 .../out_of_bounds_ptr_1.rs | 0 .../out_of_bounds_ptr_2.rs | 0 .../ptr_offset_overflow.rs | 0 .../reallocate-bad-size.rs | 0 .../reallocate-change-alloc.rs | 0 .../reallocate-dangling.rs | 0 .../stack_free.rs | 0 .../stacked_borrows/alias_through_mutation.rs | 0 .../stacked_borrows/aliasing_mut1.rs | 0 .../stacked_borrows/aliasing_mut2.rs | 0 .../stacked_borrows/aliasing_mut3.rs | 0 .../stacked_borrows/aliasing_mut4.rs | 0 .../box_exclusive_violation1.rs | 0 .../stacked_borrows/buggy_as_mut_slice.rs | 0 .../stacked_borrows/buggy_split_at_mut.rs | 0 .../deallocate_against_barrier.rs | 0 .../stacked_borrows/illegal_read1.rs | 0 .../stacked_borrows/illegal_read2.rs | 0 .../stacked_borrows/illegal_read3.rs | 0 .../stacked_borrows/illegal_read4.rs | 0 .../stacked_borrows/illegal_read5.rs | 0 .../stacked_borrows/illegal_write1.rs | 0 .../stacked_borrows/illegal_write2.rs | 0 .../stacked_borrows/illegal_write3.rs | 0 .../stacked_borrows/illegal_write4.rs | 0 .../stacked_borrows/illegal_write5.rs | 0 .../invalidate_against_barrier1.rs | 0 .../invalidate_against_barrier2.rs | 0 .../stacked_borrows/load_invalid_mut.rs | 0 .../stacked_borrows/load_invalid_shr.rs | 0 .../mut_exclusive_violation1.rs | 0 .../stacked_borrows/outdated_local.rs | 0 .../stacked_borrows/pass_invalid_mut.rs | 0 .../stacked_borrows/pass_invalid_shr.rs | 0 .../stacked_borrows/pointer_smuggling.rs | 0 .../stacked_borrows/return_invalid_mut.rs | 0 .../return_invalid_mut_option.rs | 0 .../return_invalid_mut_tuple.rs | 0 .../stacked_borrows/return_invalid_shr.rs | 0 .../return_invalid_shr_option.rs | 0 .../return_invalid_shr_tuple.rs | 0 .../stacked_borrows/shr_frozen_violation1.rs | 0 .../static_memory_modification.rs | 0 .../stacked_borrows/transmute-is-no-escape.rs | 0 .../stacked_borrows/unescaped_local.rs | 0 .../transmute-pair-undef.rs | 0 tests/compiletest.rs | 43 ++++--------------- .../async-fn.rs | 0 .../box-pair-to-vec.rs | 0 .../box-pair-to-vec.stdout | 0 tests/{run-pass-fullmir => run-pass}/catch.rs | 0 .../catch.stdout | 0 tests/{run-pass-fullmir => run-pass}/env.rs | 0 .../foreign-fn-linkname.rs | 0 .../{run-pass-fullmir => run-pass}/format.rs | 0 .../format.stdout | 0 .../from_utf8.rs | 0 .../{run-pass-fullmir => run-pass}/hashmap.rs | 0 tests/{run-pass-fullmir => run-pass}/hello.rs | 0 .../hello.stdout | 0 .../integer-ops.rs | 0 .../issue-3794.rs | 0 .../issue-3794.stdout | 0 .../loop-break-value.rs | 0 .../{run-pass-fullmir => run-pass}/memchr.rs | 0 .../send-is-not-static-par-for.rs | 0 .../{run-pass-fullmir => run-pass}/threads.rs | 0 tests/{run-pass-fullmir => run-pass}/u128.rs | 0 .../unsized-tuple-impls.rs | 0 .../vecdeque.rs | 0 84 files changed, 22 insertions(+), 50 deletions(-) rename {cargo-miri-test => test-cargo-miri}/.gitignore (100%) rename {cargo-miri-test => test-cargo-miri}/Cargo.lock (100%) rename {cargo-miri-test => test-cargo-miri}/Cargo.toml (100%) rename {cargo-miri-test => test-cargo-miri}/run-test.py (100%) rename {cargo-miri-test => test-cargo-miri}/src/main.rs (100%) rename {cargo-miri-test => test-cargo-miri}/stderr.ref (100%) rename {cargo-miri-test => test-cargo-miri}/stdout.ref (100%) rename {cargo-miri-test => test-cargo-miri}/tests/foo.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/copy_nonoverlapping.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/deallocate-bad-alignment.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/deallocate-bad-size.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/deallocate-twice.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/memleak_rc.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/out_of_bounds_ptr_1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/out_of_bounds_ptr_2.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/ptr_offset_overflow.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/reallocate-bad-size.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/reallocate-change-alloc.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/reallocate-dangling.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stack_free.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/alias_through_mutation.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/aliasing_mut1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/aliasing_mut2.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/aliasing_mut3.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/aliasing_mut4.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/box_exclusive_violation1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/buggy_as_mut_slice.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/buggy_split_at_mut.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/deallocate_against_barrier.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_read1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_read2.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_read3.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_read4.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_read5.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_write1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_write2.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_write3.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_write4.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/illegal_write5.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/invalidate_against_barrier1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/invalidate_against_barrier2.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/load_invalid_mut.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/load_invalid_shr.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/mut_exclusive_violation1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/outdated_local.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/pass_invalid_mut.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/pass_invalid_shr.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/pointer_smuggling.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/return_invalid_mut.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/return_invalid_mut_option.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/return_invalid_mut_tuple.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/return_invalid_shr.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/return_invalid_shr_option.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/return_invalid_shr_tuple.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/shr_frozen_violation1.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/static_memory_modification.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/transmute-is-no-escape.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/stacked_borrows/unescaped_local.rs (100%) rename tests/{compile-fail-fullmir => compile-fail}/transmute-pair-undef.rs (100%) rename tests/{run-pass-fullmir => run-pass}/async-fn.rs (100%) rename tests/{run-pass-fullmir => run-pass}/box-pair-to-vec.rs (100%) rename tests/{run-pass-fullmir => run-pass}/box-pair-to-vec.stdout (100%) rename tests/{run-pass-fullmir => run-pass}/catch.rs (100%) rename tests/{run-pass-fullmir => run-pass}/catch.stdout (100%) rename tests/{run-pass-fullmir => run-pass}/env.rs (100%) rename tests/{run-pass-fullmir => run-pass}/foreign-fn-linkname.rs (100%) rename tests/{run-pass-fullmir => run-pass}/format.rs (100%) rename tests/{run-pass-fullmir => run-pass}/format.stdout (100%) rename tests/{run-pass-fullmir => run-pass}/from_utf8.rs (100%) rename tests/{run-pass-fullmir => run-pass}/hashmap.rs (100%) rename tests/{run-pass-fullmir => run-pass}/hello.rs (100%) rename tests/{run-pass-fullmir => run-pass}/hello.stdout (100%) rename tests/{run-pass-fullmir => run-pass}/integer-ops.rs (100%) rename tests/{run-pass-fullmir => run-pass}/issue-3794.rs (100%) rename tests/{run-pass-fullmir => run-pass}/issue-3794.stdout (100%) rename tests/{run-pass-fullmir => run-pass}/loop-break-value.rs (100%) rename tests/{run-pass-fullmir => run-pass}/memchr.rs (100%) rename tests/{run-pass-fullmir => run-pass}/send-is-not-static-par-for.rs (100%) rename tests/{run-pass-fullmir => run-pass}/threads.rs (100%) rename tests/{run-pass-fullmir => run-pass}/u128.rs (100%) rename tests/{run-pass-fullmir => run-pass}/unsized-tuple-impls.rs (100%) rename tests/{run-pass-fullmir => run-pass}/vecdeque.rs (100%) diff --git a/.travis.yml b/.travis.yml index ba3b8d3639..ac3f16ce13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,36 +20,35 @@ before_script: else RUST_TOOLCHAIN=$(cat rust-version) fi +- | + if [ "$TRAVIS_OS_NAME" == osx ]; then + export MIRI_SYSROOT_BASE=~/Library/Caches/miri.miri.miri/ + else + export MIRI_SYSROOT_BASE=~/.cache/miri/HOST + fi # install Rust - curl https://build.travis-ci.org/files/rustup-init.sh -sSf | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" - export PATH=$HOME/.cargo/bin:$PATH - rustc --version -# customize installation -- rustup target add i686-unknown-linux-gnu -- rustup target add i686-pc-windows-gnu -- rustup target add i686-pc-windows-msvc script: - set -e - | - # Test and install plain miri + # Build and install miri cargo build --release --all-features --all-targets && - cargo test --release --all-features && cargo install --all-features --force --path . - | - # Get ourselves a MIR-full libstd, and use it henceforth + # Get ourselves a MIR-full libstd cargo miri setup && - if [ "$TRAVIS_OS_NAME" == osx ]; then - export MIRI_SYSROOT=~/Library/Caches/miri.miri.miri/HOST - else - export MIRI_SYSROOT=~/.cache/miri/HOST - fi + cargo miri setup --target i686-unknown-linux-gnu && + cargo miri setup --target i686-apple-darwin - | - # Test miri with full MIR - cargo test --release --all-features + # Test miri with full MIR, on the host and other architectures + MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST cargo test --release --all-features && + MIRI_SYSROOT=$MIRI_SYSROOT_BASE cargo test --release --all-features - | # Test cargo integration - (cd cargo-miri-test && ./run-test.py) + (cd test-cargo-miri && MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST ./run-test.py) notifications: email: diff --git a/cargo-miri-test/.gitignore b/test-cargo-miri/.gitignore similarity index 100% rename from cargo-miri-test/.gitignore rename to test-cargo-miri/.gitignore diff --git a/cargo-miri-test/Cargo.lock b/test-cargo-miri/Cargo.lock similarity index 100% rename from cargo-miri-test/Cargo.lock rename to test-cargo-miri/Cargo.lock diff --git a/cargo-miri-test/Cargo.toml b/test-cargo-miri/Cargo.toml similarity index 100% rename from cargo-miri-test/Cargo.toml rename to test-cargo-miri/Cargo.toml diff --git a/cargo-miri-test/run-test.py b/test-cargo-miri/run-test.py similarity index 100% rename from cargo-miri-test/run-test.py rename to test-cargo-miri/run-test.py diff --git a/cargo-miri-test/src/main.rs b/test-cargo-miri/src/main.rs similarity index 100% rename from cargo-miri-test/src/main.rs rename to test-cargo-miri/src/main.rs diff --git a/cargo-miri-test/stderr.ref b/test-cargo-miri/stderr.ref similarity index 100% rename from cargo-miri-test/stderr.ref rename to test-cargo-miri/stderr.ref diff --git a/cargo-miri-test/stdout.ref b/test-cargo-miri/stdout.ref similarity index 100% rename from cargo-miri-test/stdout.ref rename to test-cargo-miri/stdout.ref diff --git a/cargo-miri-test/tests/foo.rs b/test-cargo-miri/tests/foo.rs similarity index 100% rename from cargo-miri-test/tests/foo.rs rename to test-cargo-miri/tests/foo.rs diff --git a/tests/compile-fail-fullmir/copy_nonoverlapping.rs b/tests/compile-fail/copy_nonoverlapping.rs similarity index 100% rename from tests/compile-fail-fullmir/copy_nonoverlapping.rs rename to tests/compile-fail/copy_nonoverlapping.rs diff --git a/tests/compile-fail-fullmir/deallocate-bad-alignment.rs b/tests/compile-fail/deallocate-bad-alignment.rs similarity index 100% rename from tests/compile-fail-fullmir/deallocate-bad-alignment.rs rename to tests/compile-fail/deallocate-bad-alignment.rs diff --git a/tests/compile-fail-fullmir/deallocate-bad-size.rs b/tests/compile-fail/deallocate-bad-size.rs similarity index 100% rename from tests/compile-fail-fullmir/deallocate-bad-size.rs rename to tests/compile-fail/deallocate-bad-size.rs diff --git a/tests/compile-fail-fullmir/deallocate-twice.rs b/tests/compile-fail/deallocate-twice.rs similarity index 100% rename from tests/compile-fail-fullmir/deallocate-twice.rs rename to tests/compile-fail/deallocate-twice.rs diff --git a/tests/compile-fail-fullmir/memleak_rc.rs b/tests/compile-fail/memleak_rc.rs similarity index 100% rename from tests/compile-fail-fullmir/memleak_rc.rs rename to tests/compile-fail/memleak_rc.rs diff --git a/tests/compile-fail-fullmir/out_of_bounds_ptr_1.rs b/tests/compile-fail/out_of_bounds_ptr_1.rs similarity index 100% rename from tests/compile-fail-fullmir/out_of_bounds_ptr_1.rs rename to tests/compile-fail/out_of_bounds_ptr_1.rs diff --git a/tests/compile-fail-fullmir/out_of_bounds_ptr_2.rs b/tests/compile-fail/out_of_bounds_ptr_2.rs similarity index 100% rename from tests/compile-fail-fullmir/out_of_bounds_ptr_2.rs rename to tests/compile-fail/out_of_bounds_ptr_2.rs diff --git a/tests/compile-fail-fullmir/ptr_offset_overflow.rs b/tests/compile-fail/ptr_offset_overflow.rs similarity index 100% rename from tests/compile-fail-fullmir/ptr_offset_overflow.rs rename to tests/compile-fail/ptr_offset_overflow.rs diff --git a/tests/compile-fail-fullmir/reallocate-bad-size.rs b/tests/compile-fail/reallocate-bad-size.rs similarity index 100% rename from tests/compile-fail-fullmir/reallocate-bad-size.rs rename to tests/compile-fail/reallocate-bad-size.rs diff --git a/tests/compile-fail-fullmir/reallocate-change-alloc.rs b/tests/compile-fail/reallocate-change-alloc.rs similarity index 100% rename from tests/compile-fail-fullmir/reallocate-change-alloc.rs rename to tests/compile-fail/reallocate-change-alloc.rs diff --git a/tests/compile-fail-fullmir/reallocate-dangling.rs b/tests/compile-fail/reallocate-dangling.rs similarity index 100% rename from tests/compile-fail-fullmir/reallocate-dangling.rs rename to tests/compile-fail/reallocate-dangling.rs diff --git a/tests/compile-fail-fullmir/stack_free.rs b/tests/compile-fail/stack_free.rs similarity index 100% rename from tests/compile-fail-fullmir/stack_free.rs rename to tests/compile-fail/stack_free.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/alias_through_mutation.rs b/tests/compile-fail/stacked_borrows/alias_through_mutation.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/alias_through_mutation.rs rename to tests/compile-fail/stacked_borrows/alias_through_mutation.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/aliasing_mut1.rs b/tests/compile-fail/stacked_borrows/aliasing_mut1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/aliasing_mut1.rs rename to tests/compile-fail/stacked_borrows/aliasing_mut1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/aliasing_mut2.rs b/tests/compile-fail/stacked_borrows/aliasing_mut2.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/aliasing_mut2.rs rename to tests/compile-fail/stacked_borrows/aliasing_mut2.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/aliasing_mut3.rs b/tests/compile-fail/stacked_borrows/aliasing_mut3.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/aliasing_mut3.rs rename to tests/compile-fail/stacked_borrows/aliasing_mut3.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/aliasing_mut4.rs b/tests/compile-fail/stacked_borrows/aliasing_mut4.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/aliasing_mut4.rs rename to tests/compile-fail/stacked_borrows/aliasing_mut4.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/box_exclusive_violation1.rs b/tests/compile-fail/stacked_borrows/box_exclusive_violation1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/box_exclusive_violation1.rs rename to tests/compile-fail/stacked_borrows/box_exclusive_violation1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/buggy_as_mut_slice.rs b/tests/compile-fail/stacked_borrows/buggy_as_mut_slice.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/buggy_as_mut_slice.rs rename to tests/compile-fail/stacked_borrows/buggy_as_mut_slice.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/buggy_split_at_mut.rs b/tests/compile-fail/stacked_borrows/buggy_split_at_mut.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/buggy_split_at_mut.rs rename to tests/compile-fail/stacked_borrows/buggy_split_at_mut.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/deallocate_against_barrier.rs b/tests/compile-fail/stacked_borrows/deallocate_against_barrier.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/deallocate_against_barrier.rs rename to tests/compile-fail/stacked_borrows/deallocate_against_barrier.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_read1.rs b/tests/compile-fail/stacked_borrows/illegal_read1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_read1.rs rename to tests/compile-fail/stacked_borrows/illegal_read1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_read2.rs b/tests/compile-fail/stacked_borrows/illegal_read2.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_read2.rs rename to tests/compile-fail/stacked_borrows/illegal_read2.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_read3.rs b/tests/compile-fail/stacked_borrows/illegal_read3.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_read3.rs rename to tests/compile-fail/stacked_borrows/illegal_read3.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_read4.rs b/tests/compile-fail/stacked_borrows/illegal_read4.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_read4.rs rename to tests/compile-fail/stacked_borrows/illegal_read4.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_read5.rs b/tests/compile-fail/stacked_borrows/illegal_read5.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_read5.rs rename to tests/compile-fail/stacked_borrows/illegal_read5.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_write1.rs b/tests/compile-fail/stacked_borrows/illegal_write1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_write1.rs rename to tests/compile-fail/stacked_borrows/illegal_write1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_write2.rs b/tests/compile-fail/stacked_borrows/illegal_write2.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_write2.rs rename to tests/compile-fail/stacked_borrows/illegal_write2.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_write3.rs b/tests/compile-fail/stacked_borrows/illegal_write3.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_write3.rs rename to tests/compile-fail/stacked_borrows/illegal_write3.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_write4.rs b/tests/compile-fail/stacked_borrows/illegal_write4.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_write4.rs rename to tests/compile-fail/stacked_borrows/illegal_write4.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/illegal_write5.rs b/tests/compile-fail/stacked_borrows/illegal_write5.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/illegal_write5.rs rename to tests/compile-fail/stacked_borrows/illegal_write5.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/invalidate_against_barrier1.rs b/tests/compile-fail/stacked_borrows/invalidate_against_barrier1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/invalidate_against_barrier1.rs rename to tests/compile-fail/stacked_borrows/invalidate_against_barrier1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/invalidate_against_barrier2.rs b/tests/compile-fail/stacked_borrows/invalidate_against_barrier2.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/invalidate_against_barrier2.rs rename to tests/compile-fail/stacked_borrows/invalidate_against_barrier2.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/load_invalid_mut.rs b/tests/compile-fail/stacked_borrows/load_invalid_mut.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/load_invalid_mut.rs rename to tests/compile-fail/stacked_borrows/load_invalid_mut.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/load_invalid_shr.rs b/tests/compile-fail/stacked_borrows/load_invalid_shr.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/load_invalid_shr.rs rename to tests/compile-fail/stacked_borrows/load_invalid_shr.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/mut_exclusive_violation1.rs b/tests/compile-fail/stacked_borrows/mut_exclusive_violation1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/mut_exclusive_violation1.rs rename to tests/compile-fail/stacked_borrows/mut_exclusive_violation1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/outdated_local.rs b/tests/compile-fail/stacked_borrows/outdated_local.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/outdated_local.rs rename to tests/compile-fail/stacked_borrows/outdated_local.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/pass_invalid_mut.rs b/tests/compile-fail/stacked_borrows/pass_invalid_mut.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/pass_invalid_mut.rs rename to tests/compile-fail/stacked_borrows/pass_invalid_mut.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/pass_invalid_shr.rs b/tests/compile-fail/stacked_borrows/pass_invalid_shr.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/pass_invalid_shr.rs rename to tests/compile-fail/stacked_borrows/pass_invalid_shr.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/pointer_smuggling.rs b/tests/compile-fail/stacked_borrows/pointer_smuggling.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/pointer_smuggling.rs rename to tests/compile-fail/stacked_borrows/pointer_smuggling.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/return_invalid_mut.rs b/tests/compile-fail/stacked_borrows/return_invalid_mut.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/return_invalid_mut.rs rename to tests/compile-fail/stacked_borrows/return_invalid_mut.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/return_invalid_mut_option.rs b/tests/compile-fail/stacked_borrows/return_invalid_mut_option.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/return_invalid_mut_option.rs rename to tests/compile-fail/stacked_borrows/return_invalid_mut_option.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/return_invalid_mut_tuple.rs b/tests/compile-fail/stacked_borrows/return_invalid_mut_tuple.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/return_invalid_mut_tuple.rs rename to tests/compile-fail/stacked_borrows/return_invalid_mut_tuple.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/return_invalid_shr.rs b/tests/compile-fail/stacked_borrows/return_invalid_shr.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/return_invalid_shr.rs rename to tests/compile-fail/stacked_borrows/return_invalid_shr.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/return_invalid_shr_option.rs b/tests/compile-fail/stacked_borrows/return_invalid_shr_option.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/return_invalid_shr_option.rs rename to tests/compile-fail/stacked_borrows/return_invalid_shr_option.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/return_invalid_shr_tuple.rs b/tests/compile-fail/stacked_borrows/return_invalid_shr_tuple.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/return_invalid_shr_tuple.rs rename to tests/compile-fail/stacked_borrows/return_invalid_shr_tuple.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/shr_frozen_violation1.rs b/tests/compile-fail/stacked_borrows/shr_frozen_violation1.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/shr_frozen_violation1.rs rename to tests/compile-fail/stacked_borrows/shr_frozen_violation1.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/static_memory_modification.rs b/tests/compile-fail/stacked_borrows/static_memory_modification.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/static_memory_modification.rs rename to tests/compile-fail/stacked_borrows/static_memory_modification.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/transmute-is-no-escape.rs b/tests/compile-fail/stacked_borrows/transmute-is-no-escape.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/transmute-is-no-escape.rs rename to tests/compile-fail/stacked_borrows/transmute-is-no-escape.rs diff --git a/tests/compile-fail-fullmir/stacked_borrows/unescaped_local.rs b/tests/compile-fail/stacked_borrows/unescaped_local.rs similarity index 100% rename from tests/compile-fail-fullmir/stacked_borrows/unescaped_local.rs rename to tests/compile-fail/stacked_borrows/unescaped_local.rs diff --git a/tests/compile-fail-fullmir/transmute-pair-undef.rs b/tests/compile-fail/transmute-pair-undef.rs similarity index 100% rename from tests/compile-fail-fullmir/transmute-pair-undef.rs rename to tests/compile-fail/transmute-pair-undef.rs diff --git a/tests/compiletest.rs b/tests/compiletest.rs index 1c11d07c1b..f0ebbf6b07 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -1,4 +1,5 @@ #![feature(slice_concat_ext, custom_test_frameworks)] +// Custom test runner, to avoid libtest being wrapped around compiletest which wraps libtest. #![test_runner(test_runner)] use std::slice::SliceConcatExt; @@ -24,11 +25,6 @@ fn rustc_lib_path() -> PathBuf { option_env!("RUSTC_LIB_PATH").unwrap().into() } -fn have_fullmir() -> bool { - // We assume we have full MIR when MIRI_SYSROOT is set or when we are in rustc - std::env::var("MIRI_SYSROOT").is_ok() || rustc_test_suite().is_some() -} - fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp { let mut config = compiletest::Config::default().tempdir(); config.mode = mode.parse().expect("Invalid mode"); @@ -41,16 +37,7 @@ fn mk_config(mode: &str) -> compiletest::common::ConfigWithTemp { config } -fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: bool, opt: bool) { - if need_fullmir && !have_fullmir() { - eprintln!("{}\n", format!( - "## Skipping compile-fail tests in {} against miri for target {} due to missing mir", - path, - target - ).yellow().bold()); - return; - } - +fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool) { let opt_str = if opt { " with optimizations" } else { "" }; eprintln!("{}", format!( "## Running compile-fail tests in {} against miri for target {}{}", @@ -78,16 +65,7 @@ fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, need_fullm compiletest::run_tests(&config); } -fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: bool, opt: bool) { - if need_fullmir && !have_fullmir() { - eprintln!("{}\n", format!( - "## Skipping run-pass tests in {} against miri for target {} due to missing mir", - path, - target - ).yellow().bold()); - return; - } - +fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, opt: bool) { let opt_str = if opt { " with optimizations" } else { "" }; eprintln!("{}", format!( "## Running run-pass tests in {} against miri for target {}{}", @@ -105,10 +83,6 @@ fn miri_pass(sysroot: &Path, path: &str, target: &str, host: &str, need_fullmir: // whitelist. flags.push("-Zmir-opt-level=1".to_owned()); } - if !have_fullmir() { - // FIXME: Validation relies on the EscapeToRaw statements being emitted - flags.push("-Zmiri-disable-validation".to_owned()); - } let mut config = mk_config("ui"); config.src_base = PathBuf::from(path); @@ -132,7 +106,7 @@ fn target_has_std>(path: P) -> bool { .map(|entry| entry.unwrap()) .filter(|entry| entry.file_type().unwrap().is_file()) .filter_map(|entry| entry.file_name().into_string().ok()) - .any(|file_name| file_name.starts_with("libstd") && file_name.ends_with(".rlib")) + .any(|file_name| file_name == "libstd.rlib") } @@ -186,18 +160,17 @@ fn run_pass_miri(opt: bool) { let host = get_host(); for_all_targets(&sysroot, |target| { - miri_pass(&sysroot, "tests/run-pass", &target, &host, false, opt); + miri_pass(&sysroot, "tests/run-pass", &target, &host, opt); }); - miri_pass(&sysroot, "tests/run-pass-fullmir", &host, &host, true, opt); } fn compile_fail_miri(opt: bool) { let sysroot = get_sysroot(); let host = get_host(); - // FIXME: run tests for other targets, too - compile_fail(&sysroot, "tests/compile-fail", &host, &host, false, opt); - compile_fail(&sysroot, "tests/compile-fail-fullmir", &host, &host, true, opt); + for_all_targets(&sysroot, |target| { + compile_fail(&sysroot, "tests/compile-fail", &target, &host, opt); + }); } fn test_runner(_tests: &[&()]) { diff --git a/tests/run-pass-fullmir/async-fn.rs b/tests/run-pass/async-fn.rs similarity index 100% rename from tests/run-pass-fullmir/async-fn.rs rename to tests/run-pass/async-fn.rs diff --git a/tests/run-pass-fullmir/box-pair-to-vec.rs b/tests/run-pass/box-pair-to-vec.rs similarity index 100% rename from tests/run-pass-fullmir/box-pair-to-vec.rs rename to tests/run-pass/box-pair-to-vec.rs diff --git a/tests/run-pass-fullmir/box-pair-to-vec.stdout b/tests/run-pass/box-pair-to-vec.stdout similarity index 100% rename from tests/run-pass-fullmir/box-pair-to-vec.stdout rename to tests/run-pass/box-pair-to-vec.stdout diff --git a/tests/run-pass-fullmir/catch.rs b/tests/run-pass/catch.rs similarity index 100% rename from tests/run-pass-fullmir/catch.rs rename to tests/run-pass/catch.rs diff --git a/tests/run-pass-fullmir/catch.stdout b/tests/run-pass/catch.stdout similarity index 100% rename from tests/run-pass-fullmir/catch.stdout rename to tests/run-pass/catch.stdout diff --git a/tests/run-pass-fullmir/env.rs b/tests/run-pass/env.rs similarity index 100% rename from tests/run-pass-fullmir/env.rs rename to tests/run-pass/env.rs diff --git a/tests/run-pass-fullmir/foreign-fn-linkname.rs b/tests/run-pass/foreign-fn-linkname.rs similarity index 100% rename from tests/run-pass-fullmir/foreign-fn-linkname.rs rename to tests/run-pass/foreign-fn-linkname.rs diff --git a/tests/run-pass-fullmir/format.rs b/tests/run-pass/format.rs similarity index 100% rename from tests/run-pass-fullmir/format.rs rename to tests/run-pass/format.rs diff --git a/tests/run-pass-fullmir/format.stdout b/tests/run-pass/format.stdout similarity index 100% rename from tests/run-pass-fullmir/format.stdout rename to tests/run-pass/format.stdout diff --git a/tests/run-pass-fullmir/from_utf8.rs b/tests/run-pass/from_utf8.rs similarity index 100% rename from tests/run-pass-fullmir/from_utf8.rs rename to tests/run-pass/from_utf8.rs diff --git a/tests/run-pass-fullmir/hashmap.rs b/tests/run-pass/hashmap.rs similarity index 100% rename from tests/run-pass-fullmir/hashmap.rs rename to tests/run-pass/hashmap.rs diff --git a/tests/run-pass-fullmir/hello.rs b/tests/run-pass/hello.rs similarity index 100% rename from tests/run-pass-fullmir/hello.rs rename to tests/run-pass/hello.rs diff --git a/tests/run-pass-fullmir/hello.stdout b/tests/run-pass/hello.stdout similarity index 100% rename from tests/run-pass-fullmir/hello.stdout rename to tests/run-pass/hello.stdout diff --git a/tests/run-pass-fullmir/integer-ops.rs b/tests/run-pass/integer-ops.rs similarity index 100% rename from tests/run-pass-fullmir/integer-ops.rs rename to tests/run-pass/integer-ops.rs diff --git a/tests/run-pass-fullmir/issue-3794.rs b/tests/run-pass/issue-3794.rs similarity index 100% rename from tests/run-pass-fullmir/issue-3794.rs rename to tests/run-pass/issue-3794.rs diff --git a/tests/run-pass-fullmir/issue-3794.stdout b/tests/run-pass/issue-3794.stdout similarity index 100% rename from tests/run-pass-fullmir/issue-3794.stdout rename to tests/run-pass/issue-3794.stdout diff --git a/tests/run-pass-fullmir/loop-break-value.rs b/tests/run-pass/loop-break-value.rs similarity index 100% rename from tests/run-pass-fullmir/loop-break-value.rs rename to tests/run-pass/loop-break-value.rs diff --git a/tests/run-pass-fullmir/memchr.rs b/tests/run-pass/memchr.rs similarity index 100% rename from tests/run-pass-fullmir/memchr.rs rename to tests/run-pass/memchr.rs diff --git a/tests/run-pass-fullmir/send-is-not-static-par-for.rs b/tests/run-pass/send-is-not-static-par-for.rs similarity index 100% rename from tests/run-pass-fullmir/send-is-not-static-par-for.rs rename to tests/run-pass/send-is-not-static-par-for.rs diff --git a/tests/run-pass-fullmir/threads.rs b/tests/run-pass/threads.rs similarity index 100% rename from tests/run-pass-fullmir/threads.rs rename to tests/run-pass/threads.rs diff --git a/tests/run-pass-fullmir/u128.rs b/tests/run-pass/u128.rs similarity index 100% rename from tests/run-pass-fullmir/u128.rs rename to tests/run-pass/u128.rs diff --git a/tests/run-pass-fullmir/unsized-tuple-impls.rs b/tests/run-pass/unsized-tuple-impls.rs similarity index 100% rename from tests/run-pass-fullmir/unsized-tuple-impls.rs rename to tests/run-pass/unsized-tuple-impls.rs diff --git a/tests/run-pass-fullmir/vecdeque.rs b/tests/run-pass/vecdeque.rs similarity index 100% rename from tests/run-pass-fullmir/vecdeque.rs rename to tests/run-pass/vecdeque.rs From 4d767e1f415967a4ff58a2e88905d5c9f9c98453 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 10:10:03 +0100 Subject: [PATCH 4/8] MIRI_SYSROOT is no longer needed for development agains a locally built rustc --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 5f8f8fb850..1b9e5304bd 100644 --- a/README.md +++ b/README.md @@ -133,9 +133,6 @@ cp config.toml.example config.toml rustup toolchain link custom build/x86_64-unknown-linux-gnu/stage2 # Now cd to your Miri directory, then configure rustup rustup override set custom -# We also need to tell Miri where to find its sysroot. Since we set -# `test-miri` above, we can just use rustc' sysroot. -export MIRI_SYSROOT=$(rustc --print sysroot) ``` With this, you should now have a working development setup! See From b8e6af49d946b123181a15f34a7c0dad24a48d5e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 10:52:59 +0100 Subject: [PATCH 5/8] fix setting the manifest path manually when using cargo miri --- src/bin/cargo-miri.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 68da028a81..8a1a9d0554 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -75,7 +75,9 @@ fn get_arg_flag_value(name: &str) -> Option { fn list_targets() -> impl Iterator { // We need to get the manifest, and then the metadata, to enumerate targets. - let manifest_path = get_arg_flag_value("--manifest-path").map(PathBuf::from); + let manifest_path = get_arg_flag_value("--manifest-path").map(|m| + Path::new(&m).canonicalize().unwrap() + ); let mut metadata = if let Ok(metadata) = cargo_metadata::metadata( manifest_path.as_ref().map(AsRef::as_ref), From b50662d68c886de44628e7ce55e331515df6c5e0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 10:19:44 +0100 Subject: [PATCH 6/8] fix CI --- .travis.yml | 16 +++++++++++----- appveyor.yml | 5 ++--- src/bin/cargo-miri.rs | 9 ++++----- src/fn_call.rs | 2 ++ 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac3f16ce13..1d49394e29 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,13 +9,16 @@ cache: os: - linux - osx +dist: xenial before_script: +# install extra stuff for cross-compilation +- if [[ "$TRAVIS_OS_NAME" == linux ]]; then sudo apt update && sudo apt install gcc-multilib; fi # macOS weirdness (https://github.com/travis-ci/travis-ci/issues/6307, https://github.com/travis-ci/travis-ci/issues/10165) - if [[ "$TRAVIS_OS_NAME" == osx ]]; then rvm get stable; fi # Compute the rust version we use. We do not use "language: rust" to have more control here. - | - if [ "$TRAVIS_EVENT_TYPE" = cron ]; then + if [[ "$TRAVIS_EVENT_TYPE" == cron ]]; then RUST_TOOLCHAIN=nightly else RUST_TOOLCHAIN=$(cat rust-version) @@ -24,7 +27,7 @@ before_script: if [ "$TRAVIS_OS_NAME" == osx ]; then export MIRI_SYSROOT_BASE=~/Library/Caches/miri.miri.miri/ else - export MIRI_SYSROOT_BASE=~/.cache/miri/HOST + export MIRI_SYSROOT_BASE=~/.cache/miri/ fi # install Rust - curl https://build.travis-ci.org/files/rustup-init.sh -sSf | sh -s -- -y --default-toolchain "$RUST_TOOLCHAIN" @@ -38,10 +41,13 @@ script: cargo build --release --all-features --all-targets && cargo install --all-features --force --path . - | - # Get ourselves a MIR-full libstd + # Get ourselves a MIR-full libstd for the host and a foreign architecture cargo miri setup && - cargo miri setup --target i686-unknown-linux-gnu && - cargo miri setup --target i686-apple-darwin + if [[ "$TRAVIS_OS_NAME" == osx ]]; then + cargo miri setup --target i686-apple-darwin + else + cargo miri setup --target i686-unknown-linux-gnu + fi - | # Test miri with full MIR, on the host and other architectures MIRI_SYSROOT=$MIRI_SYSROOT_BASE/HOST cargo test --release --all-features && diff --git a/appveyor.yml b/appveyor.yml index 1f38b848c0..4f4aebd807 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,13 +27,12 @@ build: false test_script: - set RUSTFLAGS=-g - set RUST_BACKTRACE=1 - # Test plain miri + # Build miri - cargo build --release --all-features --all-targets - - cargo test --release --all-features # Get ourselves a MIR-full libstd, and use it henceforth - cargo run --release --all-features --bin cargo-miri -- miri setup - set MIRI_SYSROOT=%USERPROFILE%\AppData\Local\miri\miri\cache\HOST - # Test miri with full MIR + # Test miri - cargo test --release --all-features notifications: diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index 8a1a9d0554..7e1785fd3b 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -342,11 +342,11 @@ fn main() { .collect() }; args.splice(0..0, miri::miri_default_args().iter().map(ToString::to_string)); + args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]); // this check ensures that dependencies are built but not interpreted and the final crate is // interpreted but not built let miri_enabled = std::env::args().any(|s| s == "--emit=dep-info,metadata"); - let mut command = if miri_enabled { let mut path = std::env::current_exe().expect("current executable path invalid"); path.set_file_name("miri"); @@ -354,10 +354,9 @@ fn main() { } else { Command::new("rustc") }; + command.args(&args); - args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]); - - match command.args(&args).status() { + match command.status() { Ok(exit) => { if !exit.success() { std::process::exit(exit.code().unwrap_or(42)); @@ -388,7 +387,7 @@ where args.push(r#"feature="cargo-miri""#.to_owned()); let path = std::env::current_exe().expect("current executable path invalid"); - let exit_status = std::process::Command::new("cargo") + let exit_status = Command::new("cargo") .args(&args) .env("RUSTC", path) .spawn() diff --git a/src/fn_call.rs b/src/fn_call.rs index e9d3255a5b..701dc8ca92 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -113,6 +113,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo Some(name) => name.as_str(), None => self.tcx.item_name(def_id).as_str(), }; + // Strip linker suffixes (seen on 32bit macOS) + let link_name = link_name.trim_end_matches("$UNIX2003"); let tcx = &{self.tcx.tcx}; From 05f2b2ed3da6f504ac31d61e8bffb9a989780847 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 12:26:20 +0100 Subject: [PATCH 7/8] remove support for not having libstd MIR --- src/fn_call.rs | 84 +------------------------------- src/lib.rs | 128 +++++++++++++++++++++---------------------------- 2 files changed, 56 insertions(+), 156 deletions(-) diff --git a/src/fn_call.rs b/src/fn_call.rs index 701dc8ca92..e28497aa25 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -17,18 +17,6 @@ pub trait EvalContextExt<'tcx, 'mir> { ret: mir::BasicBlock, ) -> EvalResult<'tcx>; - /// Emulate a function that should have MIR but does not. - /// This is solely to support execution without full MIR. - /// Fail if emulating this function is not supported. - /// This function will handle `goto_block` if needed. - fn emulate_missing_fn( - &mut self, - path: String, - args: &[OpTy<'tcx, Borrow>], - dest: Option>, - ret: Option, - ) -> EvalResult<'tcx>; - fn find_fn( &mut self, instance: ty::Instance<'tcx>, @@ -81,24 +69,8 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo return Ok(None); } - // Otherwise we really want to see the MIR -- but if we do not have it, maybe we can - // emulate something. This is a HACK to support running without a full-MIR libstd. - let mir = match self.load_mir(instance.def) { - Ok(mir) => mir, - Err(EvalError { kind: EvalErrorKind::NoMirFor(path), .. }) => { - self.emulate_missing_fn( - path, - args, - dest, - ret, - )?; - // `goto_block` already handled - return Ok(None); - } - Err(other) => return Err(other), - }; - - Ok(Some(mir)) + // Otherwise, load the MIR + Ok(Some(self.load_mir(instance.def)?)) } fn emulate_foreign_item( @@ -657,58 +629,6 @@ impl<'a, 'mir, 'tcx: 'mir + 'a> EvalContextExt<'tcx, 'mir> for super::MiriEvalCo Ok(()) } - fn emulate_missing_fn( - &mut self, - path: String, - _args: &[OpTy<'tcx, Borrow>], - dest: Option>, - ret: Option, - ) -> EvalResult<'tcx> { - // In some cases in non-MIR libstd-mode, not having a destination is legit. Handle these early. - match &path[..] { - "std::panicking::rust_panic_with_hook" | - "core::panicking::panic_fmt::::panic_impl" | - "std::rt::begin_panic_fmt" => - return err!(MachineError("the evaluated program panicked".to_string())), - _ => {} - } - - let dest = dest.ok_or_else( - // Must be some function we do not support - || EvalErrorKind::NoMirFor(path.clone()), - )?; - - match &path[..] { - // A Rust function is missing, which means we are running with MIR missing for libstd (or other dependencies). - // Still, we can make many things mostly work by "emulating" or ignoring some functions. - "std::io::_print" | - "std::io::_eprint" => { - warn!( - "Ignoring output. To run programs that prints, make sure you have a libstd with full MIR." - ); - } - "std::thread::Builder::new" => { - return err!(Unimplemented("miri does not support threading".to_owned())) - } - "std::env::args" => { - return err!(Unimplemented( - "miri does not support program arguments".to_owned(), - )) - } - "std::panicking::panicking" | - "std::rt::panicking" => { - // we abort on panic -> `std::rt::panicking` always returns false - self.write_scalar(Scalar::from_bool(false), dest)?; - } - - _ => return err!(NoMirFor(path)), - } - - self.goto_block(ret)?; - self.dump_place(*dest); - Ok(()) - } - fn write_null(&mut self, dest: PlaceTy<'tcx, Borrow>) -> EvalResult<'tcx> { self.write_scalar(Scalar::from_int(0, dest.layout.size), dest) } diff --git a/src/lib.rs b/src/lib.rs index 71abff2675..9641670a2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,82 +80,62 @@ pub fn create_ecx<'a, 'mir: 'a, 'tcx: 'mir>( )); } - let libstd_has_mir = { - let rustc_panic = ecx.resolve_path(&["std", "panicking", "rust_panic"])?; - ecx.load_mir(rustc_panic.def).is_ok() - }; - - if libstd_has_mir { - let start_id = tcx.lang_items().start_fn().unwrap(); - let main_ret_ty = tcx.fn_sig(main_id).output(); - let main_ret_ty = main_ret_ty.no_bound_vars().unwrap(); - let start_instance = ty::Instance::resolve( - ecx.tcx.tcx, - ty::ParamEnv::reveal_all(), - start_id, - ecx.tcx.mk_substs( - ::std::iter::once(ty::subst::Kind::from(main_ret_ty))) - ).unwrap(); - let start_mir = ecx.load_mir(start_instance.def)?; - - if start_mir.arg_count != 3 { - return err!(AbiViolation(format!( - "'start' lang item should have three arguments, but has {}", - start_mir.arg_count - ))); - } - - // Return value (in static memory so that it does not count as leak) - let ret = ecx.layout_of(start_mir.return_ty())?; - let ret_ptr = ecx.allocate(ret, MiriMemoryKind::MutStatic.into())?; - - // Push our stack frame - ecx.push_stack_frame( - start_instance, - DUMMY_SP, // there is no call site, we want no span - start_mir, - Some(ret_ptr.into()), - StackPopCleanup::None { cleanup: true }, - )?; - - let mut args = ecx.frame().mir.args_iter(); - - // First argument: pointer to main() - let main_ptr = ecx.memory_mut().create_fn_alloc(main_instance).with_default_tag(); - let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; - ecx.write_scalar(Scalar::Ptr(main_ptr), dest)?; - - // Second argument (argc): 1 - let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; - ecx.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?; - - // FIXME: extract main source file path - // Third argument (argv): &[b"foo"] - let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; - let foo = ecx.memory_mut().allocate_static_bytes(b"foo\0").with_default_tag(); - let foo_ty = ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8); - let foo_layout = ecx.layout_of(foo_ty)?; - let foo_place = ecx.allocate(foo_layout, MiriMemoryKind::Env.into())?; - ecx.write_scalar(Scalar::Ptr(foo), foo_place.into())?; - ecx.memory_mut().mark_immutable(foo_place.to_ptr()?.alloc_id)?; - ecx.write_scalar(foo_place.ptr, dest)?; - - assert!(args.next().is_none(), "start lang item has more arguments than expected"); - } else { - let ret_place = MPlaceTy::dangling(ecx.layout_of(tcx.mk_unit())?, &ecx).into(); - ecx.push_stack_frame( - main_instance, - DUMMY_SP, // there is no call site, we want no span - main_mir, - Some(ret_place), - StackPopCleanup::None { cleanup: true }, - )?; - - // No arguments - let mut args = ecx.frame().mir.args_iter(); - assert!(args.next().is_none(), "main function must not have arguments"); + let start_id = tcx.lang_items().start_fn().unwrap(); + let main_ret_ty = tcx.fn_sig(main_id).output(); + let main_ret_ty = main_ret_ty.no_bound_vars().unwrap(); + let start_instance = ty::Instance::resolve( + ecx.tcx.tcx, + ty::ParamEnv::reveal_all(), + start_id, + ecx.tcx.mk_substs( + ::std::iter::once(ty::subst::Kind::from(main_ret_ty))) + ).unwrap(); + let start_mir = ecx.load_mir(start_instance.def)?; + + if start_mir.arg_count != 3 { + return err!(AbiViolation(format!( + "'start' lang item should have three arguments, but has {}", + start_mir.arg_count + ))); } + // Return value (in static memory so that it does not count as leak) + let ret = ecx.layout_of(start_mir.return_ty())?; + let ret_ptr = ecx.allocate(ret, MiriMemoryKind::MutStatic.into())?; + + // Push our stack frame + ecx.push_stack_frame( + start_instance, + DUMMY_SP, // there is no call site, we want no span + start_mir, + Some(ret_ptr.into()), + StackPopCleanup::None { cleanup: true }, + )?; + + let mut args = ecx.frame().mir.args_iter(); + + // First argument: pointer to main() + let main_ptr = ecx.memory_mut().create_fn_alloc(main_instance).with_default_tag(); + let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; + ecx.write_scalar(Scalar::Ptr(main_ptr), dest)?; + + // Second argument (argc): 1 + let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; + ecx.write_scalar(Scalar::from_int(1, dest.layout.size), dest)?; + + // FIXME: extract main source file path + // Third argument (argv): &[b"foo"] + let dest = ecx.eval_place(&mir::Place::Local(args.next().unwrap()))?; + let foo = ecx.memory_mut().allocate_static_bytes(b"foo\0").with_default_tag(); + let foo_ty = ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8); + let foo_layout = ecx.layout_of(foo_ty)?; + let foo_place = ecx.allocate(foo_layout, MiriMemoryKind::Env.into())?; + ecx.write_scalar(Scalar::Ptr(foo), foo_place.into())?; + ecx.memory_mut().mark_immutable(foo_place.to_ptr()?.alloc_id)?; + ecx.write_scalar(foo_place.ptr, dest)?; + + assert!(args.next().is_none(), "start lang item has more arguments than expected"); + Ok(ecx) } From 5689366a0d47ced0e7ed85abed168493d82555c5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Dec 2018 13:14:46 +0100 Subject: [PATCH 8/8] use rustc_version also to parse host in compiletest --- tests/compiletest.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/compiletest.rs b/tests/compiletest.rs index f0ebbf6b07..7187a3caee 100644 --- a/tests/compiletest.rs +++ b/tests/compiletest.rs @@ -142,17 +142,15 @@ fn get_sysroot() -> PathBuf { fn get_host() -> String { let rustc = rustc_test_suite().unwrap_or(PathBuf::from("rustc")); - let host = std::process::Command::new(rustc) + let rustc_version = std::process::Command::new(rustc) .arg("-vV") .output() .expect("rustc not found for -vV") .stdout; - let host = std::str::from_utf8(&host).expect("sysroot is not utf8"); - let host = host.split("\nhost: ").nth(1).expect( - "no host: part in rustc -vV", - ); - let host = host.split('\n').next().expect("no \n after host"); - String::from(host) + let rustc_version = std::str::from_utf8(&rustc_version).expect("rustc -vV is not utf8"); + let version_meta = rustc_version::version_meta_for(&rustc_version) + .expect("failed to parse rustc version info"); + version_meta.host } fn run_pass_miri(opt: bool) {