diff --git a/.gitignore b/.gitignore deleted file mode 100644 index d32d9eb99afd..000000000000 --- a/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -target -/doc -tex/*/out -*.dot -*.mir -*.rs.bk diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 86577702e96d..000000000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ -language: rust -rust: -- nightly -before_script: -- export PATH=$HOME/.local/bin:$PATH -- rustup target add i686-unknown-linux-gnu -- rustup target add i686-pc-windows-gnu -- rustup target add i686-pc-windows-msvc -- rustup component add rust-src -- cargo install --git https://github.com/japaric/xargo.git -- export RUST_SYSROOT=$HOME/rust -script: -- set -e -- | - # get ourselves a MIR-ful libstd - xargo/build.sh -- | - # Test plain miri - cargo build --locked --release --all-features && - cargo test --locked --release --all-features --all && - cargo install --locked --all-features -- | - # Test cargo miri - cd cargo-miri-test && - cargo miri && - cargo miri test && - cd .. -- | - # and run all tests with full mir - MIRI_SYSROOT=~/.xargo/HOST cargo test --locked --release -- | - # test that the rustc_tests binary compiles - cd rustc_tests && - cargo build --locked --release && - cd .. -notifications: - email: - on_success: never -branches: - only: - - master -env: - global: - - RUST_TEST_NOCAPTURE=1 - - TRAVIS_CARGO_NIGHTLY_FEATURE="" diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index c84d79a089c3..000000000000 --- a/Cargo.lock +++ /dev/null @@ -1,413 +0,0 @@ -[root] -name = "rustc_miri" -version = "0.1.0" -dependencies = [ - "backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "aho-corasick" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "bitflags" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "byteorder" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cargo_metadata" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cfg-if" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "compiletest_rs" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", - "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "conv" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "custom_derive" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "dbghelp-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "diff" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "dtoa" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "env_logger" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "filetime" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gcc" -version = "0.3.53" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "getopts" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "itoa" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazy_static" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.30" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log_settings" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "magenta" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "magenta-sys" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "memchr" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "miri" -version = "0.1.0" -dependencies = [ - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "compiletest_rs 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_miri 0.1.0", -] - -[[package]] -name = "num-traits" -version = "0.1.40" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "quote" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rand" -version = "0.3.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc-demangle" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "serde_derive" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_derive_internals" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "serde_json" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "syn" -version = "0.11.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", - "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "synom" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "tempdir" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unicode-xid" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "utf8-ranges" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" -"checksum backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "99f2ce94e22b8e664d95c57fff45b98a966c2252b60691d0b7aeeccd88d70983" -"checksum backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "afccc5772ba333abccdf60d55200fa3406f8c59dcf54d5f7998c9107d3799c7c" -"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" -"checksum cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "be1057b8462184f634c3a208ee35b0f935cfd94b694b26deadccd98732088d7b" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -"checksum compiletest_rs 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86f4663adfd113e17109c35c2067194eca782a5baf9c90f4696ca13d04631adb" -"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" -"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" -"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" -"checksum diff 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0a515461b6c8c08419850ced27bc29e86166dcdcde8fbe76f8b1f0589bb49472" -"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" -"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" -"checksum filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "5363ab8e4139b8568a6237db5248646e5a8a2f89bd5ccb02092182b11fd3e922" -"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" -"checksum getopts 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "65922871abd2f101a2eb0eaebadc66668e54a87ad9c3dd82520b5f86ede5eff9" -"checksum itoa 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f74cf6ca1bdbc28496a2b9798ab7fccc2ca5a42cace95bb2b219577216a5fb90" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" -"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" -"checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6" -"checksum magenta 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf0336886480e671965f794bc9b6fce88503563013d1bfb7a502c81fe3ac527" -"checksum magenta-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40d014c7011ac470ae28e2f76a02bfea4a8480f73e701353b49ad7a8d75f4699" -"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" -"checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0" -"checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum rand 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "eb250fd207a4729c976794d03db689c9be1d634ab5a1c9da9492a13d8fecbcdf" -"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" -"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" -"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" -"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" -"checksum serde 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f7726f29ddf9731b17ff113c461e362c381d9d69433f79de4f3dd572488823e9" -"checksum serde_derive 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cf823e706be268e73e7747b147aa31c8f633ab4ba31f115efb57e5047c3a76dd" -"checksum serde_derive_internals 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "37aee4e0da52d801acfbc0cc219eb1eda7142112339726e427926a6f6ee65d3a" -"checksum serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "48b04779552e92037212c3615370f6bd57a40ebba7f20e554ff9f55e41a69a7b" -"checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -"checksum tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "87974a6f5c1dfb344d733055601650059a3363de2a6104819293baff662132d6" -"checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" -"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/Cargo.toml b/Cargo.toml deleted file mode 100644 index b3db572871da..000000000000 --- a/Cargo.toml +++ /dev/null @@ -1,39 +0,0 @@ -[package] -authors = ["Scott Olson "] -description = "An experimental interpreter for Rust MIR." -license = "MIT/Apache-2.0" -name = "miri" -repository = "https://github.com/solson/miri" -version = "0.1.0" -build = "build.rs" - -[[bin]] -doc = false -name = "miri" -path = "miri/bin/miri.rs" - -[[bin]] -doc = false -name = "cargo-miri" -path = "miri/bin/cargo-miri.rs" -required-features = ["cargo_miri"] - -[lib] -path = "miri/lib.rs" - -[dependencies] -byteorder = { version = "1.1", features = ["i128"]} -env_logger = "0.4.3" -log = "0.3.6" -log_settings = "0.1.1" -cargo_metadata = { version = "0.2", optional = true } -rustc_miri = { path = "src/librustc_mir" } - -[features] -cargo_miri = ["cargo_metadata"] - -[dev-dependencies] -compiletest_rs = { version = "0.3", features = ["tmp"] } - -[workspace] -exclude = ["xargo", "cargo-miri-test", "rustc_tests"] diff --git a/LICENSE-APACHE b/LICENSE-APACHE deleted file mode 100644 index a32595fa70bc..000000000000 --- a/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - -1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - -2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - -3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - -4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - -5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - -6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - -7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - -8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - -9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright 2016 The Miri Developers - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/LICENSE-MIT b/LICENSE-MIT deleted file mode 100644 index 1f9d89a5862b..000000000000 --- a/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2016 The Miri Developers - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 22cb5aed79b1..000000000000 --- a/README.md +++ /dev/null @@ -1,103 +0,0 @@ -# Miri [[slides](https://solson.me/miri-slides.pdf)] [[report](https://solson.me/miri-report.pdf)] [![Build Status](https://travis-ci.org/solson/miri.svg?branch=master)](https://travis-ci.org/solson/miri) [![Windows build status](https://ci.appveyor.com/api/projects/status/github/solson/miri?svg=true)](https://ci.appveyor.com/project/solson63299/miri) - - -An experimental interpreter for [Rust][rust]'s [mid-level intermediate -representation][mir] (MIR). This project began as part of my work for the -undergraduate research course at the [University of Saskatchewan][usask]. - -## Installing Rust - -I recommend that you install [rustup][rustup] and then use it to install the -current Rust nightly version: - -```sh -rustup update nightly -``` - -You should also make `nightly` the default version for your Miri directory by -running the following command while you're in it. If you don't do this, you can -run the later `cargo` commands by using `cargo +nightly` instead. - -```sh -rustup override add nightly -``` - -## Building Miri - -```sh -cargo build -``` - -If Miri fails to build, it's likely because a change in the latest nightly -compiler broke it. You could try an older nightly with `rustup update -nightly-` where `` is a few days or weeks ago, e.g. `2016-05-20` for -May 20th. Otherwise, you could notify me in an issue or on IRC. Or, if you know -how to fix it, you could send a PR. :smile: - -## Running tests - -```sh -cargo run --bin miri tests/run-pass/vecs.rs # Or whatever test you like. -``` - -## Debugging - -You can get detailed, statement-by-statement traces by setting the `MIRI_LOG` -environment variable to `trace`. These traces are indented based on call stack -depth. You can get a much less verbose set of information with other logging -levels such as `warn`. - -## Running miri on your own project('s test suite) - -Install miri as a cargo subcommand with `cargo install --debug`. -Then, inside your own project, use `cargo +nightly miri` to run your project, if it is -a bin project, or run `cargo +nightly miri test` to run all tests in your project -through miri. - -## Running miri with full libstd - -Per default libstd does not contain the MIR of non-polymorphic functions. When -miri hits a call to such a function, execution terminates. To fix this, it is -possible to compile libstd with full MIR: - -```sh -rustup component add rust-src -cargo install xargo -cd xargo/ -RUSTFLAGS='-Zalways-encode-mir' xargo build -``` - -Now you can run miri against the libstd compiled by xargo: - -```sh -MIRI_SYSROOT=~/.xargo/HOST cargo run --bin miri tests/run-pass-fullmir/vecs.rs -``` - -Notice that you will have to re-run the last step of the preparations above when -your toolchain changes (e.g., when you update the nightly). - -## Contributing and getting help - -Check out the issues on this GitHub repository for some ideas. There's lots that -needs to be done that I haven't documented in the issues yet, however. For more -ideas or help with running or hacking on Miri, you can contact me (`scott`) on -Mozilla IRC in any of the Rust IRC channels (`#rust`, `#rust-offtopic`, etc). - -## License - -Licensed under either of - * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or - http://www.apache.org/licenses/LICENSE-2.0) - * MIT license ([LICENSE-MIT](LICENSE-MIT) or - http://opensource.org/licenses/MIT) at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted -for inclusion in the work by you shall be dual licensed as above, without any -additional terms or conditions. - -[rust]: https://www.rust-lang.org/ -[mir]: https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md -[usask]: https://www.usask.ca/ -[rustup]: https://www.rustup.rs diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 86f9b19af87f..000000000000 --- a/appveyor.yml +++ /dev/null @@ -1,41 +0,0 @@ -environment: - global: - PROJECT_NAME: miri - matrix: - - TARGET: i686-pc-windows-msvc - MSYS2_BITS: 32 - - TARGET: x86_64-pc-windows-msvc - MSYS2_BITS: 64 - -# branches to build -branches: - # whitelist - only: - - master - -install: - - set PATH=C:\Program Files\Git\mingw64\bin;%PATH% - - curl -sSf -o rustup-init.exe https://win.rustup.rs/ - - rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly - - set PATH=%PATH%;C:\Users\appveyor\.cargo\bin;C:\Users\appveyor\.rustup\toolchains\nightly-%TARGET%\bin - - if defined MSYS2_BITS set PATH=%PATH%;C:\msys64\mingw%MSYS2_BITS%\bin - - rustc -V - - cargo -V - - rustup component add rust-src - - cargo install --git https://github.com/japaric/xargo.git - - cd xargo - - set RUSTFLAGS=-Zalways-encode-mir -Zmir-emit-validate=1 - - xargo build - - set RUSTFLAGS= - - cd .. - -build: false - -test_script: - - set RUST_BACKTRACE=1 - - cargo build --locked --release - - cargo test --locked --release - -notifications: - - provider: Email - on_build_success: false diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs deleted file mode 100644 index 90b231a32bfb..000000000000 --- a/benches/fibonacci.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(test, rustc_private)] - -extern crate test; -use test::Bencher; -mod helpers; -use helpers::*; - -#[bench] -fn fib(bencher: &mut Bencher) { - bencher.iter(|| { fibonacci_helper::main(); }) -} - -#[bench] -fn fib_miri(bencher: &mut Bencher) { - miri_helper::run("fibonacci_helper", bencher); -} - -#[bench] -fn fib_iter(bencher: &mut Bencher) { - bencher.iter(|| { fibonacci_helper_iterative::main(); }) -} - -#[bench] -fn fib_iter_miri(bencher: &mut Bencher) { - miri_helper::run("fibonacci_helper_iterative", bencher); -} diff --git a/benches/helpers/fibonacci_helper.rs b/benches/helpers/fibonacci_helper.rs deleted file mode 100644 index 586f1ce7da4d..000000000000 --- a/benches/helpers/fibonacci_helper.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[inline(never)] -pub fn main() { - assert_eq!(fib(10), 55); -} - -fn fib(n: usize) -> usize { - if n <= 2 { 1 } else { fib(n - 1) + fib(n - 2) } -} diff --git a/benches/helpers/fibonacci_helper_iterative.rs b/benches/helpers/fibonacci_helper_iterative.rs deleted file mode 100644 index 59283be4820f..000000000000 --- a/benches/helpers/fibonacci_helper_iterative.rs +++ /dev/null @@ -1,15 +0,0 @@ -#[inline(never)] -pub fn main() { - assert_eq!(fib(10), 55); -} - -fn fib(n: usize) -> usize { - let mut a = 0; - let mut b = 1; - for _ in 0..n { - let c = a; - a = b; - b = c + b; - } - a -} diff --git a/benches/helpers/miri_helper.rs b/benches/helpers/miri_helper.rs deleted file mode 100644 index 6657ba119976..000000000000 --- a/benches/helpers/miri_helper.rs +++ /dev/null @@ -1,75 +0,0 @@ -extern crate getopts; -extern crate miri; -extern crate rustc; -extern crate rustc_driver; -extern crate test; - -use self::miri::eval_main; -use self::rustc::session::Session; -use self::rustc_driver::{driver, CompilerCalls, Compilation}; -use std::cell::RefCell; -use std::rc::Rc; -use test::Bencher; - -pub struct MiriCompilerCalls<'a>(Rc>); - -fn find_sysroot() -> String { - // Taken from https://github.com/Manishearth/rust-clippy/pull/911. - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - match (home, toolchain) { - (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => { - option_env!("RUST_SYSROOT") - .expect( - "need to specify RUST_SYSROOT env var or use rustup or multirust", - ) - .to_owned() - } - } -} - -pub fn run(filename: &str, bencher: &mut Bencher) { - let args = &[ - "miri".to_string(), - format!("benches/helpers/{}.rs", filename), - "--sysroot".to_string(), - find_sysroot(), - ]; - let compiler_calls = &mut MiriCompilerCalls(Rc::new(RefCell::new(bencher))); - rustc_driver::run_compiler(args, compiler_calls, None, None); -} - -impl<'a> CompilerCalls<'a> for MiriCompilerCalls<'a> { - fn build_controller( - &mut self, - _: &Session, - _: &getopts::Matches, - ) -> driver::CompileController<'a> { - let mut control: driver::CompileController<'a> = driver::CompileController::basic(); - - let bencher = self.0.clone(); - - control.after_analysis.stop = Compilation::Stop; - control.after_analysis.callback = Box::new(move |state| { - state.session.abort_if_errors(); - - let tcx = state.tcx.unwrap(); - let (entry_node_id, _) = state.session.entry_fn.borrow().expect( - "no main or start function found", - ); - let entry_def_id = tcx.map.local_def_id(entry_node_id); - - let memory_size = 100 * 1024 * 1024; // 100MB - let step_limit = 1000_000; - let stack_limit = 100; - bencher.borrow_mut().iter(|| { - eval_main(tcx, entry_def_id, memory_size, step_limit, stack_limit); - }); - - state.session.abort_if_errors(); - }); - - control - } -} diff --git a/benches/helpers/mod.rs b/benches/helpers/mod.rs deleted file mode 100644 index 27504a2cc034..000000000000 --- a/benches/helpers/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -// This module gets included in multiple crates, and they each only use part of it. -#![allow(dead_code)] - -pub mod fibonacci_helper; -pub mod fibonacci_helper_iterative; -pub mod miri_helper; -pub mod smoke_helper; diff --git a/benches/helpers/repeat.rs b/benches/helpers/repeat.rs deleted file mode 100644 index 0e8c5980b82b..000000000000 --- a/benches/helpers/repeat.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let data: [u8; 1024] = [42; 1024]; - assert_eq!(data.len(), 1024); -} diff --git a/benches/helpers/repeat_manual.rs b/benches/helpers/repeat_manual.rs deleted file mode 100644 index 6ef6f724efce..000000000000 --- a/benches/helpers/repeat_manual.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let mut data: [u8; 1024] = unsafe { std::mem::uninitialized() }; - for i in 0..data.len() { - unsafe { std::ptr::write(&mut data[i], 0); } - } - assert_eq!(data.len(), 1024); -} diff --git a/benches/helpers/smoke_helper.rs b/benches/helpers/smoke_helper.rs deleted file mode 100644 index e81db817aeac..000000000000 --- a/benches/helpers/smoke_helper.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[inline(never)] -pub fn main() {} diff --git a/benches/repeat.rs b/benches/repeat.rs deleted file mode 100644 index f5920e83d9b0..000000000000 --- a/benches/repeat.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(test, rustc_private)] - -extern crate test; -use test::Bencher; -mod helpers; -use helpers::*; - -#[bench] -fn repeat(bencher: &mut Bencher) { - miri_helper::run("repeat", bencher); -} - -#[bench] -fn repeat_manual(bencher: &mut Bencher) { - miri_helper::run("repeat_manual", bencher); -} diff --git a/benches/smoke.rs b/benches/smoke.rs deleted file mode 100644 index 1dbc4fed82f1..000000000000 --- a/benches/smoke.rs +++ /dev/null @@ -1,35 +0,0 @@ -#![feature(test, rustc_private)] - -extern crate test; -use test::Bencher; -mod helpers; -use helpers::*; - -#[bench] -fn noop(bencher: &mut Bencher) { - bencher.iter(|| { smoke_helper::main(); }) -} - -/* -// really slow -#[bench] -fn noop_miri_full(bencher: &mut Bencher) { - let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set"); - bencher.iter(|| { - let mut process = std::process::Command::new("target/release/miri"); - process.arg("benches/smoke_helper.rs") - .arg("--sysroot").arg(&path); - let output = process.output().unwrap(); - if !output.status.success() { - println!("{}", String::from_utf8(output.stdout).unwrap()); - println!("{}", String::from_utf8(output.stderr).unwrap()); - panic!("failed to run miri"); - } - }) -} -*/ - -#[bench] -fn noop_miri_interpreter(bencher: &mut Bencher) { - miri_helper::run("smoke_helper", bencher); -} diff --git a/build.rs b/build.rs deleted file mode 100644 index 2f74f7f4f616..000000000000 --- a/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -use std::env; - -fn main() { - // Forward the profile to the main compilation - println!("cargo:rustc-env=PROFILE={}", env::var("PROFILE").unwrap()); - // Don't rebuild miri even if nothing changed - println!("cargo:rerun-if-changed=build.rs"); -} diff --git a/cargo-miri-test/Cargo.lock b/cargo-miri-test/Cargo.lock deleted file mode 100644 index 8b2387fa6410..000000000000 --- a/cargo-miri-test/Cargo.lock +++ /dev/null @@ -1,14 +0,0 @@ -[root] -name = "cargo-miri-test" -version = "0.1.0" -dependencies = [ - "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "byteorder" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" diff --git a/cargo-miri-test/Cargo.toml b/cargo-miri-test/Cargo.toml deleted file mode 100644 index 5fbe923f23d3..000000000000 --- a/cargo-miri-test/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "cargo-miri-test" -version = "0.1.0" -authors = ["Oliver Schneider "] - -[dependencies] -byteorder = "1.0" \ No newline at end of file diff --git a/cargo-miri-test/src/main.rs b/cargo-miri-test/src/main.rs deleted file mode 100644 index 07b0e4cee4e5..000000000000 --- a/cargo-miri-test/src/main.rs +++ /dev/null @@ -1,9 +0,0 @@ -extern crate byteorder; - -use byteorder::{BigEndian, ByteOrder}; - -fn main() { - let buf = &[1,2,3,4]; - let n = ::read_u32(buf); - assert_eq!(n, 0x01020304); -} diff --git a/cargo-miri-test/tests/foo.rs b/cargo-miri-test/tests/foo.rs deleted file mode 100644 index fb7fad21c9db..000000000000 --- a/cargo-miri-test/tests/foo.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[test] -fn bar() { - assert_eq!(4, 4); -} diff --git a/miri/bin/cargo-miri.rs b/miri/bin/cargo-miri.rs deleted file mode 100644 index 06d5b3e9971f..000000000000 --- a/miri/bin/cargo-miri.rs +++ /dev/null @@ -1,212 +0,0 @@ -extern crate cargo_metadata; - -use std::path::{PathBuf, Path}; -use std::io::Write; -use std::process::Command; - - -const CARGO_MIRI_HELP: &str = r#"Interprets bin crates - -Usage: - cargo miri [options] [--] [...] - -Common options: - -h, --help Print this message - --features Features to compile for the package - -V, --version Print version info and exit - -Other options are the same as `cargo rustc`. - -The feature `cargo-miri` is automatically defined for convenience. You can use -it to configure the resource limits - - #![cfg_attr(feature = "cargo-miri", memory_size = 42)] - -available resource limits are `memory_size`, `step_limit`, `stack_limit` -"#; - -fn show_help() { - println!("{}", CARGO_MIRI_HELP); -} - -fn show_version() { - println!("{}", env!("CARGO_PKG_VERSION")); -} - -fn main() { - // Check for version and help flags even when invoked as 'cargo-miri' - if std::env::args().any(|a| a == "--help" || a == "-h") { - show_help(); - return; - } - if std::env::args().any(|a| a == "--version" || a == "-V") { - show_version(); - return; - } - - if let Some("miri") = std::env::args().nth(1).as_ref().map(AsRef::as_ref) { - // this arm is when `cargo miri` is called - - let test = std::env::args().nth(2).map_or(false, |text| text == "test"); - let skip = if test { 3 } else { 2 }; - - let manifest_path_arg = std::env::args().skip(skip).find(|val| { - val.starts_with("--manifest-path=") - }); - - let mut metadata = if let Ok(metadata) = cargo_metadata::metadata( - manifest_path_arg.as_ref().map(AsRef::as_ref), - ) - { - metadata - } else { - let _ = std::io::stderr().write_fmt(format_args!( - "error: Could not obtain cargo metadata." - )); - std::process::exit(101); - }; - - let manifest_path = manifest_path_arg.map(|arg| { - PathBuf::from(Path::new(&arg["--manifest-path=".len()..])) - }); - - let current_dir = std::env::current_dir(); - - let package_index = metadata - .packages - .iter() - .position(|package| { - let package_manifest_path = Path::new(&package.manifest_path); - if let Some(ref manifest_path) = manifest_path { - package_manifest_path == manifest_path - } else { - let current_dir = current_dir.as_ref().expect( - "could not read current directory", - ); - let package_manifest_directory = package_manifest_path.parent().expect( - "could not find parent directory of package manifest", - ); - package_manifest_directory == current_dir - } - }) - .expect("could not find matching package"); - let package = metadata.packages.remove(package_index); - for target in package.targets { - let args = std::env::args().skip(skip); - let kind = target.kind.get(0).expect( - "badly formatted cargo metadata: target::kind is an empty array", - ); - if test && kind == "test" { - if let Err(code) = process( - vec!["--test".to_string(), target.name].into_iter().chain( - args, - ), - ) - { - std::process::exit(code); - } - } else if !test && kind == "bin" { - if let Err(code) = process( - vec!["--bin".to_string(), target.name].into_iter().chain( - args, - ), - ) - { - std::process::exit(code); - } - } - } - } else { - // this arm is executed when cargo-miri runs `cargo rustc` with the `RUSTC` env var set to itself - - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - let sys_root = if let (Some(home), Some(toolchain)) = (home, toolchain) { - format!("{}/toolchains/{}", home, toolchain) - } else { - option_env!("RUST_SYSROOT") - .map(|s| s.to_owned()) - .or_else(|| { - Command::new("rustc") - .arg("--print") - .arg("sysroot") - .output() - .ok() - .and_then(|out| String::from_utf8(out.stdout).ok()) - .map(|s| s.trim().to_owned()) - }) - .expect("need to specify RUST_SYSROOT env var during miri compilation, or use rustup or multirust") - }; - - // this conditional check for the --sysroot flag is there so users can call `cargo-miri` directly - // without having to pass --sysroot or anything - let mut args: Vec = if std::env::args().any(|s| s == "--sysroot") { - std::env::args().skip(1).collect() - } else { - std::env::args() - .skip(1) - .chain(Some("--sysroot".to_owned())) - .chain(Some(sys_root)) - .collect() - }; - - // 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 == "-Zno-trans"); - - let mut command = if miri_enabled { - let mut path = std::env::current_exe().expect("current executable path invalid"); - path.set_file_name("miri"); - Command::new(path) - } else { - Command::new("rustc") - }; - - args.extend_from_slice(&["-Z".to_owned(), "always-encode-mir".to_owned()]); - args.extend_from_slice(&["--cfg".to_owned(), r#"feature="cargo-miri""#.to_owned()]); - - match command.args(&args).status() { - Ok(exit) => { - if !exit.success() { - std::process::exit(exit.code().unwrap_or(42)); - } - } - Err(ref e) if miri_enabled => panic!("error during miri run: {:?}", e), - Err(ref e) => panic!("error during rustc call: {:?}", e), - } - } -} - -fn process(old_args: I) -> Result<(), i32> -where - I: Iterator, -{ - let mut args = vec!["rustc".to_owned()]; - - let mut found_dashes = false; - for arg in old_args { - found_dashes |= arg == "--"; - args.push(arg); - } - if !found_dashes { - args.push("--".to_owned()); - } - args.push("-Zno-trans".to_owned()); - args.push("--cfg".to_owned()); - 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") - .args(&args) - .env("RUSTC", path) - .spawn() - .expect("could not run cargo") - .wait() - .expect("failed to wait for cargo?"); - - if exit_status.success() { - Ok(()) - } else { - Err(exit_status.code().unwrap_or(-1)) - } -} diff --git a/miri/bin/miri.rs b/miri/bin/miri.rs deleted file mode 100644 index d38f63610a0e..000000000000 --- a/miri/bin/miri.rs +++ /dev/null @@ -1,265 +0,0 @@ -#![feature(rustc_private, i128_type)] - -extern crate getopts; -extern crate miri; -extern crate rustc; -extern crate rustc_driver; -extern crate rustc_errors; -extern crate env_logger; -extern crate log_settings; -extern crate syntax; -extern crate log; - -use rustc::session::Session; -use rustc::middle::cstore::CrateStore; -use rustc_driver::{Compilation, CompilerCalls, RustcDefaultCalls}; -use rustc_driver::driver::{CompileState, CompileController}; -use rustc::session::config::{self, Input, ErrorOutputType}; -use rustc::hir::{self, itemlikevisit}; -use rustc::ty::TyCtxt; -use syntax::ast::{self, MetaItemKind, NestedMetaItemKind}; -use std::path::PathBuf; - -struct MiriCompilerCalls { - default: RustcDefaultCalls, -} - -impl<'a> CompilerCalls<'a> for MiriCompilerCalls { - fn early_callback( - &mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - descriptions: &rustc_errors::registry::Registry, - output: ErrorOutputType, - ) -> Compilation { - self.default.early_callback( - matches, - sopts, - cfg, - descriptions, - output, - ) - } - fn no_input( - &mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - odir: &Option, - ofile: &Option, - descriptions: &rustc_errors::registry::Registry, - ) -> Option<(Input, Option)> { - self.default.no_input( - matches, - sopts, - cfg, - odir, - ofile, - descriptions, - ) - } - fn late_callback( - &mut self, - matches: &getopts::Matches, - sess: &Session, - cstore: &CrateStore, - input: &Input, - odir: &Option, - ofile: &Option, - ) -> Compilation { - self.default.late_callback(matches, sess, cstore, input, odir, ofile) - } - fn build_controller( - &mut self, - sess: &Session, - matches: &getopts::Matches, - ) -> CompileController<'a> { - let mut control = self.default.build_controller(sess, matches); - control.after_hir_lowering.callback = Box::new(after_hir_lowering); - control.after_analysis.callback = Box::new(after_analysis); - if sess.target.target != sess.host { - // only fully compile targets on the host. linking will fail for cross-compilation. - control.after_analysis.stop = Compilation::Stop; - } - control - } -} - -fn after_hir_lowering(state: &mut CompileState) { - let attr = ( - String::from("miri"), - syntax::feature_gate::AttributeType::Whitelisted, - ); - state.session.plugin_attributes.borrow_mut().push(attr); -} - -fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) { - state.session.abort_if_errors(); - - let tcx = state.tcx.unwrap(); - let limits = resource_limits_from_attributes(state); - - if std::env::args().any(|arg| arg == "--test") { - struct Visitor<'a, 'tcx: 'a>( - miri::ResourceLimits, - TyCtxt<'a, 'tcx, 'tcx>, - &'a CompileState<'a, 'tcx> - ); - impl<'a, 'tcx: 'a, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'a, 'tcx> { - fn visit_item(&mut self, i: &'hir hir::Item) { - if let hir::Item_::ItemFn(_, _, _, _, _, body_id) = i.node { - if i.attrs.iter().any(|attr| { - attr.name().map_or(false, |n| n == "test") - }) - { - let did = self.1.hir.body_owner_def_id(body_id); - println!( - "running test: {}", - self.1.hir.def_path(did).to_string(self.1) - ); - miri::eval_main(self.1, did, None, self.0); - self.2.session.abort_if_errors(); - } - } - } - fn visit_trait_item(&mut self, _trait_item: &'hir hir::TraitItem) {} - fn visit_impl_item(&mut self, _impl_item: &'hir hir::ImplItem) {} - } - state.hir_crate.unwrap().visit_all_item_likes( - &mut Visitor(limits, tcx, state), - ); - } else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() { - let entry_def_id = tcx.hir.local_def_id(entry_node_id); - let start_wrapper = tcx.lang_items().start_fn().and_then(|start_fn| { - if tcx.is_mir_available(start_fn) { - Some(start_fn) - } else { - None - } - }); - miri::eval_main(tcx, entry_def_id, start_wrapper, limits); - - state.session.abort_if_errors(); - } else { - println!("no main function found, assuming auxiliary build"); - } -} - -fn resource_limits_from_attributes(state: &CompileState) -> miri::ResourceLimits { - let mut limits = miri::ResourceLimits::default(); - let krate = state.hir_crate.as_ref().unwrap(); - let err_msg = "miri attributes need to be in the form `miri(key = value)`"; - let extract_int = |lit: &syntax::ast::Lit| -> u128 { - match lit.node { - syntax::ast::LitKind::Int(i, _) => i, - _ => { - state.session.span_fatal( - lit.span, - "expected an integer literal", - ) - } - } - }; - - for attr in krate.attrs.iter().filter(|a| { - a.name().map_or(false, |n| n == "miri") - }) - { - if let Some(items) = attr.meta_item_list() { - for item in items { - if let NestedMetaItemKind::MetaItem(ref inner) = item.node { - if let MetaItemKind::NameValue(ref value) = inner.node { - match &inner.name().as_str()[..] { - "memory_size" => limits.memory_size = extract_int(value) as u64, - "step_limit" => limits.step_limit = extract_int(value) as u64, - "stack_limit" => limits.stack_limit = extract_int(value) as usize, - _ => state.session.span_err(item.span, "unknown miri attribute"), - } - } else { - state.session.span_err(inner.span, err_msg); - } - } else { - state.session.span_err(item.span, err_msg); - } - } - } else { - state.session.span_err(attr.span, err_msg); - } - } - limits -} - -fn init_logger() { - let format = |record: &log::LogRecord| { - if record.level() == log::LogLevel::Trace { - // prepend spaces to indent the final string - let indentation = log_settings::settings().indentation; - format!( - "{lvl}:{module}:{indent: String { - if let Ok(sysroot) = std::env::var("MIRI_SYSROOT") { - return sysroot; - } - - // Taken from https://github.com/Manishearth/rust-clippy/pull/911. - let home = option_env!("RUSTUP_HOME").or(option_env!("MULTIRUST_HOME")); - let toolchain = option_env!("RUSTUP_TOOLCHAIN").or(option_env!("MULTIRUST_TOOLCHAIN")); - match (home, toolchain) { - (Some(home), Some(toolchain)) => format!("{}/toolchains/{}", home, toolchain), - _ => { - option_env!("RUST_SYSROOT") - .expect( - "need to specify RUST_SYSROOT env var or use rustup or multirust", - ) - .to_owned() - } - } -} - -fn main() { - init_logger(); - let mut args: Vec = std::env::args().collect(); - - let sysroot_flag = String::from("--sysroot"); - if !args.contains(&sysroot_flag) { - args.push(sysroot_flag); - args.push(find_sysroot()); - } - - // Make sure we always have all the MIR (e.g. for auxilary builds in unit tests). - args.push("-Zalways-encode-mir".to_owned()); - - rustc_driver::run_compiler(&args, &mut MiriCompilerCalls { - default: RustcDefaultCalls, - }, None, None); -} diff --git a/miri/fn_call.rs b/miri/fn_call.rs deleted file mode 100644 index 79ef3f97a9e9..000000000000 --- a/miri/fn_call.rs +++ /dev/null @@ -1,656 +0,0 @@ -use rustc::ty::{self, Ty}; -use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX}; -use rustc::mir; -use syntax::attr; -use syntax::abi::Abi; -use syntax::codemap::Span; - -use std::mem; - -use rustc_miri::interpret::*; - -use super::{TlsKey, EvalContext}; - -use tls::MemoryExt; - -use super::memory::MemoryKind; - -pub trait EvalContextExt<'tcx> { - fn call_c_abi( - &mut self, - def_id: DefId, - args: &[ValTy<'tcx>], - dest: Lvalue, - dest_ty: Ty<'tcx>, - dest_block: mir::BasicBlock, - ) -> EvalResult<'tcx>; - - fn resolve_path(&self, path: &[&str]) -> EvalResult<'tcx, ty::Instance<'tcx>>; - - fn call_missing_fn( - &mut self, - instance: ty::Instance<'tcx>, - destination: Option<(Lvalue, mir::BasicBlock)>, - args: &[ValTy<'tcx>], - sig: ty::FnSig<'tcx>, - path: String, - ) -> EvalResult<'tcx>; - - fn eval_fn_call( - &mut self, - instance: ty::Instance<'tcx>, - destination: Option<(Lvalue, mir::BasicBlock)>, - args: &[ValTy<'tcx>], - span: Span, - sig: ty::FnSig<'tcx>, - ) -> EvalResult<'tcx, bool>; -} - -impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator> { - fn eval_fn_call( - &mut self, - instance: ty::Instance<'tcx>, - destination: Option<(Lvalue, mir::BasicBlock)>, - args: &[ValTy<'tcx>], - span: Span, - sig: ty::FnSig<'tcx>, - ) -> EvalResult<'tcx, bool> { - trace!("eval_fn_call: {:#?}, {:#?}", instance, destination); - - let mir = match self.load_mir(instance.def) { - Ok(mir) => mir, - Err(EvalError { kind: EvalErrorKind::NoMirFor(path), .. }) => { - self.call_missing_fn( - instance, - destination, - args, - sig, - path, - )?; - return Ok(true); - } - Err(other) => return Err(other), - }; - - let (return_lvalue, return_to_block) = match destination { - Some((lvalue, block)) => (lvalue, StackPopCleanup::Goto(block)), - None => (Lvalue::undef(), StackPopCleanup::None), - }; - - self.push_stack_frame( - instance, - span, - mir, - return_lvalue, - return_to_block, - )?; - - Ok(false) - } - - fn call_c_abi( - &mut self, - def_id: DefId, - args: &[ValTy<'tcx>], - dest: Lvalue, - dest_ty: Ty<'tcx>, - dest_block: mir::BasicBlock, - ) -> EvalResult<'tcx> { - let attrs = self.tcx.get_attrs(def_id); - let link_name = match attr::first_attr_value_str_by_name(&attrs, "link_name") { - Some(name) => name.as_str(), - None => self.tcx.item_name(def_id), - }; - - match &link_name[..] { - "malloc" => { - let size = self.value_to_primval(args[0])?.to_u64()?; - if size == 0 { - self.write_null(dest, dest_ty)?; - } else { - let align = self.memory.pointer_size(); - let ptr = self.memory.allocate(size, align, MemoryKind::C.into())?; - self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?; - } - } - - "free" => { - let ptr = args[0].into_ptr(&mut self.memory)?; - if !ptr.is_null()? { - self.memory.deallocate( - ptr.to_ptr()?, - None, - MemoryKind::C.into(), - )?; - } - } - - "syscall" => { - // TODO: read `syscall` ids like `sysconf` ids and - // figure out some way to actually process some of them - // - // libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK) - // is called if a `HashMap` is created the regular way. - match self.value_to_primval(args[0])?.to_u64()? { - 318 | 511 => { - return err!(Unimplemented( - "miri does not support random number generators".to_owned(), - )) - } - id => { - return err!(Unimplemented( - format!("miri does not support syscall id {}", id), - )) - } - } - } - - "dlsym" => { - let _handle = args[0].into_ptr(&mut self.memory)?; - let symbol = args[1].into_ptr(&mut self.memory)?.to_ptr()?; - let symbol_name = self.memory.read_c_str(symbol)?; - let err = format!("bad c unicode symbol: {:?}", symbol_name); - let symbol_name = ::std::str::from_utf8(symbol_name).unwrap_or(&err); - return err!(Unimplemented(format!( - "miri does not support dynamically loading libraries (requested symbol: {})", - symbol_name - ))); - } - - "__rust_maybe_catch_panic" => { - // fn __rust_maybe_catch_panic(f: fn(*mut u8), data: *mut u8, data_ptr: *mut usize, vtable_ptr: *mut usize) -> u32 - // We abort on panic, so not much is going on here, but we still have to call the closure - let u8_ptr_ty = self.tcx.mk_mut_ptr(self.tcx.types.u8); - let f = args[0].into_ptr(&mut self.memory)?.to_ptr()?; - let data = args[1].into_ptr(&mut self.memory)?; - let f_instance = self.memory.get_fn(f)?; - self.write_null(dest, dest_ty)?; - - // Now we make a function call. TODO: Consider making this re-usable? EvalContext::step does sth. similar for the TLS dtors, - // and of course eval_main. - let mir = self.load_mir(f_instance.def)?; - self.push_stack_frame( - f_instance, - mir.span, - mir, - Lvalue::undef(), - StackPopCleanup::Goto(dest_block), - )?; - let mut args = self.frame().mir.args_iter(); - - let arg_local = args.next().ok_or( - EvalErrorKind::AbiViolation( - "Argument to __rust_maybe_catch_panic does not take enough arguments." - .to_owned(), - ), - )?; - let arg_dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?; - self.write_ptr(arg_dest, data, u8_ptr_ty)?; - - assert!(args.next().is_none(), "__rust_maybe_catch_panic argument has more arguments than expected"); - - // We ourselves return 0 - self.write_null(dest, dest_ty)?; - - // Don't fall through - return Ok(()); - } - - "__rust_start_panic" => { - return err!(Panic); - } - - "memcmp" => { - let left = args[0].into_ptr(&mut self.memory)?; - let right = args[1].into_ptr(&mut self.memory)?; - let n = self.value_to_primval(args[2])?.to_u64()?; - - let result = { - let left_bytes = self.memory.read_bytes(left, n)?; - let right_bytes = self.memory.read_bytes(right, n)?; - - use std::cmp::Ordering::*; - match left_bytes.cmp(right_bytes) { - Less => -1i8, - Equal => 0, - Greater => 1, - } - }; - - self.write_primval( - dest, - PrimVal::Bytes(result as u128), - dest_ty, - )?; - } - - "memrchr" => { - let ptr = args[0].into_ptr(&mut self.memory)?; - let val = self.value_to_primval(args[1])?.to_u64()? as u8; - let num = self.value_to_primval(args[2])?.to_u64()?; - if let Some(idx) = self.memory.read_bytes(ptr, num)?.iter().rev().position( - |&c| c == val, - ) - { - let new_ptr = ptr.offset(num - idx as u64 - 1, &self)?; - self.write_ptr(dest, new_ptr, dest_ty)?; - } else { - self.write_null(dest, dest_ty)?; - } - } - - "memchr" => { - let ptr = args[0].into_ptr(&mut self.memory)?; - let val = self.value_to_primval(args[1])?.to_u64()? as u8; - let num = self.value_to_primval(args[2])?.to_u64()?; - if let Some(idx) = self.memory.read_bytes(ptr, num)?.iter().position( - |&c| c == val, - ) - { - let new_ptr = ptr.offset(idx as u64, &self)?; - self.write_ptr(dest, new_ptr, dest_ty)?; - } else { - self.write_null(dest, dest_ty)?; - } - } - - "getenv" => { - let result = { - let name_ptr = args[0].into_ptr(&mut self.memory)?.to_ptr()?; - let name = self.memory.read_c_str(name_ptr)?; - match self.machine_data.env_vars.get(name) { - Some(&var) => PrimVal::Ptr(var), - None => PrimVal::Bytes(0), - } - }; - self.write_primval(dest, result, dest_ty)?; - } - - "unsetenv" => { - let mut success = None; - { - let name_ptr = args[0].into_ptr(&mut self.memory)?; - if !name_ptr.is_null()? { - let name = self.memory.read_c_str(name_ptr.to_ptr()?)?; - if !name.is_empty() && !name.contains(&b'=') { - success = Some(self.machine_data.env_vars.remove(name)); - } - } - } - if let Some(old) = success { - if let Some(var) = old { - self.memory.deallocate(var, None, MemoryKind::Env.into())?; - } - self.write_null(dest, dest_ty)?; - } else { - self.write_primval(dest, PrimVal::from_i128(-1), dest_ty)?; - } - } - - "setenv" => { - let mut new = None; - { - let name_ptr = args[0].into_ptr(&mut self.memory)?; - let value_ptr = args[1].into_ptr(&mut self.memory)?.to_ptr()?; - let value = self.memory.read_c_str(value_ptr)?; - if !name_ptr.is_null()? { - let name = self.memory.read_c_str(name_ptr.to_ptr()?)?; - if !name.is_empty() && !name.contains(&b'=') { - new = Some((name.to_owned(), value.to_owned())); - } - } - } - if let Some((name, value)) = new { - // +1 for the null terminator - let value_copy = self.memory.allocate( - (value.len() + 1) as u64, - 1, - MemoryKind::Env.into(), - )?; - self.memory.write_bytes(value_copy.into(), &value)?; - let trailing_zero_ptr = value_copy.offset(value.len() as u64, &self)?.into(); - self.memory.write_bytes(trailing_zero_ptr, &[0])?; - if let Some(var) = self.machine_data.env_vars.insert( - name.to_owned(), - value_copy, - ) - { - self.memory.deallocate(var, None, MemoryKind::Env.into())?; - } - self.write_null(dest, dest_ty)?; - } else { - self.write_primval(dest, PrimVal::from_i128(-1), dest_ty)?; - } - } - - "write" => { - let fd = self.value_to_primval(args[0])?.to_u64()?; - let buf = args[1].into_ptr(&mut self.memory)?; - let n = self.value_to_primval(args[2])?.to_u64()?; - trace!("Called write({:?}, {:?}, {:?})", fd, buf, n); - let result = if fd == 1 || fd == 2 { - // stdout/stderr - use std::io::{self, Write}; - - let buf_cont = self.memory.read_bytes(buf, n)?; - let res = if fd == 1 { - io::stdout().write(buf_cont) - } else { - io::stderr().write(buf_cont) - }; - match res { - Ok(n) => n as isize, - Err(_) => -1, - } - } else { - warn!("Ignored output to FD {}", fd); - n as isize // pretend it all went well - }; // now result is the value we return back to the program - self.write_primval( - dest, - PrimVal::Bytes(result as u128), - dest_ty, - )?; - } - - "strlen" => { - let ptr = args[0].into_ptr(&mut self.memory)?.to_ptr()?; - let n = self.memory.read_c_str(ptr)?.len(); - self.write_primval(dest, PrimVal::Bytes(n as u128), dest_ty)?; - } - - // Some things needed for sys::thread initialization to go through - "signal" | "sigaction" | "sigaltstack" => { - self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?; - } - - "sysconf" => { - let name = self.value_to_primval(args[0])?.to_u64()?; - trace!("sysconf() called with name {}", name); - // cache the sysconf integers via miri's global cache - let paths = &[ - (&["libc", "_SC_PAGESIZE"], PrimVal::Bytes(4096)), - (&["libc", "_SC_GETPW_R_SIZE_MAX"], PrimVal::from_i128(-1)), - ]; - let mut result = None; - for &(path, path_value) in paths { - if let Ok(instance) = self.resolve_path(path) { - let cid = GlobalId { - instance, - promoted: None, - }; - // compute global if not cached - let val = match self.globals.get(&cid).cloned() { - Some(ptr) => self.value_to_primval(ValTy { value: Value::ByRef(ptr), ty: args[0].ty })?.to_u64()?, - None => eval_body_as_primval(self.tcx, instance)?.0.to_u64()?, - }; - if val == name { - result = Some(path_value); - break; - } - } - } - if let Some(result) = result { - self.write_primval(dest, result, dest_ty)?; - } else { - return err!(Unimplemented( - format!("Unimplemented sysconf name: {}", name), - )); - } - } - - // Hook pthread calls that go to the thread-local storage memory subsystem - "pthread_key_create" => { - let key_ptr = args[0].into_ptr(&mut self.memory)?; - - // Extract the function type out of the signature (that seems easier than constructing it ourselves...) - let dtor = match args[1].into_ptr(&mut self.memory)?.into_inner_primval() { - PrimVal::Ptr(dtor_ptr) => Some(self.memory.get_fn(dtor_ptr)?), - PrimVal::Bytes(0) => None, - PrimVal::Bytes(_) => return err!(ReadBytesAsPointer), - PrimVal::Undef => return err!(ReadUndefBytes), - }; - - // Figure out how large a pthread TLS key actually is. This is libc::pthread_key_t. - let key_type = args[0].ty.builtin_deref(true, ty::LvaluePreference::NoPreference) - .ok_or(EvalErrorKind::AbiViolation("Wrong signature used for pthread_key_create: First argument must be a raw pointer.".to_owned()))?.ty; - let key_size = { - let layout = self.type_layout(key_type)?; - layout.size(&self.tcx.data_layout) - }; - - // Create key and write it into the memory where key_ptr wants it - let key = self.memory.create_tls_key(dtor) as u128; - if key_size.bits() < 128 && key >= (1u128 << key_size.bits() as u128) { - return err!(OutOfTls); - } - self.memory.write_primval( - key_ptr.to_ptr()?, - PrimVal::Bytes(key), - key_size.bytes(), - false, - )?; - - // Return success (0) - self.write_null(dest, dest_ty)?; - } - "pthread_key_delete" => { - // The conversion into TlsKey here is a little fishy, but should work as long as usize >= libc::pthread_key_t - let key = self.value_to_primval(args[0])?.to_u64()? as TlsKey; - self.memory.delete_tls_key(key)?; - // Return success (0) - self.write_null(dest, dest_ty)?; - } - "pthread_getspecific" => { - // The conversion into TlsKey here is a little fishy, but should work as long as usize >= libc::pthread_key_t - let key = self.value_to_primval(args[0])?.to_u64()? as TlsKey; - let ptr = self.memory.load_tls(key)?; - self.write_ptr(dest, ptr, dest_ty)?; - } - "pthread_setspecific" => { - // The conversion into TlsKey here is a little fishy, but should work as long as usize >= libc::pthread_key_t - let key = self.value_to_primval(args[0])?.to_u64()? as TlsKey; - let new_ptr = args[1].into_ptr(&mut self.memory)?; - self.memory.store_tls(key, new_ptr)?; - - // Return success (0) - self.write_null(dest, dest_ty)?; - } - - // Stub out all the other pthread calls to just return 0 - link_name if link_name.starts_with("pthread_") => { - info!("ignoring C ABI call: {}", link_name); - self.write_null(dest, dest_ty)?; - } - - _ => { - return err!(Unimplemented( - format!("can't call C ABI function: {}", link_name), - )); - } - } - - // Since we pushed no stack frame, the main loop will act - // as if the call just completed and it's returning to the - // current frame. - self.dump_local(dest); - self.goto_block(dest_block); - Ok(()) - } - - /// Get an instance for a path. - fn resolve_path(&self, path: &[&str]) -> EvalResult<'tcx, ty::Instance<'tcx>> { - self.tcx - .crates() - .iter() - .find(|&&krate| self.tcx.original_crate_name(krate) == path[0]) - .and_then(|krate| { - let krate = DefId { - krate: *krate, - index: CRATE_DEF_INDEX, - }; - let mut items = self.tcx.item_children(krate); - let mut path_it = path.iter().skip(1).peekable(); - - while let Some(segment) = path_it.next() { - for item in mem::replace(&mut items, Default::default()).iter() { - if item.ident.name == *segment { - if path_it.peek().is_none() { - return Some(ty::Instance::mono(self.tcx, item.def.def_id())); - } - - items = self.tcx.item_children(item.def.def_id()); - break; - } - } - } - None - }) - .ok_or_else(|| { - let path = path.iter().map(|&s| s.to_owned()).collect(); - EvalErrorKind::PathNotFound(path).into() - }) - } - - fn call_missing_fn( - &mut self, - instance: ty::Instance<'tcx>, - destination: Option<(Lvalue, mir::BasicBlock)>, - args: &[ValTy<'tcx>], - sig: ty::FnSig<'tcx>, - path: String, - ) -> 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!(Panic), - _ => {} - } - - let dest_ty = sig.output(); - let (dest, dest_block) = destination.ok_or_else( - || EvalErrorKind::NoMirFor(path.clone()), - )?; - - if sig.abi == Abi::C { - // An external C function - // TODO: That functions actually has a similar preamble to what follows here. May make sense to - // unify these two mechanisms for "hooking into missing functions". - self.call_c_abi( - instance.def_id(), - args, - dest, - dest_ty, - dest_block, - )?; - return Ok(()); - } - - match &path[..] { - // Allocators are magic. They have no MIR, even when the rest of libstd does. - "alloc::heap::::__rust_alloc" => { - let size = self.value_to_primval(args[0])?.to_u64()?; - let align = self.value_to_primval(args[1])?.to_u64()?; - if size == 0 { - return err!(HeapAllocZeroBytes); - } - if !align.is_power_of_two() { - return err!(HeapAllocNonPowerOfTwoAlignment(align)); - } - let ptr = self.memory.allocate(size, align, MemoryKind::Rust.into())?; - self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?; - } - "alloc::heap::::__rust_alloc_zeroed" => { - let size = self.value_to_primval(args[0])?.to_u64()?; - let align = self.value_to_primval(args[1])?.to_u64()?; - if size == 0 { - return err!(HeapAllocZeroBytes); - } - if !align.is_power_of_two() { - return err!(HeapAllocNonPowerOfTwoAlignment(align)); - } - let ptr = self.memory.allocate(size, align, MemoryKind::Rust.into())?; - self.memory.write_repeat(ptr.into(), 0, size)?; - self.write_primval(dest, PrimVal::Ptr(ptr), dest_ty)?; - } - "alloc::heap::::__rust_dealloc" => { - let ptr = args[0].into_ptr(&mut self.memory)?.to_ptr()?; - let old_size = self.value_to_primval(args[1])?.to_u64()?; - let align = self.value_to_primval(args[2])?.to_u64()?; - if old_size == 0 { - return err!(HeapAllocZeroBytes); - } - if !align.is_power_of_two() { - return err!(HeapAllocNonPowerOfTwoAlignment(align)); - } - self.memory.deallocate( - ptr, - Some((old_size, align)), - MemoryKind::Rust.into(), - )?; - } - "alloc::heap::::__rust_realloc" => { - let ptr = args[0].into_ptr(&mut self.memory)?.to_ptr()?; - let old_size = self.value_to_primval(args[1])?.to_u64()?; - let old_align = self.value_to_primval(args[2])?.to_u64()?; - let new_size = self.value_to_primval(args[3])?.to_u64()?; - let new_align = self.value_to_primval(args[4])?.to_u64()?; - if old_size == 0 || new_size == 0 { - return err!(HeapAllocZeroBytes); - } - if !old_align.is_power_of_two() { - return err!(HeapAllocNonPowerOfTwoAlignment(old_align)); - } - if !new_align.is_power_of_two() { - return err!(HeapAllocNonPowerOfTwoAlignment(new_align)); - } - let new_ptr = self.memory.reallocate( - ptr, - old_size, - old_align, - new_size, - new_align, - MemoryKind::Rust.into(), - )?; - self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?; - } - - // 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" => { - warn!( - "Ignoring output. To run programs that print, 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 - let bool = self.tcx.types.bool; - self.write_primval(dest, PrimVal::from_bool(false), bool)?; - } - "std::sys::imp::c::::AddVectoredExceptionHandler" | - "std::sys::imp::c::::SetThreadStackGuarantee" => { - let usize = self.tcx.types.usize; - // any non zero value works for the stdlib. This is just used for stackoverflows anyway - self.write_primval(dest, PrimVal::Bytes(1), usize)?; - }, - _ => return err!(NoMirFor(path)), - } - - // Since we pushed no stack frame, the main loop will act - // as if the call just completed and it's returning to the - // current frame. - self.dump_local(dest); - self.goto_block(dest_block); - return Ok(()); - } -} diff --git a/miri/helpers.rs b/miri/helpers.rs deleted file mode 100644 index 809e5ebfacdb..000000000000 --- a/miri/helpers.rs +++ /dev/null @@ -1,73 +0,0 @@ -use rustc_miri::interpret::{Pointer, EvalResult, PrimVal, EvalContext}; - -use rustc::ty::Ty; - -pub trait EvalContextExt<'tcx> { - fn wrapping_pointer_offset( - &self, - ptr: Pointer, - pointee_ty: Ty<'tcx>, - offset: i64, - ) -> EvalResult<'tcx, Pointer>; - - fn pointer_offset( - &self, - ptr: Pointer, - pointee_ty: Ty<'tcx>, - offset: i64, - ) -> EvalResult<'tcx, Pointer>; -} - -impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator> { - fn wrapping_pointer_offset( - &self, - ptr: Pointer, - pointee_ty: Ty<'tcx>, - offset: i64, - ) -> EvalResult<'tcx, Pointer> { - // FIXME: assuming here that type size is < i64::max_value() - let pointee_size = self.type_size(pointee_ty)?.expect( - "cannot offset a pointer to an unsized type", - ) as i64; - let offset = offset.overflowing_mul(pointee_size).0; - ptr.wrapping_signed_offset(offset, self) - } - - fn pointer_offset( - &self, - ptr: Pointer, - pointee_ty: Ty<'tcx>, - offset: i64, - ) -> EvalResult<'tcx, Pointer> { - // This function raises an error if the offset moves the pointer outside of its allocation. We consider - // ZSTs their own huge allocation that doesn't overlap with anything (and nothing moves in there because the size is 0). - // We also consider the NULL pointer its own separate allocation, and all the remaining integers pointers their own - // allocation. - - if ptr.is_null()? { - // NULL pointers must only be offset by 0 - return if offset == 0 { - Ok(ptr) - } else { - err!(InvalidNullPointerUsage) - }; - } - // FIXME: assuming here that type size is < i64::max_value() - let pointee_size = self.type_size(pointee_ty)?.expect( - "cannot offset a pointer to an unsized type", - ) as i64; - return if let Some(offset) = offset.checked_mul(pointee_size) { - let ptr = ptr.signed_offset(offset, self)?; - // Do not do bounds-checking for integers; they can never alias a normal pointer anyway. - if let PrimVal::Ptr(ptr) = ptr.into_inner_primval() { - self.memory.check_bounds(ptr, false)?; - } else if ptr.is_null()? { - // We moved *to* a NULL pointer. That seems wrong, LLVM considers the NULL pointer its own small allocation. Reject this, for now. - return err!(InvalidNullPointerUsage); - } - Ok(ptr) - } else { - err!(OverflowingMath) - }; - } -} diff --git a/miri/intrinsic.rs b/miri/intrinsic.rs deleted file mode 100644 index bcff3b4aa991..000000000000 --- a/miri/intrinsic.rs +++ /dev/null @@ -1,685 +0,0 @@ -use rustc::mir; -use rustc::traits::Reveal; -use rustc::ty::layout::Layout; -use rustc::ty::{self, Ty}; - -use rustc_miri::interpret::{EvalResult, Lvalue, LvalueExtra, PrimVal, PrimValKind, Value, Pointer, - HasMemory, AccessKind, EvalContext, PtrAndAlign, ValTy}; - -use helpers::EvalContextExt as HelperEvalContextExt; - -pub trait EvalContextExt<'tcx> { - fn call_intrinsic( - &mut self, - instance: ty::Instance<'tcx>, - args: &[ValTy<'tcx>], - dest: Lvalue, - dest_ty: Ty<'tcx>, - dest_layout: &'tcx Layout, - target: mir::BasicBlock, - ) -> EvalResult<'tcx>; -} - -impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator> { - fn call_intrinsic( - &mut self, - instance: ty::Instance<'tcx>, - args: &[ValTy<'tcx>], - dest: Lvalue, - dest_ty: Ty<'tcx>, - dest_layout: &'tcx Layout, - target: mir::BasicBlock, - ) -> EvalResult<'tcx> { - let substs = instance.substs; - - let intrinsic_name = &self.tcx.item_name(instance.def_id())[..]; - match intrinsic_name { - "align_offset" => { - // FIXME: return a real value in case the target allocation has an - // alignment bigger than the one requested - self.write_primval(dest, PrimVal::Bytes(u128::max_value()), dest_ty)?; - }, - - "add_with_overflow" => { - self.intrinsic_with_overflow( - mir::BinOp::Add, - args[0], - args[1], - dest, - dest_ty, - )? - } - - "sub_with_overflow" => { - self.intrinsic_with_overflow( - mir::BinOp::Sub, - args[0], - args[1], - dest, - dest_ty, - )? - } - - "mul_with_overflow" => { - self.intrinsic_with_overflow( - mir::BinOp::Mul, - args[0], - args[1], - dest, - dest_ty, - )? - } - - "arith_offset" => { - let offset = self.value_to_primval(args[1])?.to_i128()? as i64; - let ptr = args[0].into_ptr(&self.memory)?; - let result_ptr = self.wrapping_pointer_offset(ptr, substs.type_at(0), offset)?; - self.write_ptr(dest, result_ptr, dest_ty)?; - } - - "assume" => { - let cond = self.value_to_primval(args[0])?.to_bool()?; - if !cond { - return err!(AssumptionNotHeld); - } - } - - "atomic_load" | - "atomic_load_relaxed" | - "atomic_load_acq" | - "volatile_load" => { - let ptr = args[0].into_ptr(&self.memory)?; - let valty = ValTy { - value: Value::by_ref(ptr), - ty: substs.type_at(0), - }; - self.write_value(valty, dest)?; - } - - "atomic_store" | - "atomic_store_relaxed" | - "atomic_store_rel" | - "volatile_store" => { - let ty = substs.type_at(0); - let dest = args[0].into_ptr(&self.memory)?; - self.write_value_to_ptr(args[1].value, dest, ty)?; - } - - "atomic_fence_acq" => { - // we are inherently singlethreaded and singlecored, this is a nop - } - - _ if intrinsic_name.starts_with("atomic_xchg") => { - let ty = substs.type_at(0); - let ptr = args[0].into_ptr(&self.memory)?; - let change = self.value_to_primval(args[1])?; - let old = self.read_value(ptr, ty)?; - let old = match old { - Value::ByVal(val) => val, - Value::ByRef { .. } => bug!("just read the value, can't be byref"), - Value::ByValPair(..) => bug!("atomic_xchg doesn't work with nonprimitives"), - }; - self.write_primval(dest, old, ty)?; - self.write_primval( - Lvalue::from_primval_ptr(ptr), - change, - ty, - )?; - } - - _ if intrinsic_name.starts_with("atomic_cxchg") => { - let ty = substs.type_at(0); - let ptr = args[0].into_ptr(&self.memory)?; - let expect_old = self.value_to_primval(args[1])?; - let change = self.value_to_primval(args[2])?; - let old = self.read_value(ptr, ty)?; - let old = match old { - Value::ByVal(val) => val, - Value::ByRef { .. } => bug!("just read the value, can't be byref"), - Value::ByValPair(..) => bug!("atomic_cxchg doesn't work with nonprimitives"), - }; - let (val, _) = self.binary_op(mir::BinOp::Eq, old, ty, expect_old, ty)?; - let dest = self.force_allocation(dest)?.to_ptr()?; - self.write_pair_to_ptr(old, val, dest, dest_ty)?; - self.write_primval( - Lvalue::from_primval_ptr(ptr), - change, - ty, - )?; - } - - "atomic_or" | - "atomic_or_acq" | - "atomic_or_rel" | - "atomic_or_acqrel" | - "atomic_or_relaxed" | - "atomic_xor" | - "atomic_xor_acq" | - "atomic_xor_rel" | - "atomic_xor_acqrel" | - "atomic_xor_relaxed" | - "atomic_and" | - "atomic_and_acq" | - "atomic_and_rel" | - "atomic_and_acqrel" | - "atomic_and_relaxed" | - "atomic_xadd" | - "atomic_xadd_acq" | - "atomic_xadd_rel" | - "atomic_xadd_acqrel" | - "atomic_xadd_relaxed" | - "atomic_xsub" | - "atomic_xsub_acq" | - "atomic_xsub_rel" | - "atomic_xsub_acqrel" | - "atomic_xsub_relaxed" => { - let ty = substs.type_at(0); - let ptr = args[0].into_ptr(&self.memory)?; - let change = self.value_to_primval(args[1])?; - let old = self.read_value(ptr, ty)?; - let old = match old { - Value::ByVal(val) => val, - Value::ByRef { .. } => bug!("just read the value, can't be byref"), - Value::ByValPair(..) => { - bug!("atomic_xadd_relaxed doesn't work with nonprimitives") - } - }; - self.write_primval(dest, old, ty)?; - let op = match intrinsic_name.split('_').nth(1).unwrap() { - "or" => mir::BinOp::BitOr, - "xor" => mir::BinOp::BitXor, - "and" => mir::BinOp::BitAnd, - "xadd" => mir::BinOp::Add, - "xsub" => mir::BinOp::Sub, - _ => bug!(), - }; - // FIXME: what do atomics do on overflow? - let (val, _) = self.binary_op(op, old, ty, change, ty)?; - self.write_primval(Lvalue::from_primval_ptr(ptr), val, ty)?; - } - - "breakpoint" => unimplemented!(), // halt miri - - "copy" | - "copy_nonoverlapping" => { - let elem_ty = substs.type_at(0); - let elem_size = self.type_size(elem_ty)?.expect("cannot copy unsized value"); - let count = self.value_to_primval(args[2])?.to_u64()?; - if count * elem_size != 0 { - // TODO: We do not even validate alignment for the 0-bytes case. libstd relies on this in vec::IntoIter::next. - // Also see the write_bytes intrinsic. - let elem_align = self.type_align(elem_ty)?; - let src = args[0].into_ptr(&self.memory)?; - let dest = args[1].into_ptr(&self.memory)?; - self.memory.copy( - src, - dest, - count * elem_size, - elem_align, - intrinsic_name.ends_with("_nonoverlapping"), - )?; - } - } - - "ctpop" | "cttz" | "cttz_nonzero" | "ctlz" | "ctlz_nonzero" | "bswap" => { - let ty = substs.type_at(0); - let num = self.value_to_primval(args[0])?.to_bytes()?; - let kind = self.ty_to_primval_kind(ty)?; - let num = if intrinsic_name.ends_with("_nonzero") { - if num == 0 { - return err!(Intrinsic(format!("{} called on 0", intrinsic_name))); - } - numeric_intrinsic(intrinsic_name.trim_right_matches("_nonzero"), num, kind)? - } else { - numeric_intrinsic(intrinsic_name, num, kind)? - }; - self.write_primval(dest, num, ty)?; - } - - "discriminant_value" => { - let ty = substs.type_at(0); - let adt_ptr = args[0].into_ptr(&self.memory)?.to_ptr()?; - let discr_val = self.read_discriminant_value(adt_ptr, ty)?; - self.write_primval(dest, PrimVal::Bytes(discr_val), dest_ty)?; - } - - "sinf32" | "fabsf32" | "cosf32" | "sqrtf32" | "expf32" | "exp2f32" | "logf32" | - "log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" => { - let f = self.value_to_primval(args[0])?.to_f32()?; - let f = match intrinsic_name { - "sinf32" => f.sin(), - "fabsf32" => f.abs(), - "cosf32" => f.cos(), - "sqrtf32" => f.sqrt(), - "expf32" => f.exp(), - "exp2f32" => f.exp2(), - "logf32" => f.ln(), - "log10f32" => f.log10(), - "log2f32" => f.log2(), - "floorf32" => f.floor(), - "ceilf32" => f.ceil(), - "truncf32" => f.trunc(), - _ => bug!(), - }; - self.write_primval(dest, PrimVal::from_f32(f), dest_ty)?; - } - - "sinf64" | "fabsf64" | "cosf64" | "sqrtf64" | "expf64" | "exp2f64" | "logf64" | - "log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" => { - let f = self.value_to_primval(args[0])?.to_f64()?; - let f = match intrinsic_name { - "sinf64" => f.sin(), - "fabsf64" => f.abs(), - "cosf64" => f.cos(), - "sqrtf64" => f.sqrt(), - "expf64" => f.exp(), - "exp2f64" => f.exp2(), - "logf64" => f.ln(), - "log10f64" => f.log10(), - "log2f64" => f.log2(), - "floorf64" => f.floor(), - "ceilf64" => f.ceil(), - "truncf64" => f.trunc(), - _ => bug!(), - }; - self.write_primval(dest, PrimVal::from_f64(f), dest_ty)?; - } - - "fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => { - let ty = substs.type_at(0); - let a = self.value_to_primval(args[0])?; - let b = self.value_to_primval(args[1])?; - let op = match intrinsic_name { - "fadd_fast" => mir::BinOp::Add, - "fsub_fast" => mir::BinOp::Sub, - "fmul_fast" => mir::BinOp::Mul, - "fdiv_fast" => mir::BinOp::Div, - "frem_fast" => mir::BinOp::Rem, - _ => bug!(), - }; - let result = self.binary_op(op, a, ty, b, ty)?; - self.write_primval(dest, result.0, dest_ty)?; - } - - "likely" | "unlikely" | "forget" => {} - - "init" => { - let size = self.type_size(dest_ty)?.expect("cannot zero unsized value"); - let init = |this: &mut Self, val: Value| { - let zero_val = match val { - Value::ByRef(PtrAndAlign { ptr, .. }) => { - // These writes have no alignment restriction anyway. - this.memory.write_repeat(ptr, 0, size)?; - val - } - // TODO(solson): Revisit this, it's fishy to check for Undef here. - Value::ByVal(PrimVal::Undef) => { - match this.ty_to_primval_kind(dest_ty) { - Ok(_) => Value::ByVal(PrimVal::Bytes(0)), - Err(_) => { - let ptr = this.alloc_ptr_with_substs(dest_ty, substs)?; - let ptr = Pointer::from(PrimVal::Ptr(ptr)); - this.memory.write_repeat(ptr, 0, size)?; - Value::by_ref(ptr) - } - } - } - Value::ByVal(_) => Value::ByVal(PrimVal::Bytes(0)), - Value::ByValPair(..) => { - Value::ByValPair(PrimVal::Bytes(0), PrimVal::Bytes(0)) - } - }; - Ok(zero_val) - }; - match dest { - Lvalue::Local { frame, local } => self.modify_local(frame, local, init)?, - Lvalue::Ptr { - ptr: PtrAndAlign { ptr, aligned: true }, - extra: LvalueExtra::None, - } => self.memory.write_repeat(ptr, 0, size)?, - Lvalue::Ptr { .. } => { - bug!("init intrinsic tried to write to fat or unaligned ptr target") - } - } - } - - "min_align_of" => { - let elem_ty = substs.type_at(0); - let elem_align = self.type_align(elem_ty)?; - let align_val = PrimVal::from_u128(elem_align as u128); - self.write_primval(dest, align_val, dest_ty)?; - } - - "pref_align_of" => { - let ty = substs.type_at(0); - let layout = self.type_layout(ty)?; - let align = layout.align(&self.tcx.data_layout).pref(); - let align_val = PrimVal::from_u128(align as u128); - self.write_primval(dest, align_val, dest_ty)?; - } - - "move_val_init" => { - let ty = substs.type_at(0); - let ptr = args[0].into_ptr(&self.memory)?; - self.write_value_to_ptr(args[1].value, ptr, ty)?; - } - - "needs_drop" => { - let ty = substs.type_at(0); - let env = ty::ParamEnv::empty(Reveal::All); - let needs_drop = ty.needs_drop(self.tcx, env); - self.write_primval( - dest, - PrimVal::from_bool(needs_drop), - dest_ty, - )?; - } - - "offset" => { - let offset = self.value_to_primval(args[1])?.to_i128()? as i64; - let ptr = args[0].into_ptr(&self.memory)?; - let result_ptr = self.pointer_offset(ptr, substs.type_at(0), offset)?; - self.write_ptr(dest, result_ptr, dest_ty)?; - } - - "overflowing_sub" => { - self.intrinsic_overflowing( - mir::BinOp::Sub, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "overflowing_mul" => { - self.intrinsic_overflowing( - mir::BinOp::Mul, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "overflowing_add" => { - self.intrinsic_overflowing( - mir::BinOp::Add, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "powf32" => { - let f = self.value_to_primval(args[0])?.to_f32()?; - let f2 = self.value_to_primval(args[1])?.to_f32()?; - self.write_primval( - dest, - PrimVal::from_f32(f.powf(f2)), - dest_ty, - )?; - } - - "powf64" => { - let f = self.value_to_primval(args[0])?.to_f64()?; - let f2 = self.value_to_primval(args[1])?.to_f64()?; - self.write_primval( - dest, - PrimVal::from_f64(f.powf(f2)), - dest_ty, - )?; - } - - "fmaf32" => { - let a = self.value_to_primval(args[0])?.to_f32()?; - let b = self.value_to_primval(args[1])?.to_f32()?; - let c = self.value_to_primval(args[2])?.to_f32()?; - self.write_primval( - dest, - PrimVal::from_f32(a * b + c), - dest_ty, - )?; - } - - "fmaf64" => { - let a = self.value_to_primval(args[0])?.to_f64()?; - let b = self.value_to_primval(args[1])?.to_f64()?; - let c = self.value_to_primval(args[2])?.to_f64()?; - self.write_primval( - dest, - PrimVal::from_f64(a * b + c), - dest_ty, - )?; - } - - "powif32" => { - let f = self.value_to_primval(args[0])?.to_f32()?; - let i = self.value_to_primval(args[1])?.to_i128()?; - self.write_primval( - dest, - PrimVal::from_f32(f.powi(i as i32)), - dest_ty, - )?; - } - - "powif64" => { - let f = self.value_to_primval(args[0])?.to_f64()?; - let i = self.value_to_primval(args[1])?.to_i128()?; - self.write_primval( - dest, - PrimVal::from_f64(f.powi(i as i32)), - dest_ty, - )?; - } - - "size_of" => { - let ty = substs.type_at(0); - let size = self.type_size(ty)?.expect( - "size_of intrinsic called on unsized value", - ) as u128; - self.write_primval(dest, PrimVal::from_u128(size), dest_ty)?; - } - - "size_of_val" => { - let ty = substs.type_at(0); - let (size, _) = self.size_and_align_of_dst(ty, args[0].value)?; - self.write_primval( - dest, - PrimVal::from_u128(size as u128), - dest_ty, - )?; - } - - "min_align_of_val" | - "align_of_val" => { - let ty = substs.type_at(0); - let (_, align) = self.size_and_align_of_dst(ty, args[0].value)?; - self.write_primval( - dest, - PrimVal::from_u128(align as u128), - dest_ty, - )?; - } - - "type_name" => { - let ty = substs.type_at(0); - let ty_name = ty.to_string(); - let value = self.str_to_value(&ty_name)?; - self.write_value(ValTy { value, ty: dest_ty }, dest)?; - } - "type_id" => { - let ty = substs.type_at(0); - let n = self.tcx.type_id_hash(ty); - self.write_primval(dest, PrimVal::Bytes(n as u128), dest_ty)?; - } - - "transmute" => { - let src_ty = substs.type_at(0); - let ptr = self.force_allocation(dest)?.to_ptr()?; - self.write_maybe_aligned_mut( - /*aligned*/ - false, - |ectx| { - ectx.write_value_to_ptr(args[0].value, ptr.into(), src_ty) - }, - )?; - } - - "unchecked_shl" => { - let bits = self.type_size(dest_ty)?.expect( - "intrinsic can't be called on unsized type", - ) as u128 * 8; - let rhs = self.value_to_primval(args[1])? - .to_bytes()?; - if rhs >= bits { - return err!(Intrinsic( - format!("Overflowing shift by {} in unchecked_shl", rhs), - )); - } - self.intrinsic_overflowing( - mir::BinOp::Shl, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "unchecked_shr" => { - let bits = self.type_size(dest_ty)?.expect( - "intrinsic can't be called on unsized type", - ) as u128 * 8; - let rhs = self.value_to_primval(args[1])? - .to_bytes()?; - if rhs >= bits { - return err!(Intrinsic( - format!("Overflowing shift by {} in unchecked_shr", rhs), - )); - } - self.intrinsic_overflowing( - mir::BinOp::Shr, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "unchecked_div" => { - let rhs = self.value_to_primval(args[1])? - .to_bytes()?; - if rhs == 0 { - return err!(Intrinsic(format!("Division by 0 in unchecked_div"))); - } - self.intrinsic_overflowing( - mir::BinOp::Div, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "unchecked_rem" => { - let rhs = self.value_to_primval(args[1])? - .to_bytes()?; - if rhs == 0 { - return err!(Intrinsic(format!("Division by 0 in unchecked_rem"))); - } - self.intrinsic_overflowing( - mir::BinOp::Rem, - args[0], - args[1], - dest, - dest_ty, - )?; - } - - "uninit" => { - let size = dest_layout.size(&self.tcx.data_layout).bytes(); - let uninit = |this: &mut Self, val: Value| match val { - Value::ByRef(PtrAndAlign { ptr, .. }) => { - this.memory.mark_definedness(ptr, size, false)?; - Ok(val) - } - _ => Ok(Value::ByVal(PrimVal::Undef)), - }; - match dest { - Lvalue::Local { frame, local } => self.modify_local(frame, local, uninit)?, - Lvalue::Ptr { - ptr: PtrAndAlign { ptr, aligned: true }, - extra: LvalueExtra::None, - } => self.memory.mark_definedness(ptr, size, false)?, - Lvalue::Ptr { .. } => { - bug!("uninit intrinsic tried to write to fat or unaligned ptr target") - } - } - } - - "write_bytes" => { - let ty = substs.type_at(0); - let ty_align = self.type_align(ty)?; - let val_byte = self.value_to_primval(args[1])?.to_u128()? as u8; - let size = self.type_size(ty)?.expect( - "write_bytes() type must be sized", - ); - let ptr = args[0].into_ptr(&self.memory)?; - let count = self.value_to_primval(args[2])?.to_u64()?; - if count > 0 { - // HashMap relies on write_bytes on a NULL ptr with count == 0 to work - // TODO: Should we, at least, validate the alignment? (Also see the copy intrinsic) - self.memory.check_align(ptr, ty_align, Some(AccessKind::Write))?; - self.memory.write_repeat(ptr, val_byte, size * count)?; - } - } - - name => return err!(Unimplemented(format!("unimplemented intrinsic: {}", name))), - } - - self.goto_block(target); - - // Since we pushed no stack frame, the main loop will act - // as if the call just completed and it's returning to the - // current frame. - Ok(()) - } -} - -fn numeric_intrinsic<'tcx>( - name: &str, - bytes: u128, - kind: PrimValKind, -) -> EvalResult<'tcx, PrimVal> { - macro_rules! integer_intrinsic { - ($method:ident) => ({ - use rustc_miri::interpret::PrimValKind::*; - let result_bytes = match kind { - I8 => (bytes as i8).$method() as u128, - U8 => (bytes as u8).$method() as u128, - I16 => (bytes as i16).$method() as u128, - U16 => (bytes as u16).$method() as u128, - I32 => (bytes as i32).$method() as u128, - U32 => (bytes as u32).$method() as u128, - I64 => (bytes as i64).$method() as u128, - U64 => (bytes as u64).$method() as u128, - I128 => (bytes as i128).$method() as u128, - U128 => bytes.$method() as u128, - _ => bug!("invalid `{}` argument: {:?}", name, bytes), - }; - - PrimVal::Bytes(result_bytes) - }); - } - - let result_val = match name { - "bswap" => integer_intrinsic!(swap_bytes), - "ctlz" => integer_intrinsic!(leading_zeros), - "ctpop" => integer_intrinsic!(count_ones), - "cttz" => integer_intrinsic!(trailing_zeros), - _ => bug!("not a numeric intrinsic: {}", name), - }; - - Ok(result_val) -} diff --git a/miri/lib.rs b/miri/lib.rs deleted file mode 100644 index f6ecd6e0b00b..000000000000 --- a/miri/lib.rs +++ /dev/null @@ -1,311 +0,0 @@ -#![feature( - i128_type, - rustc_private, -)] - -// From rustc. -#[macro_use] -extern crate log; -#[macro_use] -extern crate rustc; -extern crate syntax; - -use rustc::ty::{self, TyCtxt}; -use rustc::ty::layout::Layout; -use rustc::hir::def_id::DefId; -use rustc::mir; - -use syntax::ast::Mutability; -use syntax::codemap::Span; - -use std::collections::{HashMap, BTreeMap}; - -#[macro_use] -extern crate rustc_miri; -pub use rustc_miri::interpret::*; - -mod fn_call; -mod operator; -mod intrinsic; -mod helpers; -mod memory; -mod tls; - -use fn_call::EvalContextExt as MissingFnsEvalContextExt; -use operator::EvalContextExt as OperatorEvalContextExt; -use intrinsic::EvalContextExt as IntrinsicEvalContextExt; -use tls::EvalContextExt as TlsEvalContextExt; - -pub fn eval_main<'a, 'tcx: 'a>( - tcx: TyCtxt<'a, 'tcx, 'tcx>, - main_id: DefId, - start_wrapper: Option, - limits: ResourceLimits, -) { - fn run_main<'a, 'tcx: 'a>( - ecx: &mut rustc_miri::interpret::EvalContext<'a, 'tcx, Evaluator>, - main_id: DefId, - start_wrapper: Option, - ) -> EvalResult<'tcx> { - let main_instance = ty::Instance::mono(ecx.tcx, main_id); - let main_mir = ecx.load_mir(main_instance.def)?; - let mut cleanup_ptr = None; // Pointer to be deallocated when we are done - - if !main_mir.return_ty.is_nil() || main_mir.arg_count != 0 { - return err!(Unimplemented( - "miri does not support main functions without `fn()` type signatures" - .to_owned(), - )); - } - - if let Some(start_id) = start_wrapper { - let start_instance = ty::Instance::mono(ecx.tcx, start_id); - 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 - let size = ecx.tcx.data_layout.pointer_size.bytes(); - let align = ecx.tcx.data_layout.pointer_align.abi(); - let ret_ptr = ecx.memory_mut().allocate(size, align, MemoryKind::Stack)?; - cleanup_ptr = Some(ret_ptr); - - // Push our stack frame - ecx.push_stack_frame( - start_instance, - start_mir.span, - start_mir, - Lvalue::from_ptr(ret_ptr), - StackPopCleanup::None, - )?; - - let mut args = ecx.frame().mir.args_iter(); - - // First argument: pointer to main() - let main_ptr = ecx.memory_mut().create_fn_alloc(main_instance); - let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; - let main_ty = main_instance.def.def_ty(ecx.tcx); - let main_ptr_ty = ecx.tcx.mk_fn_ptr(main_ty.fn_sig(ecx.tcx)); - ecx.write_value( - ValTy { - value: Value::ByVal(PrimVal::Ptr(main_ptr)), - ty: main_ptr_ty, - }, - dest, - )?; - - // Second argument (argc): 1 - let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; - let ty = ecx.tcx.types.isize; - ecx.write_primval(dest, PrimVal::Bytes(1), ty)?; - - // FIXME: extract main source file path - // Third argument (argv): &[b"foo"] - let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; - let ty = ecx.tcx.mk_imm_ptr(ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8)); - let foo = ecx.memory.allocate_cached(b"foo\0")?; - let ptr_size = ecx.memory.pointer_size(); - let foo_ptr = ecx.memory.allocate(ptr_size * 1, ptr_size, MemoryKind::UninitializedStatic)?; - ecx.memory.write_primval(foo_ptr.into(), PrimVal::Ptr(foo.into()), ptr_size, false)?; - ecx.memory.mark_static_initalized(foo_ptr.alloc_id, Mutability::Immutable)?; - ecx.write_ptr(dest, foo_ptr.into(), ty)?; - - assert!(args.next().is_none(), "start lang item has more arguments than expected"); - } else { - ecx.push_stack_frame( - main_instance, - main_mir.span, - main_mir, - Lvalue::undef(), - StackPopCleanup::None, - )?; - - // No arguments - let mut args = ecx.frame().mir.args_iter(); - assert!(args.next().is_none(), "main function must not have arguments"); - } - - while ecx.step()? {} - ecx.run_tls_dtors()?; - if let Some(cleanup_ptr) = cleanup_ptr { - ecx.memory_mut().deallocate( - cleanup_ptr, - None, - MemoryKind::Stack, - )?; - } - Ok(()) - } - - let mut ecx = EvalContext::new(tcx, limits, Default::default(), Default::default()); - match run_main(&mut ecx, main_id, start_wrapper) { - Ok(()) => { - let leaks = ecx.memory().leak_report(); - if leaks != 0 { - tcx.sess.err("the evaluated program leaked memory"); - } - } - Err(mut e) => { - ecx.report(&mut e); - } - } -} - -pub struct Evaluator; -#[derive(Default)] -pub struct EvaluatorData { - /// Environment variables set by `setenv` - /// Miri does not expose env vars from the host to the emulated program - pub(crate) env_vars: HashMap, MemoryPointer>, -} - -pub type TlsKey = usize; - -#[derive(Copy, Clone, Debug)] -pub struct TlsEntry<'tcx> { - data: Pointer, // Will eventually become a map from thread IDs to `Pointer`s, if we ever support more than one thread. - dtor: Option>, -} - -#[derive(Default)] -pub struct MemoryData<'tcx> { - /// The Key to use for the next thread-local allocation. - next_thread_local: TlsKey, - - /// pthreads-style thread-local storage. - thread_local: BTreeMap>, -} - -impl<'tcx> Machine<'tcx> for Evaluator { - type Data = EvaluatorData; - type MemoryData = MemoryData<'tcx>; - type MemoryKinds = memory::MemoryKind; - - /// Returns Ok() when the function was handled, fail otherwise - fn eval_fn_call<'a>( - ecx: &mut EvalContext<'a, 'tcx, Self>, - instance: ty::Instance<'tcx>, - destination: Option<(Lvalue, mir::BasicBlock)>, - args: &[ValTy<'tcx>], - span: Span, - sig: ty::FnSig<'tcx>, - ) -> EvalResult<'tcx, bool> { - ecx.eval_fn_call(instance, destination, args, span, sig) - } - - fn call_intrinsic<'a>( - ecx: &mut rustc_miri::interpret::EvalContext<'a, 'tcx, Self>, - instance: ty::Instance<'tcx>, - args: &[ValTy<'tcx>], - dest: Lvalue, - dest_ty: ty::Ty<'tcx>, - dest_layout: &'tcx Layout, - target: mir::BasicBlock, - ) -> EvalResult<'tcx> { - ecx.call_intrinsic(instance, args, dest, dest_ty, dest_layout, target) - } - - fn try_ptr_op<'a>( - ecx: &rustc_miri::interpret::EvalContext<'a, 'tcx, Self>, - bin_op: mir::BinOp, - left: PrimVal, - left_ty: ty::Ty<'tcx>, - right: PrimVal, - right_ty: ty::Ty<'tcx>, - ) -> EvalResult<'tcx, Option<(PrimVal, bool)>> { - ecx.ptr_op(bin_op, left, left_ty, right, right_ty) - } - - fn mark_static_initialized(m: memory::MemoryKind) -> EvalResult<'tcx> { - use memory::MemoryKind::*; - match m { - // FIXME: This could be allowed, but not for env vars set during miri execution - Env => err!(Unimplemented("statics can't refer to env vars".to_owned())), - _ => Ok(()), - } - } - - fn box_alloc<'a>( - ecx: &mut EvalContext<'a, 'tcx, Self>, - ty: ty::Ty<'tcx>, - dest: Lvalue, - ) -> EvalResult<'tcx> { - let size = ecx.type_size(ty)?.expect("box only works with sized types"); - let align = ecx.type_align(ty)?; - - // Call the `exchange_malloc` lang item - let malloc = ecx.tcx.lang_items().exchange_malloc_fn().unwrap(); - let malloc = ty::Instance::mono(ecx.tcx, malloc); - let malloc_mir = ecx.load_mir(malloc.def)?; - ecx.push_stack_frame( - malloc, - malloc_mir.span, - malloc_mir, - dest, - // Don't do anything when we are done. The statement() function will increment - // the old stack frame's stmt counter to the next statement, which means that when - // exchange_malloc returns, we go on evaluating exactly where we want to be. - StackPopCleanup::None, - )?; - - let mut args = ecx.frame().mir.args_iter(); - let usize = ecx.tcx.types.usize; - - // First argument: size - let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; - ecx.write_value( - ValTy { - value: Value::ByVal(PrimVal::Bytes(size as u128)), - ty: usize, - }, - dest, - )?; - - // Second argument: align - let dest = ecx.eval_lvalue(&mir::Lvalue::Local(args.next().unwrap()))?; - ecx.write_value( - ValTy { - value: Value::ByVal(PrimVal::Bytes(align as u128)), - ty: usize, - }, - dest, - )?; - - // No more arguments - assert!(args.next().is_none(), "exchange_malloc lang item has more arguments than expected"); - Ok(()) - } - - fn global_item_with_linkage<'a>( - ecx: &mut EvalContext<'a, 'tcx, Self>, - instance: ty::Instance<'tcx>, - mutability: Mutability, - ) -> EvalResult<'tcx> { - // FIXME: check that it's `#[linkage = "extern_weak"]` - trace!("Initializing an extern global with NULL"); - let ptr_size = ecx.memory.pointer_size(); - let ptr = ecx.memory.allocate( - ptr_size, - ptr_size, - MemoryKind::UninitializedStatic, - )?; - ecx.memory.write_ptr_sized_unsigned(ptr, PrimVal::Bytes(0))?; - ecx.memory.mark_static_initalized(ptr.alloc_id, mutability)?; - ecx.globals.insert( - GlobalId { - instance, - promoted: None, - }, - PtrAndAlign { - ptr: ptr.into(), - aligned: true, - }, - ); - Ok(()) - } -} diff --git a/miri/memory.rs b/miri/memory.rs deleted file mode 100644 index 110540c0cf1d..000000000000 --- a/miri/memory.rs +++ /dev/null @@ -1,16 +0,0 @@ - -#[derive(Debug, PartialEq, Copy, Clone)] -pub enum MemoryKind { - /// Error if deallocated any other way than `rust_deallocate` - Rust, - /// Error if deallocated any other way than `free` - C, - /// Part of env var emulation - Env, -} - -impl Into<::rustc_miri::interpret::MemoryKind> for MemoryKind { - fn into(self) -> ::rustc_miri::interpret::MemoryKind { - ::rustc_miri::interpret::MemoryKind::Machine(self) - } -} diff --git a/miri/operator.rs b/miri/operator.rs deleted file mode 100644 index 6d68aadf96cc..000000000000 --- a/miri/operator.rs +++ /dev/null @@ -1,175 +0,0 @@ -use rustc::ty; -use rustc::mir; - -use rustc_miri::interpret::*; - -use helpers::EvalContextExt as HelperEvalContextExt; - -pub trait EvalContextExt<'tcx> { - fn ptr_op( - &self, - bin_op: mir::BinOp, - left: PrimVal, - left_ty: ty::Ty<'tcx>, - right: PrimVal, - right_ty: ty::Ty<'tcx>, - ) -> EvalResult<'tcx, Option<(PrimVal, bool)>>; - - fn ptr_int_arithmetic( - &self, - bin_op: mir::BinOp, - left: MemoryPointer, - right: i128, - signed: bool, - ) -> EvalResult<'tcx, (PrimVal, bool)>; -} - -impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator> { - fn ptr_op( - &self, - bin_op: mir::BinOp, - left: PrimVal, - left_ty: ty::Ty<'tcx>, - right: PrimVal, - right_ty: ty::Ty<'tcx>, - ) -> EvalResult<'tcx, Option<(PrimVal, bool)>> { - use rustc_miri::interpret::PrimValKind::*; - use rustc::mir::BinOp::*; - let usize = PrimValKind::from_uint_size(self.memory.pointer_size()); - let isize = PrimValKind::from_int_size(self.memory.pointer_size()); - let left_kind = self.ty_to_primval_kind(left_ty)?; - let right_kind = self.ty_to_primval_kind(right_ty)?; - match bin_op { - Offset if left_kind == Ptr && right_kind == usize => { - let pointee_ty = left_ty - .builtin_deref(true, ty::LvaluePreference::NoPreference) - .expect("Offset called on non-ptr type") - .ty; - let ptr = self.pointer_offset( - left.into(), - pointee_ty, - right.to_bytes()? as i64, - )?; - Ok(Some((ptr.into_inner_primval(), false))) - } - // These work on anything - Eq if left_kind == right_kind => { - let result = match (left, right) { - (PrimVal::Bytes(left), PrimVal::Bytes(right)) => left == right, - (PrimVal::Ptr(left), PrimVal::Ptr(right)) => left == right, - (PrimVal::Undef, _) | - (_, PrimVal::Undef) => return err!(ReadUndefBytes), - _ => false, - }; - Ok(Some((PrimVal::from_bool(result), false))) - } - Ne if left_kind == right_kind => { - let result = match (left, right) { - (PrimVal::Bytes(left), PrimVal::Bytes(right)) => left != right, - (PrimVal::Ptr(left), PrimVal::Ptr(right)) => left != right, - (PrimVal::Undef, _) | - (_, PrimVal::Undef) => return err!(ReadUndefBytes), - _ => true, - }; - Ok(Some((PrimVal::from_bool(result), false))) - } - // These need both pointers to be in the same allocation - Lt | Le | Gt | Ge | Sub - if left_kind == right_kind && - (left_kind == Ptr || left_kind == usize || left_kind == isize) && - left.is_ptr() && right.is_ptr() => { - let left = left.to_ptr()?; - let right = right.to_ptr()?; - if left.alloc_id == right.alloc_id { - let res = match bin_op { - Lt => left.offset < right.offset, - Le => left.offset <= right.offset, - Gt => left.offset > right.offset, - Ge => left.offset >= right.offset, - Sub => { - return self.binary_op( - Sub, - PrimVal::Bytes(left.offset as u128), - self.tcx.types.usize, - PrimVal::Bytes(right.offset as u128), - self.tcx.types.usize, - ).map(Some) - } - _ => bug!("We already established it has to be one of these operators."), - }; - Ok(Some((PrimVal::from_bool(res), false))) - } else { - // Both are pointers, but from different allocations. - err!(InvalidPointerMath) - } - } - // These work if one operand is a pointer, the other an integer - Add | BitAnd | Sub - if left_kind == right_kind && (left_kind == usize || left_kind == isize) && - left.is_ptr() && right.is_bytes() => { - // Cast to i128 is fine as we checked the kind to be ptr-sized - self.ptr_int_arithmetic( - bin_op, - left.to_ptr()?, - right.to_bytes()? as i128, - left_kind == isize, - ).map(Some) - } - Add | BitAnd - if left_kind == right_kind && (left_kind == usize || left_kind == isize) && - left.is_bytes() && right.is_ptr() => { - // This is a commutative operation, just swap the operands - self.ptr_int_arithmetic( - bin_op, - right.to_ptr()?, - left.to_bytes()? as i128, - left_kind == isize, - ).map(Some) - } - _ => Ok(None), - } - } - - fn ptr_int_arithmetic( - &self, - bin_op: mir::BinOp, - left: MemoryPointer, - right: i128, - signed: bool, - ) -> EvalResult<'tcx, (PrimVal, bool)> { - use rustc::mir::BinOp::*; - - fn map_to_primval((res, over): (MemoryPointer, bool)) -> (PrimVal, bool) { - (PrimVal::Ptr(res), over) - } - - Ok(match bin_op { - Sub => - // The only way this can overflow is by underflowing, so signdeness of the right operands does not matter - map_to_primval(left.overflowing_signed_offset(-right, self)), - Add if signed => - map_to_primval(left.overflowing_signed_offset(right, self)), - Add if !signed => - map_to_primval(left.overflowing_offset(right as u64, self)), - - BitAnd if !signed => { - let base_mask : u64 = !(self.memory.get(left.alloc_id)?.align - 1); - let right = right as u64; - if right & base_mask == base_mask { - // Case 1: The base address bits are all preserved, i.e., right is all-1 there - (PrimVal::Ptr(MemoryPointer::new(left.alloc_id, left.offset & right)), false) - } else if right & base_mask == 0 { - // Case 2: The base address bits are all taken away, i.e., right is all-0 there - (PrimVal::from_u128((left.offset & right) as u128), false) - } else { - return err!(ReadPointerAsBytes); - } - } - - _ => { - let msg = format!("unimplemented binary op on pointer {:?}: {:?}, {:?} ({})", bin_op, left, right, if signed { "signed" } else { "unsigned" }); - return err!(Unimplemented(msg)); - } - }) - } -} diff --git a/miri/tls.rs b/miri/tls.rs deleted file mode 100644 index e592478f6f9e..000000000000 --- a/miri/tls.rs +++ /dev/null @@ -1,142 +0,0 @@ -use rustc::{ty, mir}; - -use super::{TlsKey, TlsEntry, EvalResult, EvalErrorKind, Pointer, Memory, Evaluator, Lvalue, - StackPopCleanup, EvalContext}; - -pub trait MemoryExt<'tcx> { - fn create_tls_key(&mut self, dtor: Option>) -> TlsKey; - fn delete_tls_key(&mut self, key: TlsKey) -> EvalResult<'tcx>; - fn load_tls(&mut self, key: TlsKey) -> EvalResult<'tcx, Pointer>; - fn store_tls(&mut self, key: TlsKey, new_data: Pointer) -> EvalResult<'tcx>; - fn fetch_tls_dtor( - &mut self, - key: Option, - ) -> EvalResult<'tcx, Option<(ty::Instance<'tcx>, Pointer, TlsKey)>>; -} - -pub trait EvalContextExt<'tcx> { - fn run_tls_dtors(&mut self) -> EvalResult<'tcx>; -} - -impl<'a, 'tcx: 'a> MemoryExt<'tcx> for Memory<'a, 'tcx, Evaluator> { - fn create_tls_key(&mut self, dtor: Option>) -> TlsKey { - let new_key = self.data.next_thread_local; - self.data.next_thread_local += 1; - self.data.thread_local.insert( - new_key, - TlsEntry { - data: Pointer::null(), - dtor, - }, - ); - trace!("New TLS key allocated: {} with dtor {:?}", new_key, dtor); - return new_key; - } - - fn delete_tls_key(&mut self, key: TlsKey) -> EvalResult<'tcx> { - return match self.data.thread_local.remove(&key) { - Some(_) => { - trace!("TLS key {} removed", key); - Ok(()) - } - None => err!(TlsOutOfBounds), - }; - } - - fn load_tls(&mut self, key: TlsKey) -> EvalResult<'tcx, Pointer> { - return match self.data.thread_local.get(&key) { - Some(&TlsEntry { data, .. }) => { - trace!("TLS key {} loaded: {:?}", key, data); - Ok(data) - } - None => err!(TlsOutOfBounds), - }; - } - - fn store_tls(&mut self, key: TlsKey, new_data: Pointer) -> EvalResult<'tcx> { - return match self.data.thread_local.get_mut(&key) { - Some(&mut TlsEntry { ref mut data, .. }) => { - trace!("TLS key {} stored: {:?}", key, new_data); - *data = new_data; - Ok(()) - } - None => err!(TlsOutOfBounds), - }; - } - - /// Returns a dtor, its argument and its index, if one is supposed to run - /// - /// An optional destructor function may be associated with each key value. - /// At thread exit, if a key value has a non-NULL destructor pointer, - /// and the thread has a non-NULL value associated with that key, - /// the value of the key is set to NULL, and then the function pointed - /// to is called with the previously associated value as its sole argument. - /// The order of destructor calls is unspecified if more than one destructor - /// exists for a thread when it exits. - /// - /// If, after all the destructors have been called for all non-NULL values - /// with associated destructors, there are still some non-NULL values with - /// associated destructors, then the process is repeated. - /// If, after at least {PTHREAD_DESTRUCTOR_ITERATIONS} iterations of destructor - /// calls for outstanding non-NULL values, there are still some non-NULL values - /// with associated destructors, implementations may stop calling destructors, - /// or they may continue calling destructors until no non-NULL values with - /// associated destructors exist, even though this might result in an infinite loop. - fn fetch_tls_dtor( - &mut self, - key: Option, - ) -> EvalResult<'tcx, Option<(ty::Instance<'tcx>, Pointer, TlsKey)>> { - use std::collections::Bound::*; - let start = match key { - Some(key) => Excluded(key), - None => Unbounded, - }; - for (&key, &mut TlsEntry { ref mut data, dtor }) in - self.data.thread_local.range_mut((start, Unbounded)) - { - if !data.is_null()? { - if let Some(dtor) = dtor { - let ret = Some((dtor, *data, key)); - *data = Pointer::null(); - return Ok(ret); - } - } - } - return Ok(None); - } -} - -impl<'a, 'tcx: 'a> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, Evaluator> { - fn run_tls_dtors(&mut self) -> EvalResult<'tcx> { - let mut dtor = self.memory.fetch_tls_dtor(None)?; - // FIXME: replace loop by some structure that works with stepping - while let Some((instance, ptr, key)) = dtor { - trace!("Running TLS dtor {:?} on {:?}", instance, ptr); - // TODO: Potentially, this has to support all the other possible instances? - // See eval_fn_call in interpret/terminator/mod.rs - let mir = self.load_mir(instance.def)?; - self.push_stack_frame( - instance, - mir.span, - mir, - Lvalue::undef(), - StackPopCleanup::None, - )?; - let arg_local = self.frame().mir.args_iter().next().ok_or( - EvalErrorKind::AbiViolation("TLS dtor does not take enough arguments.".to_owned()), - )?; - let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?; - let ty = self.tcx.mk_mut_ptr(self.tcx.types.u8); - self.write_ptr(dest, ptr, ty)?; - - // step until out of stackframes - while self.step()? {} - - dtor = match self.memory.fetch_tls_dtor(Some(key))? { - dtor @ Some(_) => dtor, - None => self.memory.fetch_tls_dtor(None)?, - }; - } - Ok(()) - } -} diff --git a/rustc_tests/Cargo.lock b/rustc_tests/Cargo.lock deleted file mode 100644 index a1e273a96bdb..000000000000 --- a/rustc_tests/Cargo.lock +++ /dev/null @@ -1,217 +0,0 @@ -[root] -name = "rustc_tests" -version = "0.1.0" -dependencies = [ - "miri 0.1.0", -] - -[[package]] -name = "aho-corasick" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "byteorder" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cfg-if" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "dbghelp-sys" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "env_logger" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "gcc" -version = "0.3.53" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "kernel32-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "lazy_static" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "libc" -version = "0.2.30" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "log_settings" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "memchr" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "miri" -version = "0.1.0" -dependencies = [ - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_miri 0.1.0", -] - -[[package]] -name = "regex" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "regex-syntax" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc-demangle" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "rustc_miri" -version = "0.1.0" -dependencies = [ - "backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "thread_local" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "unreachable" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "utf8-ranges" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[metadata] -"checksum aho-corasick 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "500909c4f87a9e52355b26626d890833e9e1d53ac566db76c36faa984b889699" -"checksum backtrace 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "99f2ce94e22b8e664d95c57fff45b98a966c2252b60691d0b7aeeccd88d70983" -"checksum backtrace-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "afccc5772ba333abccdf60d55200fa3406f8c59dcf54d5f7998c9107d3799c7c" -"checksum byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff81738b726f5d099632ceaffe7fb65b90212e8dce59d518729e7e8634032d3d" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" -"checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" -"checksum gcc 0.3.53 (registry+https://github.com/rust-lang/crates.io-index)" = "e8310f7e9c890398b0e80e301c4f474e9918d2b27fca8f48486ca775fa9ffc5a" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3b37545ab726dd833ec6420aaba8231c5b320814b9029ad585555d2a03e94fbf" -"checksum libc 0.2.30 (registry+https://github.com/rust-lang/crates.io-index)" = "2370ca07ec338939e356443dac2296f581453c35fe1e3a3ed06023c49435f915" -"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" -"checksum log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d382732ea0fbc09790c4899db3255bdea0fc78b54bf234bd18a63bb603915b6" -"checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" -"checksum regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1731164734096285ec2a5ec7fea5248ae2f5485b3feeb0115af4fda2183b2d1b" -"checksum regex-syntax 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad890a5eef7953f55427c50575c680c42841653abd2b028b68cd223d157f62db" -"checksum rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aee45432acc62f7b9a108cc054142dac51f979e69e71ddce7d6fc7adf29e817e" -"checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" -"checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" -"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" -"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" diff --git a/rustc_tests/Cargo.toml b/rustc_tests/Cargo.toml deleted file mode 100644 index 736f0629768f..000000000000 --- a/rustc_tests/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "rustc_tests" -version = "0.1.0" -authors = ["Oliver Schneider "] - -[dependencies] -miri = { path = ".." } diff --git a/rustc_tests/src/main.rs b/rustc_tests/src/main.rs deleted file mode 100644 index 819721c1cd0f..000000000000 --- a/rustc_tests/src/main.rs +++ /dev/null @@ -1,292 +0,0 @@ -#![feature(rustc_private, i128_type)] -extern crate miri; -extern crate getopts; -extern crate rustc; -extern crate rustc_driver; -extern crate rustc_errors; -extern crate syntax; - -use std::path::{PathBuf, Path}; -use std::io::Write; -use std::sync::{Mutex, Arc}; -use std::io; - - -use rustc::session::Session; -use rustc::middle::cstore::CrateStore; -use rustc_driver::{Compilation, CompilerCalls, RustcDefaultCalls}; -use rustc_driver::driver::{CompileState, CompileController}; -use rustc::session::config::{self, Input, ErrorOutputType}; -use rustc::hir::{self, itemlikevisit}; -use rustc::ty::TyCtxt; -use syntax::ast; - -struct MiriCompilerCalls { - default: RustcDefaultCalls, - /// whether we are building for the host - host_target: bool, -} - -impl<'a> CompilerCalls<'a> for MiriCompilerCalls { - fn early_callback( - &mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - descriptions: &rustc_errors::registry::Registry, - output: ErrorOutputType - ) -> Compilation { - self.default.early_callback(matches, sopts, cfg, descriptions, output) - } - fn no_input( - &mut self, - matches: &getopts::Matches, - sopts: &config::Options, - cfg: &ast::CrateConfig, - odir: &Option, - ofile: &Option, - descriptions: &rustc_errors::registry::Registry - ) -> Option<(Input, Option)> { - self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions) - } - fn late_callback( - &mut self, - matches: &getopts::Matches, - sess: &Session, - cstore: &CrateStore, - input: &Input, - odir: &Option, - ofile: &Option - ) -> Compilation { - self.default.late_callback(matches, sess, cstore, input, odir, ofile) - } - fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> CompileController<'a> { - let mut control = self.default.build_controller(sess, matches); - control.after_hir_lowering.callback = Box::new(after_hir_lowering); - control.after_analysis.callback = Box::new(after_analysis); - if !self.host_target { - // only fully compile targets on the host - control.after_analysis.stop = Compilation::Stop; - } - control - } -} - -fn after_hir_lowering(state: &mut CompileState) { - let attr = (String::from("miri"), syntax::feature_gate::AttributeType::Whitelisted); - state.session.plugin_attributes.borrow_mut().push(attr); -} - -fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) { - state.session.abort_if_errors(); - - let tcx = state.tcx.unwrap(); - let limits = Default::default(); - - if std::env::args().any(|arg| arg == "--test") { - struct Visitor<'a, 'tcx: 'a>(miri::ResourceLimits, TyCtxt<'a, 'tcx, 'tcx>, &'a CompileState<'a, 'tcx>); - impl<'a, 'tcx: 'a, 'hir> itemlikevisit::ItemLikeVisitor<'hir> for Visitor<'a, 'tcx> { - fn visit_item(&mut self, i: &'hir hir::Item) { - if let hir::Item_::ItemFn(_, _, _, _, _, body_id) = i.node { - if i.attrs.iter().any(|attr| attr.name().map_or(false, |n| n == "test")) { - let did = self.1.hir.body_owner_def_id(body_id); - println!("running test: {}", self.1.hir.def_path(did).to_string(self.1)); - miri::eval_main(self.1, did, None, self.0); - self.2.session.abort_if_errors(); - } - } - } - fn visit_trait_item(&mut self, _trait_item: &'hir hir::TraitItem) {} - fn visit_impl_item(&mut self, _impl_item: &'hir hir::ImplItem) {} - } - state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(limits, tcx, state)); - } else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() { - let entry_def_id = tcx.hir.local_def_id(entry_node_id); - let start_wrapper = tcx.lang_items().start_fn().and_then(|start_fn| - if tcx.is_mir_available(start_fn) { Some(start_fn) } else { None }); - miri::eval_main(tcx, entry_def_id, start_wrapper, limits); - - state.session.abort_if_errors(); - } else { - println!("no main function found, assuming auxiliary build"); - } -} - -fn main() { - let path = option_env!("MIRI_RUSTC_TEST") - .map(String::from) - .unwrap_or_else(|| { - std::env::var("MIRI_RUSTC_TEST") - .expect("need to set MIRI_RUSTC_TEST to path of rustc tests") - }); - - let mut mir_not_found = Vec::new(); - let mut crate_not_found = Vec::new(); - let mut success = 0; - let mut failed = Vec::new(); - let mut c_abi_fns = Vec::new(); - let mut abi = Vec::new(); - let mut unsupported = Vec::new(); - let mut unimplemented_intrinsic = Vec::new(); - let mut limits = Vec::new(); - let mut files: Vec<_> = std::fs::read_dir(path).unwrap().collect(); - while let Some(file) = files.pop() { - let file = file.unwrap(); - let path = file.path(); - if file.metadata().unwrap().is_dir() { - if !path.to_str().unwrap().ends_with("auxiliary") { - // add subdirs recursively - files.extend(std::fs::read_dir(path).unwrap()); - } - continue; - } - if !file.metadata().unwrap().is_file() || !path.to_str().unwrap().ends_with(".rs") { - continue; - } - let stderr = std::io::stderr(); - write!(stderr.lock(), "test [miri-pass] {} ... ", path.display()).unwrap(); - let mut host_target = false; - let mut args: Vec = std::env::args().filter(|arg| { - if arg == "--miri_host_target" { - host_target = true; - false // remove the flag, rustc doesn't know it - } else { - true - } - }).collect(); - // file to process - args.push(path.display().to_string()); - - let sysroot_flag = String::from("--sysroot"); - if !args.contains(&sysroot_flag) { - args.push(sysroot_flag); - args.push(Path::new(&std::env::var("HOME").unwrap()).join(".xargo").join("HOST").display().to_string()); - } - - args.push("-Zmir-opt-level=3".to_owned()); - // for auxilary builds in unit tests - args.push("-Zalways-encode-mir".to_owned()); - - // A threadsafe buffer for writing. - #[derive(Default, Clone)] - struct BufWriter(Arc>>); - - impl Write for BufWriter { - fn write(&mut self, buf: &[u8]) -> io::Result { - self.0.lock().unwrap().write(buf) - } - fn flush(&mut self) -> io::Result<()> { - self.0.lock().unwrap().flush() - } - } - let buf = BufWriter::default(); - let output = buf.clone(); - let result = std::panic::catch_unwind(|| { - rustc_driver::run_compiler(&args, &mut MiriCompilerCalls { - default: RustcDefaultCalls, - host_target, - }, None, Some(Box::new(buf))); - }); - - match result { - Ok(()) => { - success += 1; - writeln!(stderr.lock(), "ok").unwrap() - }, - Err(_) => { - let output = output.0.lock().unwrap(); - let output_err = std::str::from_utf8(&output).unwrap(); - if let Some(text) = output_err.splitn(2, "no mir for `").nth(1) { - let end = text.find('`').unwrap(); - mir_not_found.push(text[..end].to_string()); - writeln!(stderr.lock(), "NO MIR FOR `{}`", &text[..end]).unwrap(); - } else if let Some(text) = output_err.splitn(2, "can't find crate for `").nth(1) { - let end = text.find('`').unwrap(); - crate_not_found.push(text[..end].to_string()); - writeln!(stderr.lock(), "CAN'T FIND CRATE FOR `{}`", &text[..end]).unwrap(); - } else { - for text in output_err.split("error: ").skip(1) { - let end = text.find('\n').unwrap_or(text.len()); - let c_abi = "can't call C ABI function: "; - let unimplemented_intrinsic_s = "unimplemented intrinsic: "; - let unsupported_s = "miri does not support "; - let abi_s = "can't handle function with "; - let limit_s = "reached the configured maximum "; - if text.starts_with(c_abi) { - c_abi_fns.push(text[c_abi.len()..end].to_string()); - } else if text.starts_with(unimplemented_intrinsic_s) { - unimplemented_intrinsic.push(text[unimplemented_intrinsic_s.len()..end].to_string()); - } else if text.starts_with(unsupported_s) { - unsupported.push(text[unsupported_s.len()..end].to_string()); - } else if text.starts_with(abi_s) { - abi.push(text[abi_s.len()..end].to_string()); - } else if text.starts_with(limit_s) { - limits.push(text[limit_s.len()..end].to_string()); - } else if text.find("aborting").is_none() { - failed.push(text[..end].to_string()); - } - } - writeln!(stderr.lock(), "stderr: \n {}", output_err).unwrap(); - } - } - } - } - let stderr = std::io::stderr(); - let mut stderr = stderr.lock(); - writeln!(stderr, "{} success, {} no mir, {} crate not found, {} failed, \ - {} C fn, {} ABI, {} unsupported, {} intrinsic", - success, mir_not_found.len(), crate_not_found.len(), failed.len(), - c_abi_fns.len(), abi.len(), unsupported.len(), unimplemented_intrinsic.len()).unwrap(); - writeln!(stderr, "# The \"other reasons\" errors").unwrap(); - writeln!(stderr, "(sorted, deduplicated)").unwrap(); - print_vec(&mut stderr, failed); - - writeln!(stderr, "# can't call C ABI function").unwrap(); - print_vec(&mut stderr, c_abi_fns); - - writeln!(stderr, "# unsupported ABI").unwrap(); - print_vec(&mut stderr, abi); - - writeln!(stderr, "# unsupported").unwrap(); - print_vec(&mut stderr, unsupported); - - writeln!(stderr, "# unimplemented intrinsics").unwrap(); - print_vec(&mut stderr, unimplemented_intrinsic); - - writeln!(stderr, "# mir not found").unwrap(); - print_vec(&mut stderr, mir_not_found); - - writeln!(stderr, "# crate not found").unwrap(); - print_vec(&mut stderr, crate_not_found); -} - -fn print_vec(stderr: &mut W, v: Vec) { - writeln!(stderr, "```").unwrap(); - for (n, s) in vec_to_hist(v).into_iter().rev() { - writeln!(stderr, "{:4} {}", n, s).unwrap(); - } - writeln!(stderr, "```").unwrap(); -} - -fn vec_to_hist(mut v: Vec) -> Vec<(usize, T)> { - v.sort(); - let mut v = v.into_iter(); - let mut result = Vec::new(); - let mut current = v.next(); - 'outer: while let Some(current_val) = current { - let mut n = 1; - for next in &mut v { - if next == current_val { - n += 1; - } else { - result.push((n, current_val)); - current = Some(next); - continue 'outer; - } - } - result.push((n, current_val)); - break; - } - result.sort(); - result -} diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml deleted file mode 100644 index c72de828c8d2..000000000000 --- a/src/librustc_mir/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -authors = ["Scott Olson "] -description = "An experimental interpreter for Rust MIR." -license = "MIT/Apache-2.0" -name = "rustc_miri" -repository = "https://github.com/solson/miri" -version = "0.1.0" -workspace = "../.." - -[lib] -path = "lib.rs" - -[dependencies] -byteorder = { version = "1.1", features = ["i128"]} -log = "0.3.6" -log_settings = "0.1.1" -lazy_static = "0.2.8" -regex = "0.2.2" -backtrace = "0.3.3" diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs deleted file mode 100644 index c640932e50e2..000000000000 --- a/src/librustc_mir/lib.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature( - i128_type, - rustc_private, - conservative_impl_trait, - never_type, - catch_expr, -)] - -// From rustc. -#[macro_use] -extern crate log; -extern crate log_settings; -#[macro_use] -extern crate rustc; -extern crate rustc_const_math; -extern crate rustc_data_structures; -extern crate syntax; - -// From crates.io. -extern crate byteorder; -#[macro_use] -extern crate lazy_static; -extern crate regex; -extern crate backtrace; - -pub mod interpret; diff --git a/tests/compile-fail-fullmir/undefined_byte_read.rs b/tests/compile-fail-fullmir/undefined_byte_read.rs deleted file mode 100644 index 99404b7d5f3f..000000000000 --- a/tests/compile-fail-fullmir/undefined_byte_read.rs +++ /dev/null @@ -1,9 +0,0 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 - -fn main() { - let v: Vec = Vec::with_capacity(10); - let undef = unsafe { *v.get_unchecked(5) }; - let x = undef + 1; //~ ERROR: attempted to read undefined bytes - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/alignment.rs b/tests/compile-fail/alignment.rs deleted file mode 100644 index 4faaa359df62..000000000000 --- a/tests/compile-fail/alignment.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - // miri always gives allocations the worst possible alignment, so a `u8` array is guaranteed - // to be at the virtual location 1 (so one byte offset from the ultimate alignemnt location 0) - let mut x = [0u8; 20]; - let x_ptr: *mut u8 = &mut x[0]; - let y_ptr = x_ptr as *mut u64; - unsafe { - *y_ptr = 42; //~ ERROR tried to access memory with alignment 1, but alignment - } - panic!("unreachable in miri"); -} diff --git a/tests/compile-fail/assume.rs b/tests/compile-fail/assume.rs deleted file mode 100644 index 69758a5d7fe8..000000000000 --- a/tests/compile-fail/assume.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![feature(core_intrinsics)] - -fn main() { - let x = 5; - unsafe { - std::intrinsics::assume(x < 10); - std::intrinsics::assume(x > 1); - std::intrinsics::assume(x > 42); //~ ERROR: `assume` argument was false - } -} diff --git a/tests/compile-fail/bitop-beyond-alignment.rs b/tests/compile-fail/bitop-beyond-alignment.rs deleted file mode 100644 index a30c054ab5d0..000000000000 --- a/tests/compile-fail/bitop-beyond-alignment.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(dead_code)] - -use std::mem; - -enum Tag { - Tag2(A) -} - -struct Rec { - c8: u8, - t: Tag -} - -fn mk_rec() -> Rec { - return Rec { c8:0, t:Tag::Tag2(0) }; -} - -fn is_u64_aligned(u: &Tag) -> bool { - let p: usize = unsafe { mem::transmute(u) }; - let u64_align = std::mem::align_of::(); - return (p & (u64_align + 1)) == 0; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes -} - -pub fn main() { - let x = mk_rec(); - assert!(is_u64_aligned(&x.t)); -} diff --git a/tests/compile-fail/cast_box_int_to_fn_ptr.rs b/tests/compile-fail/cast_box_int_to_fn_ptr.rs deleted file mode 100644 index 912b1bd7d91f..000000000000 --- a/tests/compile-fail/cast_box_int_to_fn_ptr.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Validation makes this fail in the wrong place -// compile-flags: -Zmir-emit-validate=0 - -fn main() { - let b = Box::new(42); - let g = unsafe { - std::mem::transmute::<&usize, &fn(i32)>(&b) - }; - - (*g)(42) //~ ERROR a memory access tried to interpret some bytes as a pointer -} diff --git a/tests/compile-fail/cast_fn_ptr.rs b/tests/compile-fail/cast_fn_ptr.rs deleted file mode 100644 index 7509ae6ed77c..000000000000 --- a/tests/compile-fail/cast_fn_ptr.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - fn f() {} - - let g = unsafe { - std::mem::transmute::(f) - }; - - g(42) //~ ERROR tried to call a function with sig fn() through a function pointer of type fn(i32) -} diff --git a/tests/compile-fail/cast_fn_ptr2.rs b/tests/compile-fail/cast_fn_ptr2.rs deleted file mode 100644 index 5d902e1f9aaa..000000000000 --- a/tests/compile-fail/cast_fn_ptr2.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - fn f(_ : (i32,i32)) {} - - let g = unsafe { - std::mem::transmute::(f) - }; - - g(42) //~ ERROR tried to call a function with sig fn((i32, i32)) through a function pointer of type fn(i32) -} diff --git a/tests/compile-fail/cast_fn_ptr_unsafe.rs b/tests/compile-fail/cast_fn_ptr_unsafe.rs deleted file mode 100644 index 568681da3c5d..000000000000 --- a/tests/compile-fail/cast_fn_ptr_unsafe.rs +++ /dev/null @@ -1,10 +0,0 @@ -// just making sure that fn -> unsafe fn casts are handled by rustc so miri doesn't have to -fn main() { - fn f() {} - - let g = f as fn() as unsafe fn(i32); //~ERROR: non-primitive cast: `fn()` as `unsafe fn(i32)` - - unsafe { - g(42); - } -} diff --git a/tests/compile-fail/cast_fn_ptr_unsafe2.rs b/tests/compile-fail/cast_fn_ptr_unsafe2.rs deleted file mode 100644 index 314365939fe8..000000000000 --- a/tests/compile-fail/cast_fn_ptr_unsafe2.rs +++ /dev/null @@ -1,10 +0,0 @@ -// just making sure that fn -> unsafe fn casts are handled by rustc so miri doesn't have to -fn main() { - fn f() {} - - let g = f as fn() as fn(i32) as unsafe fn(i32); //~ERROR: non-primitive cast: `fn()` as `fn(i32)` - - unsafe { - g(42); - } -} diff --git a/tests/compile-fail/cast_int_to_fn_ptr.rs b/tests/compile-fail/cast_int_to_fn_ptr.rs deleted file mode 100644 index 23f85dbaf3ec..000000000000 --- a/tests/compile-fail/cast_int_to_fn_ptr.rs +++ /dev/null @@ -1,10 +0,0 @@ -// Validation makes this fail in the wrong place -// compile-flags: -Zmir-emit-validate=0 - -fn main() { - let g = unsafe { - std::mem::transmute::(42) - }; - - g(42) //~ ERROR a memory access tried to interpret some bytes as a pointer -} diff --git a/tests/compile-fail/copy_nonoverlapping.rs b/tests/compile-fail/copy_nonoverlapping.rs deleted file mode 100644 index f4acbadfd549..000000000000 --- a/tests/compile-fail/copy_nonoverlapping.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(core_intrinsics)] - -use std::intrinsics::*; - -//error-pattern: copy_nonoverlapping called on overlapping ranges - -fn main() { - let mut data = [0u8; 16]; - unsafe { - let a = &data[0] as *const _; - let b = &mut data[1] as *mut _; - std::ptr::copy_nonoverlapping(a, b, 2); - } -} diff --git a/tests/compile-fail/ctlz_nonzero.rs b/tests/compile-fail/ctlz_nonzero.rs deleted file mode 100644 index 704c4d4b7d46..000000000000 --- a/tests/compile-fail/ctlz_nonzero.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(intrinsics)] - -mod rusti { - extern "rust-intrinsic" { - pub fn ctlz_nonzero(x: T) -> T; - } -} - -pub fn main() { - unsafe { - use rusti::*; - - ctlz_nonzero(0u8); //~ ERROR: ctlz_nonzero called on 0 - } -} diff --git a/tests/compile-fail/cttz_nonzero.rs b/tests/compile-fail/cttz_nonzero.rs deleted file mode 100644 index eda25c661521..000000000000 --- a/tests/compile-fail/cttz_nonzero.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(intrinsics)] - -mod rusti { - extern "rust-intrinsic" { - pub fn cttz_nonzero(x: T) -> T; - } -} - -pub fn main() { - unsafe { - use rusti::*; - - cttz_nonzero(0u8); //~ ERROR: cttz_nonzero called on 0 - } -} diff --git a/tests/compile-fail/dangling_pointer_deref.rs b/tests/compile-fail/dangling_pointer_deref.rs deleted file mode 100644 index 0ede7c96f004..000000000000 --- a/tests/compile-fail/dangling_pointer_deref.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - let p = { - let b = Box::new(42); - &*b as *const i32 - }; - let x = unsafe { *p }; //~ ERROR: dangling pointer was dereferenced - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/deallocate-bad-alignment.rs b/tests/compile-fail/deallocate-bad-alignment.rs deleted file mode 100644 index c1ae7477c81a..000000000000 --- a/tests/compile-fail/deallocate-bad-alignment.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: tried to deallocate or reallocate using incorrect alignment or size - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - Heap.dealloc(x, Layout::from_size_align_unchecked(1, 2)); - } -} diff --git a/tests/compile-fail/deallocate-bad-size.rs b/tests/compile-fail/deallocate-bad-size.rs deleted file mode 100644 index 5577f10736d2..000000000000 --- a/tests/compile-fail/deallocate-bad-size.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: tried to deallocate or reallocate using incorrect alignment or size - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - Heap.dealloc(x, Layout::from_size_align_unchecked(2, 1)); - } -} diff --git a/tests/compile-fail/deallocate-twice.rs b/tests/compile-fail/deallocate-twice.rs deleted file mode 100644 index e11df0eb4147..000000000000 --- a/tests/compile-fail/deallocate-twice.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: tried to deallocate dangling pointer - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - Heap.dealloc(x, Layout::from_size_align_unchecked(1, 1)); - Heap.dealloc(x, Layout::from_size_align_unchecked(1, 1)); - } -} diff --git a/tests/compile-fail/deref_fn_ptr.rs b/tests/compile-fail/deref_fn_ptr.rs deleted file mode 100644 index c1eaf7eaa61d..000000000000 --- a/tests/compile-fail/deref_fn_ptr.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn f() {} - -fn main() { - let x: i32 = unsafe { - *std::mem::transmute::(f) //~ ERROR: tried to dereference a function pointer - }; - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/div-by-zero-2.rs b/tests/compile-fail/div-by-zero-2.rs deleted file mode 100644 index 3e869ad4a507..000000000000 --- a/tests/compile-fail/div-by-zero-2.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(const_err)] - -fn main() { - let _n = 1 / 0; //~ ERROR: DivisionByZero -} diff --git a/tests/compile-fail/div-by-zero.rs b/tests/compile-fail/div-by-zero.rs deleted file mode 100644 index 4ac6214d88ab..000000000000 --- a/tests/compile-fail/div-by-zero.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(core_intrinsics)] - -use std::intrinsics::*; - -//error-pattern: Division by 0 in unchecked_div - -fn main() { - unsafe { - let _n = unchecked_div(1i64, 0); - } -} diff --git a/tests/compile-fail/execute_memory.rs b/tests/compile-fail/execute_memory.rs deleted file mode 100644 index 87d975e1f9d4..000000000000 --- a/tests/compile-fail/execute_memory.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Validation makes this fail in the wrong place -// compile-flags: -Zmir-emit-validate=0 - -#![feature(box_syntax)] - -fn main() { - let x = box 42; - unsafe { - let f = std::mem::transmute::, fn()>(x); - f() //~ ERROR: tried to treat a memory pointer as a function pointer - } -} diff --git a/tests/compile-fail/fn_ptr_offset.rs b/tests/compile-fail/fn_ptr_offset.rs deleted file mode 100644 index 45e32142a8c4..000000000000 --- a/tests/compile-fail/fn_ptr_offset.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Validation makes this fail in the wrong place -// compile-flags: -Zmir-emit-validate=0 - -use std::mem; - -fn f() {} - -fn main() { - let x : fn() = f; - let y : *mut u8 = unsafe { mem::transmute(x) }; - let y = y.wrapping_offset(1); - let x : fn() = unsafe { mem::transmute(y) }; - x(); //~ ERROR: tried to use a function pointer after offsetting it -} diff --git a/tests/compile-fail/invalid_bool.rs b/tests/compile-fail/invalid_bool.rs deleted file mode 100644 index c30c9b439a46..000000000000 --- a/tests/compile-fail/invalid_bool.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let b = unsafe { std::mem::transmute::(2) }; //~ ERROR: invalid boolean value read - if b { unreachable!() } else { unreachable!() } -} diff --git a/tests/compile-fail/invalid_enum_discriminant.rs b/tests/compile-fail/invalid_enum_discriminant.rs deleted file mode 100644 index 9ce6d44ca460..000000000000 --- a/tests/compile-fail/invalid_enum_discriminant.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Validation makes this fail in the wrong place -// compile-flags: -Zmir-emit-validate=0 - -#[repr(C)] -pub enum Foo { - A, B, C, D -} - -fn main() { - let f = unsafe { std::mem::transmute::(42) }; - match f { - Foo::A => {}, //~ ERROR invalid enum discriminant value read - Foo::B => {}, - Foo::C => {}, - Foo::D => {}, - } -} diff --git a/tests/compile-fail/match_char.rs b/tests/compile-fail/match_char.rs deleted file mode 100644 index 4fee6e692bad..000000000000 --- a/tests/compile-fail/match_char.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - assert!(std::char::from_u32(-1_i32 as u32).is_none()); - match unsafe { std::mem::transmute::(-1) } { //~ERROR tried to interpret an invalid 32-bit value as a char: 4294967295 - 'a' => {}, - 'b' => {}, - _ => {}, - } -} diff --git a/tests/compile-fail/memleak.rs b/tests/compile-fail/memleak.rs deleted file mode 100644 index 71b4e2f442f3..000000000000 --- a/tests/compile-fail/memleak.rs +++ /dev/null @@ -1,5 +0,0 @@ -//error-pattern: the evaluated program leaked memory - -fn main() { - std::mem::forget(Box::new(42)); -} diff --git a/tests/compile-fail/memleak_rc.rs b/tests/compile-fail/memleak_rc.rs deleted file mode 100644 index b2bc6722afb0..000000000000 --- a/tests/compile-fail/memleak_rc.rs +++ /dev/null @@ -1,12 +0,0 @@ -//error-pattern: the evaluated program leaked memory - -use std::rc::Rc; -use std::cell::RefCell; - -struct Dummy(Rc>>); - -fn main() { - let x = Dummy(Rc::new(RefCell::new(None))); - let y = Dummy(x.0.clone()); - *x.0.borrow_mut() = Some(y); -} diff --git a/tests/compile-fail/modifying_constants.rs b/tests/compile-fail/modifying_constants.rs deleted file mode 100644 index cb2e7217d579..000000000000 --- a/tests/compile-fail/modifying_constants.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - let x = &1; // the `&1` is promoted to a constant, but it used to be that only the pointer is marked static, not the pointee - let y = unsafe { &mut *(x as *const i32 as *mut i32) }; - *y = 42; //~ ERROR tried to modify constant memory - assert_eq!(*x, 42); -} diff --git a/tests/compile-fail/never_say_never.rs b/tests/compile-fail/never_say_never.rs deleted file mode 100644 index 6aa4e281818c..000000000000 --- a/tests/compile-fail/never_say_never.rs +++ /dev/null @@ -1,15 +0,0 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 - -#![feature(never_type)] -#![allow(unreachable_code)] - -fn main() { - let y = &5; - let x: ! = unsafe { - *(y as *const _ as *const !) //~ ERROR tried to access a dead local variable - }; - f(x) -} - -fn f(x: !) -> ! { x } diff --git a/tests/compile-fail/never_transmute_humans.rs b/tests/compile-fail/never_transmute_humans.rs deleted file mode 100644 index 7390596cf7fa..000000000000 --- a/tests/compile-fail/never_transmute_humans.rs +++ /dev/null @@ -1,17 +0,0 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 - -#![feature(never_type)] -#![allow(unreachable_code)] -#![allow(unused_variables)] - -struct Human; - -fn main() { - let x: ! = unsafe { - std::mem::transmute::(Human) //~ ERROR entered unreachable code - }; - f(x) -} - -fn f(x: !) -> ! { x } diff --git a/tests/compile-fail/never_transmute_void.rs b/tests/compile-fail/never_transmute_void.rs deleted file mode 100644 index 0b0897644409..000000000000 --- a/tests/compile-fail/never_transmute_void.rs +++ /dev/null @@ -1,19 +0,0 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 - -#![feature(never_type)] -#![allow(unreachable_code)] -#![allow(unused_variables)] - -enum Void {} - -fn f(v: Void) -> ! { - match v {} //~ ERROR entered unreachable code -} - -fn main() { - let v: Void = unsafe { - std::mem::transmute::<(), Void>(()) - }; - f(v); -} diff --git a/tests/compile-fail/null_pointer_deref.rs b/tests/compile-fail/null_pointer_deref.rs deleted file mode 100644 index 5a26856eba08..000000000000 --- a/tests/compile-fail/null_pointer_deref.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let x: i32 = unsafe { *std::ptr::null() }; //~ ERROR: invalid use of NULL pointer - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/oom.rs b/tests/compile-fail/oom.rs deleted file mode 100644 index d4aebb912ee1..000000000000 --- a/tests/compile-fail/oom.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(custom_attribute, attr_literals)] -#![miri(memory_size=4095)] - -fn main() { - let _x = [42; 1024]; - //~^ERROR tried to allocate 4096 more bytes, but only -} diff --git a/tests/compile-fail/oom2.rs b/tests/compile-fail/oom2.rs deleted file mode 100644 index 6c973bcf4016..000000000000 --- a/tests/compile-fail/oom2.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Validation forces more allocation; disable it. -// compile-flags: -Zmir-emit-validate=0 -#![feature(box_syntax, custom_attribute, attr_literals)] -#![miri(memory_size=1024)] - -// On 64bit platforms, the allocator needs 32 bytes allocated to pass a return value, so that's the error we see. -// On 32bit platforms, it's just 16 bytes. -// error-pattern: tried to allocate - -fn main() { - loop { - ::std::mem::forget(box 42); - } -} diff --git a/tests/compile-fail/out_of_bounds_ptr_1.rs b/tests/compile-fail/out_of_bounds_ptr_1.rs deleted file mode 100644 index 8dce7e578626..000000000000 --- a/tests/compile-fail/out_of_bounds_ptr_1.rs +++ /dev/null @@ -1,8 +0,0 @@ -// error-pattern: pointer computed at offset 5, outside bounds of allocation -fn main() { - let v = [0i8; 4]; - let x = &v as *const i8; - // The error is inside another function, so we cannot match it by line - let x = unsafe { x.offset(5) }; - panic!("this should never print: {:?}", x); -} diff --git a/tests/compile-fail/out_of_bounds_ptr_2.rs b/tests/compile-fail/out_of_bounds_ptr_2.rs deleted file mode 100644 index f7546494574b..000000000000 --- a/tests/compile-fail/out_of_bounds_ptr_2.rs +++ /dev/null @@ -1,7 +0,0 @@ -// error-pattern: overflowing math -fn main() { - let v = [0i8; 4]; - let x = &v as *const i8; - let x = unsafe { x.offset(-1) }; - panic!("this should never print: {:?}", x); -} diff --git a/tests/compile-fail/out_of_bounds_read.rs b/tests/compile-fail/out_of_bounds_read.rs deleted file mode 100644 index 8c56b14bdf22..000000000000 --- a/tests/compile-fail/out_of_bounds_read.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let v: Vec = vec![1, 2]; - let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR: which has size 2 - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/out_of_bounds_read2.rs b/tests/compile-fail/out_of_bounds_read2.rs deleted file mode 100644 index d29b22ffb2a6..000000000000 --- a/tests/compile-fail/out_of_bounds_read2.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let v: Vec = vec![1, 2]; - let x = unsafe { *v.as_ptr().wrapping_offset(5) }; //~ ERROR: memory access at offset 6, outside bounds of allocation - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/overflowing-lsh-neg.rs b/tests/compile-fail/overflowing-lsh-neg.rs deleted file mode 100644 index 3a889be741ef..000000000000 --- a/tests/compile-fail/overflowing-lsh-neg.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(exceeding_bitshifts)] -#![allow(const_err)] - -fn main() { - let _n = 2i64 << -1; //~ Overflow(Shl) -} diff --git a/tests/compile-fail/overflowing-rsh-2.rs b/tests/compile-fail/overflowing-rsh-2.rs deleted file mode 100644 index ac09a1740c43..000000000000 --- a/tests/compile-fail/overflowing-rsh-2.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(exceeding_bitshifts, const_err)] - -fn main() { - // Make sure we catch overflows that would be hidden by first casting the RHS to u32 - let _n = 1i64 >> (u32::max_value() as i64 + 1); //~ Overflow(Shr) -} diff --git a/tests/compile-fail/overflowing-rsh.rs b/tests/compile-fail/overflowing-rsh.rs deleted file mode 100644 index a7ac9d1d5039..000000000000 --- a/tests/compile-fail/overflowing-rsh.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(exceeding_bitshifts)] - -fn main() { - let _n = 1i64 >> 64; //~ Overflow(Shr) -} diff --git a/tests/compile-fail/overflowing-unchecked-rsh.rs b/tests/compile-fail/overflowing-unchecked-rsh.rs deleted file mode 100644 index b8291e1300ed..000000000000 --- a/tests/compile-fail/overflowing-unchecked-rsh.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(core_intrinsics)] - -use std::intrinsics::*; - -//error-pattern: Overflowing shift by 64 in unchecked_shr - -fn main() { - unsafe { - let _n = unchecked_shr(1i64, 64); - } -} diff --git a/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs b/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs deleted file mode 100644 index 50f51d0ba9ca..000000000000 --- a/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - let mut p = &42; - unsafe { - let ptr: *mut _ = &mut p; - *(ptr as *mut u8) = 123; // if we ever support 8 bit pointers, this is gonna cause - // "attempted to interpret some raw bytes as a pointer address" instead of - // "attempted to read undefined bytes" - } - let x = *p; //~ ERROR: attempted to read undefined bytes - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/panic.rs b/tests/compile-fail/panic.rs deleted file mode 100644 index 80149eeffaa6..000000000000 --- a/tests/compile-fail/panic.rs +++ /dev/null @@ -1,7 +0,0 @@ -// FIXME: Something in panic handling fails validation with full-MIR -// compile-flags: -Zmir-emit-validate=0 -//error-pattern: the evaluated program panicked - -fn main() { - assert_eq!(5, 6); -} diff --git a/tests/compile-fail/pointer_byte_read_1.rs b/tests/compile-fail/pointer_byte_read_1.rs deleted file mode 100644 index 342eb28a970f..000000000000 --- a/tests/compile-fail/pointer_byte_read_1.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let x = 13; - let y = &x; - let z = &y as *const &i32 as *const usize; - let ptr_bytes = unsafe { *z }; // the actual deref is fine, because we read the entire pointer at once - let _ = ptr_bytes % 432; //~ ERROR: tried to access part of a pointer value as raw bytes -} diff --git a/tests/compile-fail/pointer_byte_read_2.rs b/tests/compile-fail/pointer_byte_read_2.rs deleted file mode 100644 index b0f619332e00..000000000000 --- a/tests/compile-fail/pointer_byte_read_2.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let x = 13; - let y = &x; - let z = &y as *const &i32 as *const u8; - // the deref fails, because we are reading only a part of the pointer - let _ = unsafe { *z }; //~ ERROR: tried to access part of a pointer value as raw bytes -} diff --git a/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs b/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs deleted file mode 100644 index 245b7527c55b..000000000000 --- a/tests/compile-fail/pointers_to_different_allocations_are_unorderable.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let x: *const u8 = &1; - let y: *const u8 = &2; - if x < y { //~ ERROR: attempted to do invalid arithmetic on pointers - unreachable!() - } -} diff --git a/tests/compile-fail/ptr_bitops.rs b/tests/compile-fail/ptr_bitops.rs deleted file mode 100644 index 78fd8e912b5e..000000000000 --- a/tests/compile-fail/ptr_bitops.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let bytes = [0i8, 1, 2, 3, 4, 5, 6, 7, 8, 9]; - let one = bytes.as_ptr().wrapping_offset(1); - let three = bytes.as_ptr().wrapping_offset(3); - let res = (one as usize) | (three as usize); //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes - println!("{}", res); -} diff --git a/tests/compile-fail/ptr_int_cast.rs b/tests/compile-fail/ptr_int_cast.rs deleted file mode 100644 index 396c71ebb03d..000000000000 --- a/tests/compile-fail/ptr_int_cast.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - let x = &1; - // Casting down to u8 and back up to a pointer loses too much precision; this must not work. - let x = x as *const i32; - let x = x as u8; //~ ERROR: a raw memory access tried to access part of a pointer value as raw bytes - let x = x as *const i32; - let _ = unsafe { *x }; -} diff --git a/tests/compile-fail/ptr_offset_overflow.rs b/tests/compile-fail/ptr_offset_overflow.rs deleted file mode 100644 index 578468c3399b..000000000000 --- a/tests/compile-fail/ptr_offset_overflow.rs +++ /dev/null @@ -1,6 +0,0 @@ -//error-pattern: overflowing math -fn main() { - let v = [1i8, 2]; - let x = &v[1] as *const i8; - let _ = unsafe { x.offset(isize::min_value()) }; -} diff --git a/tests/compile-fail/reading_half_a_pointer.rs b/tests/compile-fail/reading_half_a_pointer.rs deleted file mode 100644 index cc41b52f3337..000000000000 --- a/tests/compile-fail/reading_half_a_pointer.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![allow(dead_code)] - -// We use packed structs to get around alignment restrictions -#[repr(packed)] -struct Data { - pad: u8, - ptr: &'static i32, -} - -// But we need to gurantee some alignment -struct Wrapper { - align: u64, - data: Data, -} - -static G : i32 = 0; - -fn main() { - let mut w = Wrapper { align: 0, data: Data { pad: 0, ptr: &G } }; - - // Get a pointer to the beginning of the Data struct (one u8 byte, then the pointer bytes). - // Thanks to the wrapper, we know this is aligned-enough to perform a load at ptr size. - // We load at pointer type, so having a relocation is okay -- but here, the relocation - // starts 1 byte to the right, so using it would actually be wrong! - let d_alias = &mut w.data as *mut _ as *mut *const u8; - unsafe { - let _x = *d_alias; //~ ERROR: tried to access part of a pointer value as raw bytes - } -} diff --git a/tests/compile-fail/reallocate-bad-alignment-2.rs b/tests/compile-fail/reallocate-bad-alignment-2.rs deleted file mode 100644 index cd6214440ff2..000000000000 --- a/tests/compile-fail/reallocate-bad-alignment-2.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: tried to deallocate or reallocate using incorrect alignment or size - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - // Try realloc with a too big alignment. - let _y = Heap.realloc(x, Layout::from_size_align_unchecked(1, 2), Layout::from_size_align_unchecked(1, 1)).unwrap(); - } -} diff --git a/tests/compile-fail/reallocate-bad-alignment.rs b/tests/compile-fail/reallocate-bad-alignment.rs deleted file mode 100644 index da5fe1d81909..000000000000 --- a/tests/compile-fail/reallocate-bad-alignment.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: tried to deallocate or reallocate using incorrect alignment or size - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 2)).unwrap(); - // Try realloc with a too small alignment. - let _y = Heap.realloc(x, Layout::from_size_align_unchecked(1, 1), Layout::from_size_align_unchecked(1, 2)).unwrap(); - } -} diff --git a/tests/compile-fail/reallocate-bad-size.rs b/tests/compile-fail/reallocate-bad-size.rs deleted file mode 100644 index 953178742c46..000000000000 --- a/tests/compile-fail/reallocate-bad-size.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: tried to deallocate or reallocate using incorrect alignment or size - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - let _y = Heap.realloc(x, Layout::from_size_align_unchecked(2, 1), Layout::from_size_align_unchecked(1, 1)).unwrap(); - } -} diff --git a/tests/compile-fail/reallocate-change-alloc.rs b/tests/compile-fail/reallocate-change-alloc.rs deleted file mode 100644 index 290c966a2bc8..000000000000 --- a/tests/compile-fail/reallocate-change-alloc.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - let _y = Heap.realloc(x, Layout::from_size_align_unchecked(1, 1), Layout::from_size_align_unchecked(1, 1)).unwrap(); - let _z = *x; //~ ERROR: dangling pointer was dereferenced - } -} diff --git a/tests/compile-fail/reallocate-dangling.rs b/tests/compile-fail/reallocate-dangling.rs deleted file mode 100644 index 6225879a5a2a..000000000000 --- a/tests/compile-fail/reallocate-dangling.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(alloc, allocator_api)] - -extern crate alloc; - -use alloc::heap::Heap; -use alloc::allocator::*; - -// error-pattern: dangling pointer was dereferenced - -fn main() { - unsafe { - let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap(); - Heap.dealloc(x, Layout::from_size_align_unchecked(1, 1)); - Heap.realloc(x, Layout::from_size_align_unchecked(1, 1), Layout::from_size_align_unchecked(1, 1)); - } -} diff --git a/tests/compile-fail/reference_to_packed.rs b/tests/compile-fail/reference_to_packed.rs deleted file mode 100644 index cc927f879504..000000000000 --- a/tests/compile-fail/reference_to_packed.rs +++ /dev/null @@ -1,19 +0,0 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 - -#![allow(dead_code, unused_variables)] - -#[repr(packed)] -struct Foo { - x: i32, - y: i32, -} - -fn main() { - let foo = Foo { - x: 42, - y: 99, - }; - let p = &foo.x; - let i = *p; //~ ERROR tried to access memory with alignment 1, but alignment 4 is required -} diff --git a/tests/compile-fail/repeat.rs b/tests/compile-fail/repeat.rs deleted file mode 100644 index abe89e233e7c..000000000000 --- a/tests/compile-fail/repeat.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let data: [u8; std::usize::MAX] = [42; std::usize::MAX]; - //~^ ERROR: rustc layout computation failed: SizeOverflow([u8; - assert_eq!(data.len(), 1024); -} diff --git a/tests/compile-fail/repeat2.rs b/tests/compile-fail/repeat2.rs deleted file mode 100644 index d489342b8599..000000000000 --- a/tests/compile-fail/repeat2.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let data: [u8; 1024*1024*1024] = [42; 1024*1024*1024]; - //~^ ERROR: reached the configured maximum execution time - assert_eq!(data.len(), 1024*1024*1024); -} diff --git a/tests/compile-fail/stack_free.rs b/tests/compile-fail/stack_free.rs deleted file mode 100644 index 96006c884e58..000000000000 --- a/tests/compile-fail/stack_free.rs +++ /dev/null @@ -1,7 +0,0 @@ -// error-pattern: tried to deallocate Stack memory but gave Machine(Rust) as the kind - -fn main() { - let x = 42; - let bad_box = unsafe { std::mem::transmute::<&i32, Box>(&x) }; - drop(bad_box); -} diff --git a/tests/compile-fail/stack_limit.rs b/tests/compile-fail/stack_limit.rs deleted file mode 100644 index c6aaf80e6ac0..000000000000 --- a/tests/compile-fail/stack_limit.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![feature(custom_attribute, attr_literals)] -#![miri(stack_limit=16)] - -//error-pattern: reached the configured maximum number of stack frames - -fn bar() { - foo(); -} - -fn foo() { - cake(); -} - -fn cake() { - bar(); -} - -fn main() { - bar(); -} diff --git a/tests/compile-fail/static_memory_modification.rs b/tests/compile-fail/static_memory_modification.rs deleted file mode 100644 index 11961becb246..000000000000 --- a/tests/compile-fail/static_memory_modification.rs +++ /dev/null @@ -1,9 +0,0 @@ -static X: usize = 5; - -#[allow(mutable_transmutes)] -fn main() { - unsafe { - *std::mem::transmute::<&usize, &mut usize>(&X) = 6; //~ ERROR: tried to modify constant memory - assert_eq!(X, 6); - } -} diff --git a/tests/compile-fail/static_memory_modification2.rs b/tests/compile-fail/static_memory_modification2.rs deleted file mode 100644 index f030a9c281de..000000000000 --- a/tests/compile-fail/static_memory_modification2.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Validation detects that we are casting & to &mut and so it changes why we fail -// compile-flags: -Zmir-emit-validate=0 - -use std::mem::transmute; - -#[allow(mutable_transmutes)] -fn main() { - unsafe { - let s = "this is a test"; - transmute::<&[u8], &mut [u8]>(s.as_bytes())[4] = 42; //~ ERROR: tried to modify constant memory - } -} diff --git a/tests/compile-fail/static_memory_modification3.rs b/tests/compile-fail/static_memory_modification3.rs deleted file mode 100644 index 743fbe60efff..000000000000 --- a/tests/compile-fail/static_memory_modification3.rs +++ /dev/null @@ -1,9 +0,0 @@ -use std::mem::transmute; - -#[allow(mutable_transmutes)] -fn main() { - unsafe { - let bs = b"this is a test"; - transmute::<&[u8], &mut [u8]>(bs)[4] = 42; //~ ERROR: tried to modify constant memory - } -} diff --git a/tests/compile-fail/timeout.rs b/tests/compile-fail/timeout.rs deleted file mode 100644 index edd4c3186691..000000000000 --- a/tests/compile-fail/timeout.rs +++ /dev/null @@ -1,9 +0,0 @@ -//error-pattern: reached the configured maximum execution time -#![feature(custom_attribute, attr_literals)] -#![miri(step_limit=1000)] - -fn main() { - for i in 0..1000000 { - assert!(i < 1000); - } -} diff --git a/tests/compile-fail/transmute-pair-undef.rs b/tests/compile-fail/transmute-pair-undef.rs deleted file mode 100644 index acc6098af7ee..000000000000 --- a/tests/compile-fail/transmute-pair-undef.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![feature(core_intrinsics)] - -use std::mem; - -fn main() { - let x: Option> = unsafe { - let z = std::intrinsics::add_with_overflow(0usize, 0usize); - std::mem::transmute::<(usize, bool), Option>>(z) - }; - let y = &x; - // Now read this bytewise. There should be (ptr_size+1) def bytes followed by (ptr_size-1) undef bytes (the padding after the bool) in there. - let z : *const u8 = y as *const _ as *const _; - let first_undef = mem::size_of::() as isize + 1; - for i in 0..first_undef { - let byte = unsafe { *z.offset(i) }; - assert_eq!(byte, 0); - } - let v = unsafe { *z.offset(first_undef) }; - if v == 0 {} //~ ERROR attempted to read undefined bytes -} diff --git a/tests/compile-fail/transmute_fat.rs b/tests/compile-fail/transmute_fat.rs deleted file mode 100644 index 7d5d95a1dc6d..000000000000 --- a/tests/compile-fail/transmute_fat.rs +++ /dev/null @@ -1,15 +0,0 @@ -// This should fail even without validation -// compile-flags: -Zmir-emit-validate=0 -#![feature(i128_type)] - -fn main() { - #[cfg(target_pointer_width="64")] - let bad = unsafe { - std::mem::transmute::<&[u8], u128>(&[1u8]) - }; - #[cfg(target_pointer_width="32")] - let bad = unsafe { - std::mem::transmute::<&[u8], u64>(&[1u8]) - }; - bad + 1; //~ ERROR a raw memory access tried to access part of a pointer value as raw bytes -} diff --git a/tests/compile-fail/transmute_fat2.rs b/tests/compile-fail/transmute_fat2.rs deleted file mode 100644 index 028ed613eee7..000000000000 --- a/tests/compile-fail/transmute_fat2.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(i128_type)] - -fn main() { - #[cfg(target_pointer_width="64")] - let bad = unsafe { - std::mem::transmute::(42) - }; - #[cfg(target_pointer_width="32")] - let bad = unsafe { - std::mem::transmute::(42) - }; - bad[0]; //~ ERROR index out of bounds: the len is 0 but the index is 0 -} diff --git a/tests/compile-fail/unaligned_ptr_cast.rs b/tests/compile-fail/unaligned_ptr_cast.rs deleted file mode 100644 index 8ad1b323250c..000000000000 --- a/tests/compile-fail/unaligned_ptr_cast.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - let x = &2u16; - let x = x as *const _ as *const u32; - // This must fail because alignment is violated - let _x = unsafe { *x }; //~ ERROR: tried to access memory with alignment 2, but alignment 4 is required -} diff --git a/tests/compile-fail/unaligned_ptr_cast2.rs b/tests/compile-fail/unaligned_ptr_cast2.rs deleted file mode 100644 index 15fb7dd31368..000000000000 --- a/tests/compile-fail/unaligned_ptr_cast2.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let x = &2u16; - let x = x as *const _ as *const *const u8; - // This must fail because alignment is violated. Test specifically for loading pointers, which have special code - // in miri's memory. - let _x = unsafe { *x }; //~ ERROR: tried to access memory with alignment 2, but alignment -} diff --git a/tests/compile-fail/unaligned_ptr_cast_zst.rs b/tests/compile-fail/unaligned_ptr_cast_zst.rs deleted file mode 100644 index fc603840684e..000000000000 --- a/tests/compile-fail/unaligned_ptr_cast_zst.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - let x = &2u16; - let x = x as *const _ as *const [u32; 0]; - // This must fail because alignment is violated. Test specifically for loading ZST. - let _x = unsafe { *x }; //~ ERROR: tried to access memory with alignment 2, but alignment 4 is required -} diff --git a/tests/compile-fail/validation_aliasing_mut1.rs b/tests/compile-fail/validation_aliasing_mut1.rs deleted file mode 100644 index 86aa57447fe6..000000000000 --- a/tests/compile-fail/validation_aliasing_mut1.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - pub fn safe(x: &mut i32, y: &mut i32) {} //~ ERROR: in conflict with lock WriteLock -} - -fn main() { - let x = &mut 0 as *mut _; - unsafe { safe::safe(&mut *x, &mut *x) }; -} diff --git a/tests/compile-fail/validation_aliasing_mut2.rs b/tests/compile-fail/validation_aliasing_mut2.rs deleted file mode 100644 index ed7497e5e546..000000000000 --- a/tests/compile-fail/validation_aliasing_mut2.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - pub fn safe(x: &i32, y: &mut i32) {} //~ ERROR: in conflict with lock ReadLock -} - -fn main() { - let x = &mut 0 as *mut _; - unsafe { safe::safe(&*x, &mut *x) }; -} diff --git a/tests/compile-fail/validation_aliasing_mut3.rs b/tests/compile-fail/validation_aliasing_mut3.rs deleted file mode 100644 index 69fbbc167ca0..000000000000 --- a/tests/compile-fail/validation_aliasing_mut3.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - pub fn safe(x: &mut i32, y: &i32) {} //~ ERROR: in conflict with lock WriteLock -} - -fn main() { - let x = &mut 0 as *mut _; - unsafe { safe::safe(&mut *x, &*x) }; -} diff --git a/tests/compile-fail/validation_aliasing_mut4.rs b/tests/compile-fail/validation_aliasing_mut4.rs deleted file mode 100644 index 3dac55aeaac9..000000000000 --- a/tests/compile-fail/validation_aliasing_mut4.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - use std::cell::Cell; - - // Make sure &mut UnsafeCell also has a lock to it - pub fn safe(x: &mut Cell, y: &i32) {} //~ ERROR: in conflict with lock WriteLock -} - -fn main() { - let x = &mut 0 as *mut _; - unsafe { safe::safe(&mut *(x as *mut _), &*x) }; -} diff --git a/tests/compile-fail/validation_buggy_as_mut_slice.rs b/tests/compile-fail/validation_buggy_as_mut_slice.rs deleted file mode 100644 index 98eca8d3607f..000000000000 --- a/tests/compile-fail/validation_buggy_as_mut_slice.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![allow(unused_variables)] - -// For some reason, the error location is different when using fullmir -// error-pattern: in conflict with lock WriteLock - -mod safe { - use std::slice::from_raw_parts_mut; - - pub fn as_mut_slice(self_: &Vec) -> &mut [T] { - unsafe { - from_raw_parts_mut(self_.as_ptr() as *mut T, self_.len()) - } - } -} - -fn main() { - let v = vec![0,1,2]; - let v1_ = safe::as_mut_slice(&v); - let v2_ = safe::as_mut_slice(&v); -} diff --git a/tests/compile-fail/validation_buggy_split_at_mut.rs b/tests/compile-fail/validation_buggy_split_at_mut.rs deleted file mode 100644 index 9e67b2a4ab18..000000000000 --- a/tests/compile-fail/validation_buggy_split_at_mut.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - use std::slice::from_raw_parts_mut; - - pub fn split_at_mut(self_: &mut [T], mid: usize) -> (&mut [T], &mut [T]) { - let len = self_.len(); - let ptr = self_.as_mut_ptr(); - - unsafe { - assert!(mid <= len); - - (from_raw_parts_mut(ptr, len - mid), // BUG: should be "mid" instead of "len - mid" - from_raw_parts_mut(ptr.offset(mid as isize), len - mid)) - } - } -} - -fn main() { - let mut array = [1,2,3,4]; - let _x = safe::split_at_mut(&mut array, 0); //~ ERROR: in conflict with lock WriteLock -} diff --git a/tests/compile-fail/validation_illegal_write.rs b/tests/compile-fail/validation_illegal_write.rs deleted file mode 100644 index 1432f4cc9f17..000000000000 --- a/tests/compile-fail/validation_illegal_write.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - pub(crate) fn safe(x: &u32) { - let x : &mut u32 = unsafe { &mut *(x as *const _ as *mut _) }; - *x = 42; //~ ERROR: in conflict with lock ReadLock - } -} - -fn main() { - let target = &mut 42; - let target_ref = ⌖ - // do a reborrow, but we keep the lock - safe::safe(&*target); -} diff --git a/tests/compile-fail/validation_lock_confusion.rs b/tests/compile-fail/validation_lock_confusion.rs deleted file mode 100644 index b352346114d7..000000000000 --- a/tests/compile-fail/validation_lock_confusion.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Make sure validation can handle many overlapping shared borrows for different parts of a data structure -#![allow(unused_variables)] -use std::cell::RefCell; - -fn evil(x: *mut i32) { - unsafe { *x = 0; } //~ ERROR: in conflict with lock WriteLock -} - -fn test(r: &mut RefCell) { - let x = &*r; // releasing write lock, first suspension recorded - let mut x_ref = x.borrow_mut(); - let x_inner : &mut i32 = &mut *x_ref; // new inner write lock, with same lifetime as outer lock - { - let x_inner_shr = &*x_inner; // releasing inner write lock, recording suspension - let y = &*r; // second suspension for the outer write lock - let x_inner_shr2 = &*x_inner; // 2nd suspension for inner write lock - } - // If the two locks are mixed up, here we should have a write lock, but we do not. - evil(x_inner as *mut _); -} - -fn main() { - test(&mut RefCell::new(0)); -} diff --git a/tests/compile-fail/validation_pointer_smuggling.rs b/tests/compile-fail/validation_pointer_smuggling.rs deleted file mode 100644 index 3320d2a89d35..000000000000 --- a/tests/compile-fail/validation_pointer_smuggling.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![allow(unused_variables)] - -static mut PTR: *mut u8 = 0 as *mut _; - -fn fun1(x: &mut u8) { - unsafe { - PTR = x; - } -} - -fn fun2() { - // Now we use a pointer we are not allowed to use - let _x = unsafe { *PTR }; //~ ERROR: in conflict with lock WriteLock -} - -fn main() { - let mut val = 0; - fun1(&mut val); - fun2(); -} diff --git a/tests/compile-fail/validation_recover1.rs b/tests/compile-fail/validation_recover1.rs deleted file mode 100644 index 55c38a694c55..000000000000 --- a/tests/compile-fail/validation_recover1.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![allow(unused_variables)] - -#[repr(u32)] -enum Bool { True } - -mod safe { - pub(crate) fn safe(x: &mut super::Bool) { - let x = x as *mut _ as *mut u32; - unsafe { *x = 44; } // out-of-bounds enum discriminant - } -} - -fn main() { - let mut x = Bool::True; - safe::safe(&mut x); //~ ERROR: invalid enum discriminant -} diff --git a/tests/compile-fail/validation_recover2.rs b/tests/compile-fail/validation_recover2.rs deleted file mode 100644 index 756be9fde6fc..000000000000 --- a/tests/compile-fail/validation_recover2.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - // This makes a ref that was passed to us via &mut alias with things it should not alias with - pub(crate) fn safe(x: &mut &u32, target: &mut u32) { - unsafe { *x = &mut *(target as *mut _); } - } -} - -fn main() { - let target = &mut 42; - let mut target_alias = &42; // initial dummy value - safe::safe(&mut target_alias, target); //~ ERROR: in conflict with lock ReadLock -} diff --git a/tests/compile-fail/validation_recover3.rs b/tests/compile-fail/validation_recover3.rs deleted file mode 100644 index afe6fe7c0bb9..000000000000 --- a/tests/compile-fail/validation_recover3.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![allow(unused_variables)] - -mod safe { - pub(crate) fn safe(x: *mut u32) { - unsafe { *x = 42; } //~ ERROR: in conflict with lock WriteLock - } -} - -fn main() { - let target = &mut 42u32; - let target2 = target as *mut _; - drop(&mut *target); // reborrow - // Now make sure we still got the lock - safe::safe(target2); -} diff --git a/tests/compile-fail/validation_undef.rs b/tests/compile-fail/validation_undef.rs deleted file mode 100644 index b889b1ea5317..000000000000 --- a/tests/compile-fail/validation_undef.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![allow(unused_variables)] -// error-pattern: attempted to read undefined bytes - -mod safe { - use std::mem; - - pub(crate) fn make_float() -> f32 { - unsafe { mem::uninitialized() } - } -} - -fn main() { - let _x = safe::make_float(); -} diff --git a/tests/compile-fail/wild_pointer_deref.rs b/tests/compile-fail/wild_pointer_deref.rs deleted file mode 100644 index 57da8dfc01b2..000000000000 --- a/tests/compile-fail/wild_pointer_deref.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - let p = 44 as *const i32; - let x = unsafe { *p }; //~ ERROR: a memory access tried to interpret some bytes as a pointer - panic!("this should never print: {}", x); -} diff --git a/tests/compile-fail/zst.rs b/tests/compile-fail/zst.rs deleted file mode 100644 index 343982404794..000000000000 --- a/tests/compile-fail/zst.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let x = &() as *const () as *const i32; - let _ = unsafe { *x }; //~ ERROR: tried to access memory with alignment 1, but alignment 4 is required -} diff --git a/tests/compiletest.rs b/tests/compiletest.rs deleted file mode 100644 index b1ea3fc8b0d4..000000000000 --- a/tests/compiletest.rs +++ /dev/null @@ -1,213 +0,0 @@ -#![feature(slice_concat_ext)] - -extern crate compiletest_rs as compiletest; - -use std::slice::SliceConcatExt; -use std::path::{PathBuf, Path}; -use std::io::Write; -use std::env; - -macro_rules! eprintln { - ($($arg:tt)*) => { - let stderr = std::io::stderr(); - writeln!(stderr.lock(), $($arg)*).unwrap(); - } -} - -fn miri_path() -> PathBuf { - if rustc_test_suite().is_some() { - PathBuf::from(option_env!("MIRI_PATH").unwrap()) - } else { - PathBuf::from(concat!("target/", env!("PROFILE"), "/miri")) - } -} - -fn rustc_test_suite() -> Option { - option_env!("RUSTC_TEST_SUITE").map(PathBuf::from) -} - -fn rustc_lib_path() -> PathBuf { - option_env!("RUSTC_LIB_PATH").unwrap().into() -} - -fn compile_fail(sysroot: &Path, path: &str, target: &str, host: &str, fullmir: bool) { - eprintln!( - "## Running compile-fail tests in {} against miri for target {}", - path, - target - ); - let mut config = compiletest::Config::default().tempdir(); - config.mode = "compile-fail".parse().expect("Invalid mode"); - config.rustc_path = miri_path(); - let mut flags = Vec::new(); - if rustc_test_suite().is_some() { - config.run_lib_path = rustc_lib_path(); - config.compile_lib_path = rustc_lib_path(); - } - // if we are building as part of the rustc test suite, we already have fullmir for everything - if fullmir && rustc_test_suite().is_none() { - if host != target { - // skip fullmir on nonhost - return; - } - let sysroot = std::env::home_dir().unwrap() - .join(".xargo") - .join("HOST"); - config.target_rustcflags = Some(format!("--sysroot {}", sysroot.to_str().unwrap())); - config.src_base = PathBuf::from(path.to_string()); - } else { - config.target_rustcflags = Some(format!("--sysroot {}", sysroot.to_str().unwrap())); - config.src_base = PathBuf::from(path.to_string()); - } - flags.push("-Zmir-emit-validate=1".to_owned()); - config.target_rustcflags = Some(flags.join(" ")); - config.target = target.to_owned(); - compiletest::run_tests(&config); -} - -fn run_pass(path: &str) { - eprintln!("## Running run-pass tests in {} against rustc", path); - let mut config = compiletest::Config::default().tempdir(); - config.mode = "run-pass".parse().expect("Invalid mode"); - config.src_base = PathBuf::from(path); - if let Some(rustc_path) = rustc_test_suite() { - config.rustc_path = rustc_path; - config.run_lib_path = rustc_lib_path(); - config.compile_lib_path = rustc_lib_path(); - config.target_rustcflags = Some(format!("-Dwarnings --sysroot {}", get_sysroot().display())); - } else { - config.target_rustcflags = Some("-Dwarnings".to_owned()); - } - config.host_rustcflags = Some("-Dwarnings".to_string()); - compiletest::run_tests(&config); -} - -fn miri_pass(path: &str, target: &str, host: &str, fullmir: bool, opt: bool) { - let opt_str = if opt { " with optimizations" } else { "" }; - eprintln!( - "## Running run-pass tests in {} against miri for target {}{}", - path, - target, - opt_str - ); - let mut config = compiletest::Config::default().tempdir(); - config.mode = "ui".parse().expect("Invalid mode"); - config.src_base = PathBuf::from(path); - config.target = target.to_owned(); - config.host = host.to_owned(); - config.rustc_path = miri_path(); - if rustc_test_suite().is_some() { - config.run_lib_path = rustc_lib_path(); - config.compile_lib_path = rustc_lib_path(); - } - let mut flags = Vec::new(); - // Control miri logging. This is okay despite concurrent test execution as all tests - // will set this env var to the same value. - env::set_var("MIRI_LOG", "warn"); - // if we are building as part of the rustc test suite, we already have fullmir for everything - if fullmir && rustc_test_suite().is_none() { - if host != target { - // skip fullmir on nonhost - return; - } - let sysroot = std::env::home_dir().unwrap() - .join(".xargo") - .join("HOST"); - - flags.push(format!("--sysroot {}", sysroot.to_str().unwrap())); - } - if opt { - flags.push("-Zmir-opt-level=3".to_owned()); - } else { - flags.push("-Zmir-opt-level=0".to_owned()); - // For now, only validate without optimizations. Inlining breaks validation. - flags.push("-Zmir-emit-validate=1".to_owned()); - } - config.target_rustcflags = Some(flags.join(" ")); - compiletest::run_tests(&config); -} - -fn is_target_dir>(path: P) -> bool { - let mut path = path.into(); - path.push("lib"); - path.metadata().map(|m| m.is_dir()).unwrap_or(false) -} - -fn for_all_targets(sysroot: &Path, mut f: F) { - let target_dir = sysroot.join("lib").join("rustlib"); - for entry in std::fs::read_dir(target_dir).expect("invalid sysroot") { - let entry = entry.unwrap(); - if !is_target_dir(entry.path()) { - continue; - } - let target = entry.file_name().into_string().unwrap(); - f(target); - } -} - -fn get_sysroot() -> PathBuf { - let sysroot = std::env::var("MIRI_SYSROOT").unwrap_or_else(|_| { - let sysroot = std::process::Command::new("rustc") - .arg("--print") - .arg("sysroot") - .output() - .expect("rustc not found") - .stdout; - String::from_utf8(sysroot).expect("sysroot is not utf8") - }); - PathBuf::from(sysroot.trim()) -} - -fn get_host() -> String { - let rustc = rustc_test_suite().unwrap_or(PathBuf::from("rustc")); - println!("using rustc at {}", rustc.display()); - let host = 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) -} - -fn run_pass_miri(opt: bool) { - let sysroot = get_sysroot(); - let host = get_host(); - - for_all_targets(&sysroot, |target| { - miri_pass("tests/run-pass", &target, &host, false, opt); - }); - miri_pass("tests/run-pass-fullmir", &host, &host, true, opt); -} - -#[test] -fn run_pass_miri_noopt() { - run_pass_miri(false); -} - -#[test] -#[ignore] // FIXME: Disabled for now, as the optimizer is pretty broken and crashes... -fn run_pass_miri_opt() { - run_pass_miri(true); -} - -#[test] -fn run_pass_rustc() { - run_pass("tests/run-pass"); - run_pass("tests/run-pass-fullmir"); -} - -#[test] -fn compile_fail_miri() { - let sysroot = get_sysroot(); - let host = get_host(); - - for_all_targets(&sysroot, |target| { - compile_fail(&sysroot, "tests/compile-fail", &target, &host, false); - }); - compile_fail(&sysroot, "tests/compile-fail-fullmir", &host, &host, true); -} diff --git a/tests/run-pass-fullmir/catch.rs b/tests/run-pass-fullmir/catch.rs deleted file mode 100644 index 490f17d4cf4f..000000000000 --- a/tests/run-pass-fullmir/catch.rs +++ /dev/null @@ -1,8 +0,0 @@ -//ignore-msvc -use std::panic::{catch_unwind, AssertUnwindSafe}; - -fn main() { - let mut i = 3; - let _ = catch_unwind(AssertUnwindSafe(|| {i -= 2;} )); - println!("{}", i); -} diff --git a/tests/run-pass-fullmir/catch.stdout b/tests/run-pass-fullmir/catch.stdout deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/tests/run-pass-fullmir/catch.stdout +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/run-pass-fullmir/foreign-fn-linkname.rs b/tests/run-pass-fullmir/foreign-fn-linkname.rs deleted file mode 100644 index 20cb713590c9..000000000000 --- a/tests/run-pass-fullmir/foreign-fn-linkname.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc -#![feature(libc)] - -extern crate libc; -use std::ffi::CString; - -mod mlibc { - use libc::{c_char, size_t}; - - extern { - #[link_name = "strlen"] - pub fn my_strlen(str: *const c_char) -> size_t; - } -} - -fn strlen(str: String) -> usize { - // C string is terminated with a zero - let s = CString::new(str).unwrap(); - unsafe { - mlibc::my_strlen(s.as_ptr()) as usize - } -} - -pub fn main() { - let len = strlen("Rust".to_string()); - assert_eq!(len, 4); -} diff --git a/tests/run-pass-fullmir/format.rs b/tests/run-pass-fullmir/format.rs deleted file mode 100644 index a14d7054e729..000000000000 --- a/tests/run-pass-fullmir/format.rs +++ /dev/null @@ -1,4 +0,0 @@ -//ignore-msvc -fn main() { - println!("Hello {}", 13); -} diff --git a/tests/run-pass-fullmir/format.stdout b/tests/run-pass-fullmir/format.stdout deleted file mode 100644 index e193b8ae89f8..000000000000 --- a/tests/run-pass-fullmir/format.stdout +++ /dev/null @@ -1 +0,0 @@ -Hello 13 diff --git a/tests/run-pass-fullmir/from_utf8.rs b/tests/run-pass-fullmir/from_utf8.rs deleted file mode 100644 index c5d4abcfdaef..000000000000 --- a/tests/run-pass-fullmir/from_utf8.rs +++ /dev/null @@ -1,4 +0,0 @@ -//ignore-msvc -fn main() { - let _ = ::std::str::from_utf8(b"a"); -} diff --git a/tests/run-pass-fullmir/hashmap.rs b/tests/run-pass-fullmir/hashmap.rs deleted file mode 100644 index 99f05e25985e..000000000000 --- a/tests/run-pass-fullmir/hashmap.rs +++ /dev/null @@ -1,26 +0,0 @@ -//ignore-msvc -use std::collections::{self, HashMap}; -use std::hash::BuildHasherDefault; - -fn main() { - let mut map : HashMap> = Default::default(); - map.insert(0, 0); - assert_eq!(map.values().fold(0, |x, y| x+y), 0); - - let table_base = map.get(&0).unwrap() as *const _; - - let num = 22; // large enough to trigger a resize - for i in 1..num { - map.insert(i, i); - } - assert!(table_base != map.get(&0).unwrap() as *const _); // make sure relocation happened - assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now - - // Inserting again replaces the existing entries - for i in 0..num { - map.insert(i, num-1-i); - } - assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); - - // TODO: Test Entry API -} diff --git a/tests/run-pass-fullmir/heap.rs b/tests/run-pass-fullmir/heap.rs deleted file mode 100644 index 917d51d0e4b6..000000000000 --- a/tests/run-pass-fullmir/heap.rs +++ /dev/null @@ -1,35 +0,0 @@ -//ignore-msvc -#![feature(box_syntax)] - -fn make_box() -> Box<(i16, i16)> { - Box::new((1, 2)) -} - -fn make_box_syntax() -> Box<(i16, i16)> { - box (1, 2) -} - -fn allocate_reallocate() { - let mut s = String::new(); - - // 6 byte heap alloc (__rust_allocate) - s.push_str("foobar"); - assert_eq!(s.len(), 6); - assert_eq!(s.capacity(), 6); - - // heap size doubled to 12 (__rust_reallocate) - s.push_str("baz"); - assert_eq!(s.len(), 9); - assert_eq!(s.capacity(), 12); - - // heap size reduced to 9 (__rust_reallocate) - s.shrink_to_fit(); - assert_eq!(s.len(), 9); - assert_eq!(s.capacity(), 9); -} - -fn main() { - assert_eq!(*make_box(), (1, 2)); - assert_eq!(*make_box_syntax(), (1, 2)); - allocate_reallocate(); -} diff --git a/tests/run-pass-fullmir/hello.rs b/tests/run-pass-fullmir/hello.rs deleted file mode 100644 index 986efcaf9005..000000000000 --- a/tests/run-pass-fullmir/hello.rs +++ /dev/null @@ -1,4 +0,0 @@ -//ignore-msvc -fn main() { - println!("Hello, world!"); -} diff --git a/tests/run-pass-fullmir/hello.stdout b/tests/run-pass-fullmir/hello.stdout deleted file mode 100644 index af5626b4a114..000000000000 --- a/tests/run-pass-fullmir/hello.stdout +++ /dev/null @@ -1 +0,0 @@ -Hello, world! diff --git a/tests/run-pass-fullmir/integer-ops.rs b/tests/run-pass-fullmir/integer-ops.rs deleted file mode 100644 index 97c694fd5674..000000000000 --- a/tests/run-pass-fullmir/integer-ops.rs +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// FIXME: remove -Zmir-opt-level once https://github.com/rust-lang/rust/issues/43359 is fixed -// compile-flags: -Zmir-opt-level=0 - -//ignore-msvc -use std::i32; - -pub fn main() { - // This tests that do (not) do sign extension properly when loading integers - assert_eq!(u32::max_value() as i64, 4294967295); - assert_eq!(i32::min_value() as i64, -2147483648); - - assert_eq!(i8::min_value(), -128); - - assert_eq!(i8::max_value(), 127); - - assert_eq!(i32::from_str_radix("A", 16), Ok(10)); - - let n = -0b1000_0000i8; - assert_eq!(n.count_ones(), 1); - - let n = -0b1000_0000i8; - assert_eq!(n.count_zeros(), 7); - - let n = -1i16; - assert_eq!(n.leading_zeros(), 0); - - let n = -4i8; - assert_eq!(n.trailing_zeros(), 2); - - let n = 0x0123456789ABCDEFi64; - let m = -0x76543210FEDCBA99i64; - assert_eq!(n.rotate_left(32), m); - - let n = 0x0123456789ABCDEFi64; - let m = -0xFEDCBA987654322i64; - assert_eq!(n.rotate_right(4), m); - - let n = 0x0123456789ABCDEFi64; - let m = -0x1032547698BADCFFi64; - assert_eq!(n.swap_bytes(), m); - - let n = 0x0123456789ABCDEFi64; - if cfg!(target_endian = "big") { - assert_eq!(i64::from_be(n), n) - } else { - assert_eq!(i64::from_be(n), n.swap_bytes()) - } - - let n = 0x0123456789ABCDEFi64; - if cfg!(target_endian = "little") { - assert_eq!(i64::from_le(n), n) - } else { - assert_eq!(i64::from_le(n), n.swap_bytes()) - } - - let n = 0x0123456789ABCDEFi64; - if cfg!(target_endian = "big") { - assert_eq!(n.to_be(), n) - } else { - assert_eq!(n.to_be(), n.swap_bytes()) - } - - let n = 0x0123456789ABCDEFi64; - if cfg!(target_endian = "little") { - assert_eq!(n.to_le(), n) - } else { - assert_eq!(n.to_le(), n.swap_bytes()) - } - - assert_eq!(7i16.checked_add(32760), Some(32767)); - assert_eq!(8i16.checked_add(32760), None); - - assert_eq!((-127i8).checked_sub(1), Some(-128)); - assert_eq!((-128i8).checked_sub(1), None); - - assert_eq!(6i8.checked_mul(21), Some(126)); - assert_eq!(6i8.checked_mul(22), None); - - assert_eq!((-127i8).checked_div(-1), Some(127)); - assert_eq!((-128i8).checked_div(-1), None); - assert_eq!((1i8).checked_div(0), None); - - assert_eq!(5i32.checked_rem(2), Some(1)); - assert_eq!(5i32.checked_rem(0), None); - assert_eq!(i32::MIN.checked_rem(-1), None); - - assert_eq!(5i32.checked_neg(), Some(-5)); - assert_eq!(i32::MIN.checked_neg(), None); - - assert_eq!(0x10i32.checked_shl(4), Some(0x100)); - assert_eq!(0x10i32.checked_shl(33), None); - - assert_eq!(0x10i32.checked_shr(4), Some(0x1)); - assert_eq!(0x10i32.checked_shr(33), None); - - assert_eq!((-5i32).checked_abs(), Some(5)); - assert_eq!(i32::MIN.checked_abs(), None); - - assert_eq!(100i8.saturating_add(1), 101); - assert_eq!(100i8.saturating_add(127), 127); - - assert_eq!(100i8.saturating_sub(127), -27); - assert_eq!((-100i8).saturating_sub(127), -128); - - assert_eq!(100i32.saturating_mul(127), 12700); - assert_eq!((1i32 << 23).saturating_mul(1 << 23), i32::MAX); - assert_eq!((-1i32 << 23).saturating_mul(1 << 23), i32::MIN); - - assert_eq!(100i8.wrapping_add(27), 127); - assert_eq!(100i8.wrapping_add(127), -29); - - assert_eq!(0i8.wrapping_sub(127), -127); - assert_eq!((-2i8).wrapping_sub(127), 127); - - assert_eq!(10i8.wrapping_mul(12), 120); - assert_eq!(11i8.wrapping_mul(12), -124); - - assert_eq!(100u8.wrapping_div(10), 10); - assert_eq!((-128i8).wrapping_div(-1), -128); - - assert_eq!(100i8.wrapping_rem(10), 0); - assert_eq!((-128i8).wrapping_rem(-1), 0); - - assert_eq!(100i8.wrapping_neg(), -100); - assert_eq!((-128i8).wrapping_neg(), -128); - - assert_eq!((-1i8).wrapping_shl(7), -128); - assert_eq!((-1i8).wrapping_shl(8), -1); - - assert_eq!((-128i8).wrapping_shr(7), -1); - assert_eq!((-128i8).wrapping_shr(8), -128); - - assert_eq!(100i8.wrapping_abs(), 100); - assert_eq!((-100i8).wrapping_abs(), 100); - assert_eq!((-128i8).wrapping_abs(), -128); - assert_eq!((-128i8).wrapping_abs() as u8, 128); - - assert_eq!(5i32.overflowing_add(2), (7, false)); - assert_eq!(i32::MAX.overflowing_add(1), (i32::MIN, true)); - - assert_eq!(5i32.overflowing_sub(2), (3, false)); - assert_eq!(i32::MIN.overflowing_sub(1), (i32::MAX, true)); - - assert_eq!(5i32.overflowing_mul(2), (10, false)); - assert_eq!(1_000_000_000i32.overflowing_mul(10), (1410065408, true)); - - assert_eq!(5i32.overflowing_div(2), (2, false)); - assert_eq!(i32::MIN.overflowing_div(-1), (i32::MIN, true)); - - assert_eq!(5i32.overflowing_rem(2), (1, false)); - assert_eq!(i32::MIN.overflowing_rem(-1), (0, true)); - - assert_eq!(2i32.overflowing_neg(), (-2, false)); - assert_eq!(i32::MIN.overflowing_neg(), (i32::MIN, true)); - - assert_eq!(0x10i32.overflowing_shl(4), (0x100, false)); - assert_eq!(0x10i32.overflowing_shl(36), (0x100, true)); - - assert_eq!(0x10i32.overflowing_shr(4), (0x1, false)); - assert_eq!(0x10i32.overflowing_shr(36), (0x1, true)); - - assert_eq!(10i8.overflowing_abs(), (10,false)); - assert_eq!((-10i8).overflowing_abs(), (10,false)); - assert_eq!((-128i8).overflowing_abs(), (-128,true)); -} diff --git a/tests/run-pass-fullmir/issue-15080.rs b/tests/run-pass-fullmir/issue-15080.rs deleted file mode 100644 index 4a84f2bc5d62..000000000000 --- a/tests/run-pass-fullmir/issue-15080.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc - -#![feature(slice_patterns)] - -fn main() { - let mut x: &[_] = &[1, 2, 3, 4]; - - let mut result = vec!(); - loop { - x = match *x { - [1, n, 3, ref rest..] => { - result.push(n); - rest - } - [n, ref rest..] => { - result.push(n); - rest - } - [] => - break - } - } - assert_eq!(result, [2, 4]); -} diff --git a/tests/run-pass-fullmir/issue-3794.rs b/tests/run-pass-fullmir/issue-3794.rs deleted file mode 100644 index 8d55af58eeca..000000000000 --- a/tests/run-pass-fullmir/issue-3794.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc -#![feature(box_syntax)] - -trait T { - fn print(&self); -} - -#[derive(Debug)] -struct S { - s: isize, -} - -impl T for S { - fn print(&self) { - println!("{:?}", self); - } -} - -fn print_t(t: &T) { - t.print(); -} - -fn print_s(s: &S) { - s.print(); -} - -pub fn main() { - let s: Box = box S { s: 5 }; - print_s(&*s); - let t: Box = s as Box; - print_t(&*t); -} diff --git a/tests/run-pass-fullmir/issue-3794.stdout b/tests/run-pass-fullmir/issue-3794.stdout deleted file mode 100644 index e4afe6fa55f1..000000000000 --- a/tests/run-pass-fullmir/issue-3794.stdout +++ /dev/null @@ -1,2 +0,0 @@ -S { s: 5 } -S { s: 5 } diff --git a/tests/run-pass-fullmir/loop-break-value.rs b/tests/run-pass-fullmir/loop-break-value.rs deleted file mode 100644 index 8a0ea113c5d6..000000000000 --- a/tests/run-pass-fullmir/loop-break-value.rs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc - -#![feature(never_type)] -#![allow(unreachable_code)] - -#[allow(unused)] -fn never_returns() { - loop { - break loop {}; - } -} - -pub fn main() { - let value = 'outer: loop { - if 1 == 1 { - break 13; - } else { - let _never: ! = loop { - break loop { - break 'outer panic!(); - } - }; - } - }; - assert_eq!(value, 13); - - let x = [1, 3u32, 5]; - let y = [17]; - let z = []; - let coerced: &[_] = loop { - match 2 { - 1 => break &x, - 2 => break &y, - 3 => break &z, - _ => (), - } - }; - assert_eq!(coerced, &[17u32]); - - let trait_unified = loop { - break if true { - break Default::default() - } else { - break [13, 14] - }; - }; - assert_eq!(trait_unified, [0, 0]); - - let trait_unified_2 = loop { - if false { - break [String::from("Hello")] - } else { - break Default::default() - }; - }; - assert_eq!(trait_unified_2, [""]); - - let trait_unified_3 = loop { - break if false { - break [String::from("Hello")] - } else { - ["Yes".into()] - }; - }; - assert_eq!(trait_unified_3, ["Yes"]); - - let regular_break = loop { - if true { - break; - } else { - break break Default::default(); - } - }; - assert_eq!(regular_break, ()); - - let regular_break_2 = loop { - if true { - break Default::default(); - } else { - break; - } - }; - assert_eq!(regular_break_2, ()); - - let regular_break_3 = loop { - break if true { - Default::default() - } else { - break; - } - }; - assert_eq!(regular_break_3, ()); - - let regular_break_4 = loop { - break (); - break; - }; - assert_eq!(regular_break_4, ()); - - let regular_break_5 = loop { - break; - break (); - }; - assert_eq!(regular_break_5, ()); - - let nested_break_value = 'outer2: loop { - let _a: u32 = 'inner: loop { - if true { - break 'outer2 "hello"; - } else { - break 'inner 17; - } - }; - panic!(); - }; - assert_eq!(nested_break_value, "hello"); - - let break_from_while_cond = loop { - 'inner_loop: while break 'inner_loop { - panic!(); - } - break 123; - }; - assert_eq!(break_from_while_cond, 123); - - let break_from_while_to_outer = 'outer_loop: loop { - while break 'outer_loop 567 { - panic!("from_inner"); - } - panic!("from outer"); - }; - assert_eq!(break_from_while_to_outer, 567); -} diff --git a/tests/run-pass-fullmir/move-arg-2-unique.rs b/tests/run-pass-fullmir/move-arg-2-unique.rs deleted file mode 100644 index f3c656623765..000000000000 --- a/tests/run-pass-fullmir/move-arg-2-unique.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc - -#![allow(unused_features, unused_variables)] -#![feature(box_syntax)] - -fn test(foo: Box> ) { assert_eq!((*foo)[0], 10); } - -pub fn main() { - let x = box vec![10]; - // Test forgetting a local by move-in - test(x); -} diff --git a/tests/run-pass-fullmir/regions-mock-trans.rs b/tests/run-pass-fullmir/regions-mock-trans.rs deleted file mode 100644 index cef62e47a56c..000000000000 --- a/tests/run-pass-fullmir/regions-mock-trans.rs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// FIXME: We handle uninitialzied storage here, which currently makes validation fail. -// compile-flags: -Zmir-emit-validate=0 - -//ignore-msvc - -#![feature(libc)] - -#![allow(dead_code)] - -extern crate libc; -use std::mem; - -struct Arena(()); - -struct Bcx<'a> { - fcx: &'a Fcx<'a> -} - -struct Fcx<'a> { - arena: &'a Arena, - ccx: &'a Ccx -} - -struct Ccx { - x: isize -} - -fn alloc<'a>(_bcx : &'a Arena) -> &'a Bcx<'a> { - unsafe { - mem::transmute(libc::malloc(mem::size_of::>() - as libc::size_t)) - } -} - -fn h<'a>(bcx : &'a Bcx<'a>) -> &'a Bcx<'a> { - return alloc(bcx.fcx.arena); -} - -fn g(fcx : &Fcx) { - let bcx = Bcx { fcx: fcx }; - let bcx2 = h(&bcx); - unsafe { - libc::free(mem::transmute(bcx2)); - } -} - -fn f(ccx : &Ccx) { - let a = Arena(()); - let fcx = Fcx { arena: &a, ccx: ccx }; - return g(&fcx); -} - -pub fn main() { - let ccx = Ccx { x: 0 }; - f(&ccx); -} diff --git a/tests/run-pass-fullmir/u128.rs b/tests/run-pass-fullmir/u128.rs deleted file mode 100644 index 5b2efdd20517..000000000000 --- a/tests/run-pass-fullmir/u128.rs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc - -#![feature(i128_type)] - -fn b(t: T) -> T { t } - -fn main() { - let x: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFF; - assert_eq!(0, !x); - assert_eq!(0, !x); - let y: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFE; - assert_eq!(!1, y); - assert_eq!(x, y | 1); - assert_eq!(0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFE, - y & - 0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFF); - let z: u128 = 0xABCD_EF; - assert_eq!(z * z, 0x734C_C2F2_A521); - assert_eq!(z * z * z * z, 0x33EE_0E2A_54E2_59DA_A0E7_8E41); - assert_eq!(z + z + z + z, 0x2AF3_7BC); - let k: u128 = 0x1234_5678_9ABC_DEFF_EDCB_A987_6543_210; - assert_eq!(k + k, 0x2468_ACF1_3579_BDFF_DB97_530E_CA86_420); - assert_eq!(0, k - k); - assert_eq!(0x1234_5678_9ABC_DEFF_EDCB_A987_5A86_421, k - z); - assert_eq!(0x1000_0000_0000_0000_0000_0000_0000_000, - k - 0x234_5678_9ABC_DEFF_EDCB_A987_6543_210); - assert_eq!(0x6EF5_DE4C_D3BC_2AAA_3BB4_CC5D_D6EE_8, k / 42); - assert_eq!(0, k % 42); - assert_eq!(15, z % 42); - assert_eq!(0x169D_A8020_CEC18, k % 0x3ACB_FE49_FF24_AC); - assert_eq!(0x91A2_B3C4_D5E6_F7, k >> 65); - assert_eq!(0xFDB9_7530_ECA8_6420_0000_0000_0000_0000, k << 65); - assert!(k > z); - assert!(y > k); - assert!(y < x); - assert_eq!(x as u64, !0); - assert_eq!(z as u64, 0xABCD_EF); - assert_eq!(k as u64, 0xFEDC_BA98_7654_3210); - assert_eq!(k as i128, 0x1234_5678_9ABC_DEFF_EDCB_A987_6543_210); - assert_eq!((z as f64) as u128, z); - assert_eq!((z as f32) as u128, z); - assert_eq!((z as f64 * 16.0) as u128, z * 16); - assert_eq!((z as f32 * 16.0) as u128, z * 16); - let l :u128 = 432 << 100; - assert_eq!((l as f32) as u128, l); - assert_eq!((l as f64) as u128, l); - // formatting - let j: u128 = 1 << 67; - assert_eq!("147573952589676412928", format!("{}", j)); - assert_eq!("80000000000000000", format!("{:x}", j)); - assert_eq!("20000000000000000000000", format!("{:o}", j)); - assert_eq!("10000000000000000000000000000000000000000000000000000000000000000000", - format!("{:b}", j)); - assert_eq!("340282366920938463463374607431768211455", - format!("{}", u128::max_value())); - assert_eq!("147573952589676412928", format!("{:?}", j)); - // common traits - assert_eq!(x, b(x.clone())); - // overflow checks - assert_eq!((z).checked_mul(z), Some(0x734C_C2F2_A521)); - assert_eq!((k).checked_mul(k), None); - let l: u128 = b(u128::max_value() - 10); - let o: u128 = b(17); - assert_eq!(l.checked_add(b(11)), None); - assert_eq!(l.checked_sub(l), Some(0)); - assert_eq!(o.checked_sub(b(18)), None); - assert_eq!(b(1u128).checked_shl(b(127)), Some(1 << 127)); - assert_eq!(o.checked_shl(b(128)), None); -} diff --git a/tests/run-pass-fullmir/unsized-tuple-impls.rs b/tests/run-pass-fullmir/unsized-tuple-impls.rs deleted file mode 100644 index 828e5c26927e..000000000000 --- a/tests/run-pass-fullmir/unsized-tuple-impls.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc - -#![feature(unsized_tuple_coercion)] -use std::mem; - -fn main() { - let x : &(i32, i32, [i32]) = &(0, 1, [2, 3]); - let y : &(i32, i32, [i32]) = &(0, 1, [2, 3, 4]); - let mut a = [y, x]; - a.sort(); - assert_eq!(a, [x, y]); - - assert_eq!(&format!("{:?}", a), "[(0, 1, [2, 3]), (0, 1, [2, 3, 4])]"); - assert_eq!(mem::size_of_val(x), 16); -} diff --git a/tests/run-pass-fullmir/vecs.rs b/tests/run-pass-fullmir/vecs.rs deleted file mode 100644 index 9a8912a6b988..000000000000 --- a/tests/run-pass-fullmir/vecs.rs +++ /dev/null @@ -1,52 +0,0 @@ -//ignore-msvc - -fn make_vec() -> Vec { - let mut v = Vec::with_capacity(4); - v.push(1); - v.push(2); - v -} - -fn make_vec_macro() -> Vec { - vec![1, 2] -} - -fn make_vec_macro_repeat() -> Vec { - vec![42; 5] -} - -fn make_vec_macro_repeat_zeroed() -> Vec { - vec![0; 7] -} - -fn vec_into_iter() -> u8 { - vec![1, 2, 3, 4] - .into_iter() - .map(|x| x * x) - .fold(0, |x, y| x + y) -} - -fn vec_into_iter_zst() -> usize { - vec![[0u64; 0], [0u64; 0]] - .into_iter() - .map(|x| x.len()) - .sum() -} - -fn vec_reallocate() -> Vec { - let mut v = vec![1, 2]; - v.push(3); - v.push(4); - v.push(5); - v -} - -fn main() { - assert_eq!(vec_reallocate().len(), 5); - assert_eq!(vec_into_iter(), 30); - assert_eq!(vec_into_iter_zst(), 0); - assert_eq!(make_vec().capacity(), 4); - assert_eq!(make_vec_macro(), [1, 2]); - assert_eq!(make_vec_macro_repeat(), [42; 5]); - assert_eq!(make_vec_macro_repeat_zeroed(), [0; 7]); -} diff --git a/tests/run-pass/arrays.rs b/tests/run-pass/arrays.rs deleted file mode 100644 index 469dde3091eb..000000000000 --- a/tests/run-pass/arrays.rs +++ /dev/null @@ -1,45 +0,0 @@ -fn empty_array() -> [u16; 0] { - [] -} - -fn mini_array() -> [u16; 1] { - [42] -} - -fn big_array() -> [u16; 5] { - [5, 4, 3, 2, 1] -} - -fn array_array() -> [[u8; 2]; 3] { - [[5, 4], [3, 2], [1, 0]] -} - -fn index_unsafe() -> i32 { - let a = [0, 10, 20, 30]; - unsafe { *a.get_unchecked(2) } -} - -fn index() -> i32 { - let a = [0, 10, 20, 30]; - a[2] -} - -fn array_repeat() -> [u8; 8] { - [42; 8] -} - -fn slice_index() -> u8 { - let arr: &[_] = &[101, 102, 103, 104, 105, 106]; - arr[5] -} - -fn main() { - assert_eq!(empty_array(), []); - assert_eq!(index_unsafe(), 20); - assert_eq!(index(), 20); - assert_eq!(slice_index(), 106); - assert_eq!(big_array(), [5, 4, 3, 2, 1]); - assert_eq!(array_array(), [[5, 4], [3, 2], [1, 0]]); - assert_eq!(array_repeat(), [42; 8]); - assert_eq!(mini_array(), [42]); -} diff --git a/tests/run-pass/associated-const.rs b/tests/run-pass/associated-const.rs deleted file mode 100644 index fe5da49f807d..000000000000 --- a/tests/run-pass/associated-const.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait Foo { - const ID: i32; -} - -impl Foo for i32 { - const ID: i32 = 1; -} - -fn main() { - assert_eq!(1, ::ID); -} diff --git a/tests/run-pass/assume_bug.rs b/tests/run-pass/assume_bug.rs deleted file mode 100644 index e14f875c022e..000000000000 --- a/tests/run-pass/assume_bug.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - vec![()].into_iter(); -} diff --git a/tests/run-pass/atomic-access-bool.rs b/tests/run-pass/atomic-access-bool.rs deleted file mode 100644 index ada584705401..000000000000 --- a/tests/run-pass/atomic-access-bool.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::sync::atomic::{AtomicBool, ATOMIC_BOOL_INIT}; -use std::sync::atomic::Ordering::*; - -static mut ATOMIC: AtomicBool = ATOMIC_BOOL_INIT; - -fn main() { - unsafe { - assert_eq!(*ATOMIC.get_mut(), false); - ATOMIC.store(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_or(false, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_and(false, SeqCst); - assert_eq!(*ATOMIC.get_mut(), false); - ATOMIC.fetch_nand(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), true); - ATOMIC.fetch_xor(true, SeqCst); - assert_eq!(*ATOMIC.get_mut(), false); - } -} diff --git a/tests/run-pass/atomic-compare_exchange.rs b/tests/run-pass/atomic-compare_exchange.rs deleted file mode 100644 index 61e9a9658896..000000000000 --- a/tests/run-pass/atomic-compare_exchange.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::sync::atomic::{AtomicIsize, ATOMIC_ISIZE_INIT}; -use std::sync::atomic::Ordering::*; - -static ATOMIC: AtomicIsize = ATOMIC_ISIZE_INIT; - -fn main() { - // Make sure trans can emit all the intrinsics correctly - ATOMIC.compare_exchange(0, 1, Relaxed, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, Acquire, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, Release, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, AcqRel, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, SeqCst, Relaxed).ok(); - ATOMIC.compare_exchange(0, 1, Acquire, Acquire).ok(); - ATOMIC.compare_exchange(0, 1, AcqRel, Acquire).ok(); - ATOMIC.compare_exchange(0, 1, SeqCst, Acquire).ok(); - ATOMIC.compare_exchange(0, 1, SeqCst, SeqCst).ok(); - ATOMIC.compare_exchange_weak(0, 1, Relaxed, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, Acquire, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, Release, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, AcqRel, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, SeqCst, Relaxed).ok(); - ATOMIC.compare_exchange_weak(0, 1, Acquire, Acquire).ok(); - ATOMIC.compare_exchange_weak(0, 1, AcqRel, Acquire).ok(); - ATOMIC.compare_exchange_weak(0, 1, SeqCst, Acquire).ok(); - ATOMIC.compare_exchange_weak(0, 1, SeqCst, SeqCst).ok(); -} diff --git a/tests/run-pass/aux_test.rs b/tests/run-pass/aux_test.rs deleted file mode 100644 index beed82e05802..000000000000 --- a/tests/run-pass/aux_test.rs +++ /dev/null @@ -1,9 +0,0 @@ -// aux-build:dep.rs - -// ignore-cross-compile - -extern crate dep; - -fn main() { - dep::foo(); -} diff --git a/tests/run-pass/auxiliary/dep.rs b/tests/run-pass/auxiliary/dep.rs deleted file mode 100644 index b76b4321d62a..000000000000 --- a/tests/run-pass/auxiliary/dep.rs +++ /dev/null @@ -1 +0,0 @@ -pub fn foo() {} diff --git a/tests/run-pass/bad_substs.rs b/tests/run-pass/bad_substs.rs deleted file mode 100644 index d8da2de5d6df..000000000000 --- a/tests/run-pass/bad_substs.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let f: fn(i32) -> Option = Some::; - f(42); -} diff --git a/tests/run-pass/binops.rs b/tests/run-pass/binops.rs deleted file mode 100644 index a03b96fa499f..000000000000 --- a/tests/run-pass/binops.rs +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Binop corner cases - -fn test_nil() { - assert_eq!((), ()); - assert!((!(() != ()))); - assert!((!(() < ()))); - assert!((() <= ())); - assert!((!(() > ()))); - assert!((() >= ())); -} - -fn test_bool() { - assert!((!(true < false))); - assert!((!(true <= false))); - assert!((true > false)); - assert!((true >= false)); - - assert!((false < true)); - assert!((false <= true)); - assert!((!(false > true))); - assert!((!(false >= true))); - - // Bools support bitwise binops - assert_eq!(false & false, false); - assert_eq!(true & false, false); - assert_eq!(true & true, true); - assert_eq!(false | false, false); - assert_eq!(true | false, true); - assert_eq!(true | true, true); - assert_eq!(false ^ false, false); - assert_eq!(true ^ false, true); - assert_eq!(true ^ true, false); -} - -fn test_ptr() { - unsafe { - let p1: *const u8 = ::std::mem::transmute(0_usize); - let p2: *const u8 = ::std::mem::transmute(0_usize); - let p3: *const u8 = ::std::mem::transmute(1_usize); - - assert_eq!(p1, p2); - assert!(p1 != p3); - assert!(p1 < p3); - assert!(p1 <= p3); - assert!(p3 > p1); - assert!(p3 >= p3); - assert!(p1 <= p2); - assert!(p1 >= p2); - } -} - -#[derive(PartialEq, Debug)] -struct P { - x: isize, - y: isize, -} - -fn p(x: isize, y: isize) -> P { - P { - x: x, - y: y - } -} - -fn test_class() { - let q = p(1, 2); - let mut r = p(1, 2); - - assert_eq!(q, r); - r.y = 17; - assert!((r.y != q.y)); - assert_eq!(r.y, 17); - assert!((q != r)); -} - -pub fn main() { - test_nil(); - test_bool(); - test_ptr(); - test_class(); -} diff --git a/tests/run-pass/bools.rs b/tests/run-pass/bools.rs deleted file mode 100644 index 103d7eac27cd..000000000000 --- a/tests/run-pass/bools.rs +++ /dev/null @@ -1,28 +0,0 @@ -fn boolean() -> bool { - true -} - -fn if_false() -> i64 { - let c = false; - if c { 1 } else { 0 } -} - -fn if_true() -> i64 { - let c = true; - if c { 1 } else { 0 } -} - -fn match_bool() -> i16 { - let b = true; - match b { - true => 1, - _ => 0, - } -} - -fn main() { - assert!(boolean()); - assert_eq!(if_false(), 0); - assert_eq!(if_true(), 1); - assert_eq!(match_bool(), 1); -} diff --git a/tests/run-pass/box_box_trait.rs b/tests/run-pass/box_box_trait.rs deleted file mode 100644 index 57eef52d573b..000000000000 --- a/tests/run-pass/box_box_trait.rs +++ /dev/null @@ -1,29 +0,0 @@ -#![feature(box_syntax)] - -struct DroppableStruct; - -static mut DROPPED: bool = false; - -impl Drop for DroppableStruct { - fn drop(&mut self) { - unsafe { DROPPED = true; } - } -} - -trait MyTrait { fn dummy(&self) { } } -impl MyTrait for Box {} - -struct Whatever { w: Box } -impl Whatever { - fn new(w: Box) -> Whatever { - Whatever { w: w } - } -} - -fn main() { - { - let f: Box<_> = box DroppableStruct; - let _a = Whatever::new(box f as Box); - } - assert!(unsafe { DROPPED }); -} diff --git a/tests/run-pass/btreemap.rs b/tests/run-pass/btreemap.rs deleted file mode 100644 index 0fd28d6f1e8d..000000000000 --- a/tests/run-pass/btreemap.rs +++ /dev/null @@ -1,17 +0,0 @@ -// mir validation can't cope with `mem::uninitialized()`, so this test fails with validation & full-MIR. -// compile-flags: -Zmir-emit-validate=0 - -#[derive(PartialEq, Eq, PartialOrd, Ord)] -pub enum Foo { - A(&'static str), - _B, - _C, -} - -pub fn main() { - let mut b = std::collections::BTreeSet::new(); - b.insert(Foo::A("\'")); - b.insert(Foo::A("/=")); - b.insert(Foo::A("#")); - b.insert(Foo::A("0o")); -} diff --git a/tests/run-pass/c_enums.rs b/tests/run-pass/c_enums.rs deleted file mode 100644 index 11897b73eb2a..000000000000 --- a/tests/run-pass/c_enums.rs +++ /dev/null @@ -1,32 +0,0 @@ -enum Foo { - Bar = 42, - Baz, - Quux = 100, -} - -enum Signed { - Bar = -42, - Baz, - Quux = 100, -} - -fn foo() -> [u8; 3] { - [Foo::Bar as u8, Foo::Baz as u8, Foo::Quux as u8] -} - -fn signed() -> [i8; 3] { - [Signed::Bar as i8, Signed::Baz as i8, Signed::Quux as i8] -} - -fn unsafe_match() -> bool { - match unsafe { std::mem::transmute::(43) } { - Foo::Baz => true, - _ => false, - } -} - -fn main() { - assert_eq!(foo(), [42, 43, 100]); - assert_eq!(signed(), [-42, -41, 100]); - assert!(unsafe_match()); -} diff --git a/tests/run-pass/call_drop_on_array_elements.rs b/tests/run-pass/call_drop_on_array_elements.rs deleted file mode 100644 index c9b59f635e14..000000000000 --- a/tests/run-pass/call_drop_on_array_elements.rs +++ /dev/null @@ -1,22 +0,0 @@ -struct Bar(u16); // ZSTs are tested separately - -static mut DROP_COUNT: usize = 0; - -impl Drop for Bar { - fn drop(&mut self) { - assert_eq!(self.0 as usize, unsafe { DROP_COUNT }); // tests whether we are called at a valid address - unsafe { DROP_COUNT += 1; } - } -} - -fn main() { - let b = [Bar(0), Bar(1), Bar(2), Bar(3)]; - assert_eq!(unsafe { DROP_COUNT }, 0); - drop(b); - assert_eq!(unsafe { DROP_COUNT }, 4); - - // check empty case - let b : [Bar; 0] = []; - drop(b); - assert_eq!(unsafe { DROP_COUNT }, 4); -} diff --git a/tests/run-pass/call_drop_on_fat_ptr_array_elements.rs b/tests/run-pass/call_drop_on_fat_ptr_array_elements.rs deleted file mode 100644 index a1ab5c45e358..000000000000 --- a/tests/run-pass/call_drop_on_fat_ptr_array_elements.rs +++ /dev/null @@ -1,20 +0,0 @@ -trait Foo {} - -struct Bar; - -impl Foo for Bar {} - -static mut DROP_COUNT: usize = 0; - -impl Drop for Bar { - fn drop(&mut self) { - unsafe { DROP_COUNT += 1; } - } -} - -fn main() { - let b: [Box; 4] = [Box::new(Bar), Box::new(Bar), Box::new(Bar), Box::new(Bar)]; - assert_eq!(unsafe { DROP_COUNT }, 0); - drop(b); - assert_eq!(unsafe { DROP_COUNT }, 4); -} diff --git a/tests/run-pass/call_drop_on_zst_array_elements.rs b/tests/run-pass/call_drop_on_zst_array_elements.rs deleted file mode 100644 index 1887130fdd8a..000000000000 --- a/tests/run-pass/call_drop_on_zst_array_elements.rs +++ /dev/null @@ -1,21 +0,0 @@ -struct Bar; - -static mut DROP_COUNT: usize = 0; - -impl Drop for Bar { - fn drop(&mut self) { - unsafe { DROP_COUNT += 1; } - } -} - -fn main() { - let b = [Bar, Bar, Bar, Bar]; - assert_eq!(unsafe { DROP_COUNT }, 0); - drop(b); - assert_eq!(unsafe { DROP_COUNT }, 4); - - // check empty case - let b : [Bar; 0] = []; - drop(b); - assert_eq!(unsafe { DROP_COUNT }, 4); -} diff --git a/tests/run-pass/call_drop_through_owned_slice.rs b/tests/run-pass/call_drop_through_owned_slice.rs deleted file mode 100644 index 3ec6be65ed8b..000000000000 --- a/tests/run-pass/call_drop_through_owned_slice.rs +++ /dev/null @@ -1,16 +0,0 @@ -struct Bar; - -static mut DROP_COUNT: usize = 0; - -impl Drop for Bar { - fn drop(&mut self) { - unsafe { DROP_COUNT += 1; } - } -} - -fn main() { - let b: Box<[Bar]> = vec![Bar, Bar, Bar, Bar].into_boxed_slice(); - assert_eq!(unsafe { DROP_COUNT }, 0); - drop(b); - assert_eq!(unsafe { DROP_COUNT }, 4); -} diff --git a/tests/run-pass/call_drop_through_trait_object.rs b/tests/run-pass/call_drop_through_trait_object.rs deleted file mode 100644 index 9b6acf0b1474..000000000000 --- a/tests/run-pass/call_drop_through_trait_object.rs +++ /dev/null @@ -1,20 +0,0 @@ -trait Foo {} - -struct Bar; - -static mut DROP_CALLED: bool = false; - -impl Drop for Bar { - fn drop(&mut self) { - unsafe { DROP_CALLED = true; } - } -} - -impl Foo for Bar {} - -fn main() { - let b: Box = Box::new(Bar); - assert!(unsafe { !DROP_CALLED }); - drop(b); - assert!(unsafe { DROP_CALLED }); -} diff --git a/tests/run-pass/call_drop_through_trait_object_rc.rs b/tests/run-pass/call_drop_through_trait_object_rc.rs deleted file mode 100644 index ce56ca6a1caf..000000000000 --- a/tests/run-pass/call_drop_through_trait_object_rc.rs +++ /dev/null @@ -1,22 +0,0 @@ -trait Foo {} - -struct Bar; - -static mut DROP_CALLED: bool = false; - -impl Drop for Bar { - fn drop(&mut self) { - unsafe { DROP_CALLED = true; } - } -} - -impl Foo for Bar {} - -use std::rc::Rc; - -fn main() { - let b: Rc = Rc::new(Bar); - assert!(unsafe { !DROP_CALLED }); - drop(b); - assert!(unsafe { DROP_CALLED }); -} diff --git a/tests/run-pass/calls.rs b/tests/run-pass/calls.rs deleted file mode 100644 index c4ba4a9b701f..000000000000 --- a/tests/run-pass/calls.rs +++ /dev/null @@ -1,45 +0,0 @@ -#![feature(const_fn)] - -fn call() -> i32 { - fn increment(x: i32) -> i32 { - x + 1 - } - increment(1) -} - -fn factorial_recursive() -> i64 { - fn fact(n: i64) -> i64 { - if n == 0 { - 1 - } else { - n * fact(n - 1) - } - } - fact(10) -} - -fn call_generic() -> (i16, bool) { - fn id(t: T) -> T { t } - (id(42), id(true)) -} - -// Test calling a very simple function from the standard library. -fn cross_crate_fn_call() -> i64 { - if 1i32.is_positive() { 1 } else { 0 } -} - -const fn foo(i: i64) -> i64 { *&i + 1 } - -fn const_fn_call() -> i64 { - let x = 5 + foo(5); - assert_eq!(x, 11); - x -} - -fn main() { - assert_eq!(call(), 2); - assert_eq!(factorial_recursive(), 3628800); - assert_eq!(call_generic(), (42, true)); - assert_eq!(cross_crate_fn_call(), 1); - assert_eq!(const_fn_call(), 11); -} diff --git a/tests/run-pass/cast-rfc0401-vtable-kinds.rs b/tests/run-pass/cast-rfc0401-vtable-kinds.rs deleted file mode 100644 index afbd4760a3c9..000000000000 --- a/tests/run-pass/cast-rfc0401-vtable-kinds.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -// FIXME: remove the next line when https://github.com/rust-lang/rust/issues/43358 is resolved -// compile-flags: -Zmir-opt-level=0 - -// Check that you can cast between different pointers to trait objects -// whose vtable have the same kind (both lengths, or both trait pointers). - -trait Foo { - fn foo(&self, _: T) -> u32 { 42 } -} - -trait Bar { - fn bar(&self) { println!("Bar!"); } -} - -impl Foo for () {} -impl Foo for u32 { fn foo(&self, _: u32) -> u32 { self+43 } } -impl Bar for () {} - -unsafe fn round_trip_and_call<'a>(t: *const (Foo+'a)) -> u32 { - let foo_e : *const Foo = t as *const _; - let r_1 = foo_e as *mut Foo; - - (&*r_1).foo(0) -} - -#[repr(C)] -struct FooS(T); -#[repr(C)] -struct BarS(T); - -fn foo_to_bar(u: *const FooS) -> *const BarS { - u as *const BarS -} - -fn main() { - let x = 4u32; - let y : &Foo = &x; - let fl = unsafe { round_trip_and_call(y as *const Foo) }; - assert_eq!(fl, (43+4)); - - let s = FooS([0,1,2]); - let u: &FooS<[u32]> = &s; - let u: *const FooS<[u32]> = u; - let bar_ref : *const BarS<[u32]> = foo_to_bar(u); - let z : &BarS<[u32]> = unsafe{&*bar_ref}; - assert_eq!(&z.0, &[0,1,2]); - // If validation fails here, that's likely because an immutable suspension is recovered mutably. -} diff --git a/tests/run-pass/cast_fn_ptr.rs b/tests/run-pass/cast_fn_ptr.rs deleted file mode 100644 index 109e8dfc2a02..000000000000 --- a/tests/run-pass/cast_fn_ptr.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - fn f(_: *const u8) {} - - let g = unsafe { - std::mem::transmute::(f) - }; - - g(&42 as *const _); -} diff --git a/tests/run-pass/cast_fn_ptr_unsafe.rs b/tests/run-pass/cast_fn_ptr_unsafe.rs deleted file mode 100644 index 0cabb369bfdd..000000000000 --- a/tests/run-pass/cast_fn_ptr_unsafe.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - fn f() {} - - let g = f as fn() as unsafe fn(); - unsafe { - g(); - } -} diff --git a/tests/run-pass/char.rs b/tests/run-pass/char.rs deleted file mode 100644 index 505c09b0ad88..000000000000 --- a/tests/run-pass/char.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let c = 'x'; - assert_eq!(c, 'x'); - assert!('a' < 'z'); - assert!('1' < '9'); - assert_eq!(std::char::from_u32('x' as u32).unwrap(), 'x'); - // FIXME: - // assert_eq!(std::char::from_u32('x' as u32), Some('x')); -} diff --git a/tests/run-pass/closure-drop.rs b/tests/run-pass/closure-drop.rs deleted file mode 100644 index f1bdafaeb135..000000000000 --- a/tests/run-pass/closure-drop.rs +++ /dev/null @@ -1,25 +0,0 @@ -struct Foo<'a>(&'a mut bool); - -impl<'a> Drop for Foo<'a> { - fn drop(&mut self) { - *self.0 = true; - } -} - -fn f(t: T) { - t() -} - -fn main() { - let mut ran_drop = false; - { - let x = Foo(&mut ran_drop); - // this closure never by val uses its captures - // so it's basically a fn(&self) - // the shim used to not drop the `x` - let x = move || { let _ = x; }; - f(x); - } - assert!(ran_drop); -} - diff --git a/tests/run-pass/closure-field-ty.rs b/tests/run-pass/closure-field-ty.rs deleted file mode 100644 index 0d27728d2232..000000000000 --- a/tests/run-pass/closure-field-ty.rs +++ /dev/null @@ -1,10 +0,0 @@ -// miri issue #304 -fn main() { - let mut y = 0; - { - let mut box_maybe_closure = Box::new(None); - *box_maybe_closure = Some(|| { y += 1; }); - (box_maybe_closure.unwrap())(); - } - assert_eq!(y, 1); -} diff --git a/tests/run-pass/closures.rs b/tests/run-pass/closures.rs deleted file mode 100644 index 9b379051eb77..000000000000 --- a/tests/run-pass/closures.rs +++ /dev/null @@ -1,48 +0,0 @@ -fn simple() -> i32 { - let y = 10; - let f = |x| x + y; - f(2) -} - -fn crazy_closure() -> (i32, i32, i32) { - fn inner(t: T) -> (i32, T, T) { - struct NonCopy; - let x = NonCopy; - - let a = 2; - let b = 40; - let f = move |y, z, asdf| { - drop(x); - (a + b + y + z, asdf, t) - }; - f(a, b, t) - } - - inner(10) -} - -fn closure_arg_adjustment_problem() -> i64 { - fn once(f: F) { f(2); } - let mut y = 1; - { - let f = |x| y += x; - once(f); - } - y -} - -fn fn_once_closure_with_multiple_args() -> i64 { - fn once i64>(f: F) -> i64 { f(2, 3) } - let y = 1; - { - let f = |x, z| x + y + z; - once(f) - } -} - -fn main() { - assert_eq!(simple(), 12); - assert_eq!(crazy_closure(), (84, 10, 10)); - assert_eq!(closure_arg_adjustment_problem(), 3); - assert_eq!(fn_once_closure_with_multiple_args(), 6); -} diff --git a/tests/run-pass/const-vec-of-fns.rs b/tests/run-pass/const-vec-of-fns.rs deleted file mode 100644 index 0338a766e262..000000000000 --- a/tests/run-pass/const-vec-of-fns.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// pretty-expanded FIXME #23616 - -/*! - * Try to double-check that static fns have the right size (with or - * without dummy env ptr, as appropriate) by iterating a size-2 array. - * If the static size differs from the runtime size, the second element - * should be read as a null or otherwise wrong pointer and crash. - */ - -fn f() { } -static mut CLOSURES: &'static mut [fn()] = &mut [f as fn(), f as fn()]; - -pub fn main() { - unsafe { - for closure in &mut *CLOSURES { - (*closure)() - } - } -} diff --git a/tests/run-pass/constants.rs b/tests/run-pass/constants.rs deleted file mode 100644 index 718c85260142..000000000000 --- a/tests/run-pass/constants.rs +++ /dev/null @@ -1,9 +0,0 @@ -const A: usize = *&5; - -fn foo() -> usize { - A -} - -fn main() { - assert_eq!(foo(), A); -} diff --git a/tests/run-pass/deriving-associated-types.rs b/tests/run-pass/deriving-associated-types.rs deleted file mode 100644 index b67ef85acf62..000000000000 --- a/tests/run-pass/deriving-associated-types.rs +++ /dev/null @@ -1,208 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -pub trait DeclaredTrait { - type Type; -} - -impl DeclaredTrait for i32 { - type Type = i32; -} - -pub trait WhereTrait { - type Type; -} - -impl WhereTrait for i32 { - type Type = i32; -} - -// Make sure we don't add a bound that just shares a name with an associated -// type. -pub mod module { - pub type Type = i32; -} - -#[derive(PartialEq, Debug)] -struct PrivateStruct(T); - -#[derive(PartialEq, Debug)] -struct TupleStruct( - module::Type, - Option, - A, - PrivateStruct, - B, - B::Type, - Option, - ::Type, - Option<::Type>, - C, - C::Type, - Option, - ::Type, - Option<::Type>, - ::Type, -) where C: WhereTrait; - -#[derive(PartialEq, Debug)] -pub struct Struct where C: WhereTrait { - m1: module::Type, - m2: Option, - a1: A, - a2: PrivateStruct, - b: B, - b1: B::Type, - b2: Option, - b3: ::Type, - b4: Option<::Type>, - c: C, - c1: C::Type, - c2: Option, - c3: ::Type, - c4: Option<::Type>, - d: ::Type, -} - -#[derive(PartialEq, Debug)] -enum Enum where C: WhereTrait { - Unit, - Seq( - module::Type, - Option, - A, - PrivateStruct, - B, - B::Type, - Option, - ::Type, - Option<::Type>, - C, - C::Type, - Option, - ::Type, - Option<::Type>, - ::Type, - ), - Map { - m1: module::Type, - m2: Option, - a1: A, - a2: PrivateStruct, - b: B, - b1: B::Type, - b2: Option, - b3: ::Type, - b4: Option<::Type>, - c: C, - c1: C::Type, - c2: Option, - c3: ::Type, - c4: Option<::Type>, - d: ::Type, - }, -} - -fn main() { - - let e: Enum< - i32, - i32, - i32, - > = Enum::Seq( - 0, - None, - 0, - PrivateStruct(0), - 0, - 0, - None, - 0, - None, - 0, - 0, - None, - 0, - None, - 0, - ); - assert_eq!(e, e); - - let e: Enum< - i32, - i32, - i32, - > = Enum::Map { - m1: 0, - m2: None, - a1: 0, - a2: PrivateStruct(0), - b: 0, - b1: 0, - b2: None, - b3: 0, - b4: None, - c: 0, - c1: 0, - c2: None, - c3: 0, - c4: None, - d: 0, - }; - assert_eq!(e, e); - let e: TupleStruct< - i32, - i32, - i32, - > = TupleStruct( - 0, - None, - 0, - PrivateStruct(0), - 0, - 0, - None, - 0, - None, - 0, - 0, - None, - 0, - None, - 0, - ); - assert_eq!(e, e); - - let e: Struct< - i32, - i32, - i32, - > = Struct { - m1: 0, - m2: None, - a1: 0, - a2: PrivateStruct(0), - b: 0, - b1: 0, - b2: None, - b3: 0, - b4: None, - c: 0, - c1: 0, - c2: None, - c3: 0, - c4: None, - d: 0, - }; - assert_eq!(e, e); - - let e = Enum::Unit::; - assert_eq!(e, e); -} diff --git a/tests/run-pass/drop_empty_slice.rs b/tests/run-pass/drop_empty_slice.rs deleted file mode 100644 index b21c8a612c57..000000000000 --- a/tests/run-pass/drop_empty_slice.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(box_syntax)] - -fn main() { - // With the nested Vec, this is calling Offset(Unique::empty(), 0) on drop. - let args : Vec> = Vec::new(); - let _ = box args; -} diff --git a/tests/run-pass/dst-field-align.rs b/tests/run-pass/dst-field-align.rs deleted file mode 100644 index 5631b65ed9d8..000000000000 --- a/tests/run-pass/dst-field-align.rs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(dead_code)] - -struct Foo { - a: u16, - b: T -} - -trait Bar { - fn get(&self) -> usize; -} - -impl Bar for usize { - fn get(&self) -> usize { *self } -} - -struct Baz { - a: T -} - -struct HasDrop { - ptr: Box, - data: T -} - -fn main() { - // Test that zero-offset works properly - let b : Baz = Baz { a: 7 }; - assert_eq!(b.a.get(), 7); - let b : &Baz = &b; - assert_eq!(b.a.get(), 7); - - // Test that the field is aligned properly - let f : Foo = Foo { a: 0, b: 11 }; - assert_eq!(f.b.get(), 11); - let ptr1 : *const u8 = &f.b as *const _ as *const u8; - - let f : &Foo = &f; - let ptr2 : *const u8 = &f.b as *const _ as *const u8; - assert_eq!(f.b.get(), 11); - - // The pointers should be the same - assert_eq!(ptr1, ptr2); - - // Test that nested DSTs work properly - let f : Foo> = Foo { a: 0, b: Foo { a: 1, b: 17 }}; - assert_eq!(f.b.b.get(), 17); - let f : &Foo> = &f; - assert_eq!(f.b.b.get(), 17); - - // Test that get the pointer via destructuring works - - let f : Foo = Foo { a: 0, b: 11 }; - let f : &Foo = &f; - let &Foo { a: _, b: ref bar } = f; - assert_eq!(bar.get(), 11); - - // Make sure that drop flags don't screw things up - - let d : HasDrop> = HasDrop { - ptr: Box::new(0), - data: Baz { a: [1,2,3,4] } - }; - assert_eq!([1,2,3,4], d.data.a); - - let d : &HasDrop> = &d; - assert_eq!(&[1,2,3,4], &d.data.a); -} diff --git a/tests/run-pass/dst-irrefutable-bind.rs b/tests/run-pass/dst-irrefutable-bind.rs deleted file mode 100644 index 9f8067f372ae..000000000000 --- a/tests/run-pass/dst-irrefutable-bind.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Test(T); - -fn main() { - let x = Test([1,2,3]); - let x : &Test<[i32]> = &x; - - let & ref _y = x; - - // Make sure binding to a fat pointer behind a reference - // still works - let slice = &[1,2,3]; - let x = Test(&slice); - let Test(&_slice) = x; -} diff --git a/tests/run-pass/dst-raw.rs b/tests/run-pass/dst-raw.rs deleted file mode 100644 index 3a74626b0299..000000000000 --- a/tests/run-pass/dst-raw.rs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test DST raw pointers - - -trait Trait { - fn foo(&self) -> isize; -} - -struct A { - f: isize -} -impl Trait for A { - fn foo(&self) -> isize { - self.f - } -} - -struct Foo { - f: T -} - -pub fn main() { - // raw trait object - let x = A { f: 42 }; - let z: *const Trait = &x; - let r = unsafe { - (&*z).foo() - }; - assert_eq!(r, 42); - - // raw DST struct - let p = Foo {f: A { f: 42 }}; - let o: *const Foo = &p; - let r = unsafe { - (&*o).f.foo() - }; - assert_eq!(r, 42); - - // raw slice - let a: *const [_] = &[1, 2, 3]; - unsafe { - let b = (*a)[2]; - assert_eq!(b, 3); - let len = (*a).len(); - assert_eq!(len, 3); - } - - // raw slice with explicit cast - let a = &[1, 2, 3] as *const [i32]; - unsafe { - let b = (*a)[2]; - assert_eq!(b, 3); - let len = (*a).len(); - assert_eq!(len, 3); - } - - // raw DST struct with slice - let c: *const Foo<[_]> = &Foo {f: [1, 2, 3]}; - unsafe { - let b = (&*c).f[0]; - assert_eq!(b, 1); - let len = (&*c).f.len(); - assert_eq!(len, 3); - } - - // all of the above with *mut - let mut x = A { f: 42 }; - let z: *mut Trait = &mut x; - let r = unsafe { - (&*z).foo() - }; - assert_eq!(r, 42); - - let mut p = Foo {f: A { f: 42 }}; - let o: *mut Foo = &mut p; - let r = unsafe { - (&*o).f.foo() - }; - assert_eq!(r, 42); - - let a: *mut [_] = &mut [1, 2, 3]; - unsafe { - let b = (*a)[2]; - assert_eq!(b, 3); - let len = (*a).len(); - assert_eq!(len, 3); - } - - let a = &mut [1, 2, 3] as *mut [i32]; - unsafe { - let b = (*a)[2]; - assert_eq!(b, 3); - let len = (*a).len(); - assert_eq!(len, 3); - } - - let c: *mut Foo<[_]> = &mut Foo {f: [1, 2, 3]}; - unsafe { - let b = (&*c).f[0]; - assert_eq!(b, 1); - let len = (&*c).f.len(); - assert_eq!(len, 3); - } -} diff --git a/tests/run-pass/dst-struct-sole.rs b/tests/run-pass/dst-struct-sole.rs deleted file mode 100644 index 58d7b35a5275..000000000000 --- a/tests/run-pass/dst-struct-sole.rs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// As dst-struct.rs, but the unsized field is the only field in the struct. - - -struct Fat { - ptr: T -} - -// x is a fat pointer -fn foo(x: &Fat<[isize]>) { - let y = &x.ptr; - assert_eq!(x.ptr.len(), 3); - assert_eq!(y[0], 1); - assert_eq!(x.ptr[1], 2); -} - -fn foo2(x: &Fat<[T]>) { - let y = &x.ptr; - let bar = Bar; - assert_eq!(x.ptr.len(), 3); - assert_eq!(y[0].to_bar(), bar); - assert_eq!(x.ptr[1].to_bar(), bar); -} - -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -struct Bar; - -trait ToBar { - fn to_bar(&self) -> Bar; -} - -impl ToBar for Bar { - fn to_bar(&self) -> Bar { - *self - } -} - -pub fn main() { - // With a vec of ints. - let f1 = Fat { ptr: [1, 2, 3] }; - foo(&f1); - let f2 = &f1; - foo(f2); - let f3: &Fat<[isize]> = f2; - foo(f3); - let f4: &Fat<[isize]> = &f1; - foo(f4); - let f5: &Fat<[isize]> = &Fat { ptr: [1, 2, 3] }; - foo(f5); - - // With a vec of Bars. - let bar = Bar; - let f1 = Fat { ptr: [bar, bar, bar] }; - foo2(&f1); - let f2 = &f1; - foo2(f2); - let f3: &Fat<[Bar]> = f2; - foo2(f3); - let f4: &Fat<[Bar]> = &f1; - foo2(f4); - let f5: &Fat<[Bar]> = &Fat { ptr: [bar, bar, bar] }; - foo2(f5); - - // Assignment. - let f5: &mut Fat<[isize]> = &mut Fat { ptr: [1, 2, 3] }; - f5.ptr[1] = 34; - assert_eq!(f5.ptr[0], 1); - assert_eq!(f5.ptr[1], 34); - assert_eq!(f5.ptr[2], 3); - - // Zero size vec. - let f5: &Fat<[isize]> = &Fat { ptr: [] }; - assert!(f5.ptr.is_empty()); - let f5: &Fat<[Bar]> = &Fat { ptr: [] }; - assert!(f5.ptr.is_empty()); -} diff --git a/tests/run-pass/dst-struct.rs b/tests/run-pass/dst-struct.rs deleted file mode 100644 index 932b571eccdb..000000000000 --- a/tests/run-pass/dst-struct.rs +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#![allow(unused_features)] -#![feature(box_syntax)] - -struct Fat { - f1: isize, - f2: &'static str, - ptr: T -} - -// x is a fat pointer -fn foo(x: &Fat<[isize]>) { - let y = &x.ptr; - assert_eq!(x.ptr.len(), 3); - assert_eq!(y[0], 1); - assert_eq!(x.ptr[1], 2); - assert_eq!(x.f1, 5); - assert_eq!(x.f2, "some str"); -} - -fn foo2(x: &Fat<[T]>) { - let y = &x.ptr; - let bar = Bar; - assert_eq!(x.ptr.len(), 3); - assert_eq!(y[0].to_bar(), bar); - assert_eq!(x.ptr[1].to_bar(), bar); - assert_eq!(x.f1, 5); - assert_eq!(x.f2, "some str"); -} - -fn foo3(x: &Fat>) { - let y = &x.ptr.ptr; - assert_eq!(x.f1, 5); - assert_eq!(x.f2, "some str"); - assert_eq!(x.ptr.f1, 8); - assert_eq!(x.ptr.f2, "deep str"); - assert_eq!(x.ptr.ptr.len(), 3); - assert_eq!(y[0], 1); - assert_eq!(x.ptr.ptr[1], 2); -} - - -#[derive(Copy, Clone, PartialEq, Eq, Debug)] -struct Bar; - -trait ToBar { - fn to_bar(&self) -> Bar; -} - -impl ToBar for Bar { - fn to_bar(&self) -> Bar { - *self - } -} - -pub fn main() { - // With a vec of ints. - let f1 = Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }; - foo(&f1); - let f2 = &f1; - foo(f2); - let f3: &Fat<[isize]> = f2; - foo(f3); - let f4: &Fat<[isize]> = &f1; - foo(f4); - let f5: &Fat<[isize]> = &Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }; - foo(f5); - - // With a vec of Bars. - let bar = Bar; - let f1 = Fat { f1: 5, f2: "some str", ptr: [bar, bar, bar] }; - foo2(&f1); - let f2 = &f1; - foo2(f2); - let f3: &Fat<[Bar]> = f2; - foo2(f3); - let f4: &Fat<[Bar]> = &f1; - foo2(f4); - let f5: &Fat<[Bar]> = &Fat { f1: 5, f2: "some str", ptr: [bar, bar, bar] }; - foo2(f5); - - // Assignment. - let f5: &mut Fat<[isize]> = &mut Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }; - f5.ptr[1] = 34; - assert_eq!(f5.ptr[0], 1); - assert_eq!(f5.ptr[1], 34); - assert_eq!(f5.ptr[2], 3); - - // Zero size vec. - let f5: &Fat<[isize]> = &Fat { f1: 5, f2: "some str", ptr: [] }; - assert!(f5.ptr.is_empty()); - let f5: &Fat<[Bar]> = &Fat { f1: 5, f2: "some str", ptr: [] }; - assert!(f5.ptr.is_empty()); - - // Deeply nested. - let f1 = Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: [1, 2, 3]} }; - foo3(&f1); - let f2 = &f1; - foo3(f2); - let f3: &Fat> = f2; - foo3(f3); - let f4: &Fat> = &f1; - foo3(f4); - let f5: &Fat> = - &Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: [1, 2, 3]} }; - foo3(f5); - - // Box. - let f1 = Box::new([1, 2, 3]); - assert_eq!((*f1)[1], 2); - let f2: Box<[isize]> = f1; - assert_eq!((*f2)[1], 2); - - // Nested Box. - let f1 : Box> = box Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }; - foo(&*f1); - let f2 : Box> = f1; - foo(&*f2); - - // FIXME (#22405): Replace `Box::new` with `box` here when/if possible. - let f3 : Box> = - Box::>::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] }); - foo(&*f3); -} diff --git a/tests/run-pass/enum-nullable-const-null-with-fields.rs b/tests/run-pass/enum-nullable-const-null-with-fields.rs deleted file mode 100644 index 1342c4e104de..000000000000 --- a/tests/run-pass/enum-nullable-const-null-with-fields.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -use std::result::Result; -use std::result::Result::Ok; - -static C: Result<(), Box> = Ok(()); - -// This is because of yet another bad assertion (ICE) about the null side of a nullable enum. -// So we won't actually compile if the bug is present, but we check the value in main anyway. - -pub fn main() { - assert!(C.is_ok()); -} diff --git a/tests/run-pass/enums.rs b/tests/run-pass/enums.rs deleted file mode 100644 index 1f27292904f4..000000000000 --- a/tests/run-pass/enums.rs +++ /dev/null @@ -1,34 +0,0 @@ -enum MyEnum { - MyEmptyVariant, - MyNewtypeVariant(i32), - MyTupleVariant(i32, i32), - MyStructVariant { - my_first_field: i32, - my_second_field: i32, - } -} - -fn test(me: MyEnum) { - match me { - MyEnum::MyEmptyVariant => {}, - MyEnum::MyNewtypeVariant(ref val) => assert_eq!(val, &42), - MyEnum::MyTupleVariant(ref a, ref b) => { - assert_eq!(a, &43); - assert_eq!(b, &44); - }, - MyEnum::MyStructVariant { ref my_first_field, ref my_second_field } => { - assert_eq!(my_first_field, &45); - assert_eq!(my_second_field, &46); - }, - } -} - -fn main() { - test(MyEnum::MyEmptyVariant); - test(MyEnum::MyNewtypeVariant(42)); - test(MyEnum::MyTupleVariant(43, 44)); - test(MyEnum::MyStructVariant{ - my_first_field: 45, - my_second_field: 46, - }); -} diff --git a/tests/run-pass/float_fast_math.rs b/tests/run-pass/float_fast_math.rs deleted file mode 100644 index c1b4b55bd372..000000000000 --- a/tests/run-pass/float_fast_math.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(core_intrinsics)] - -use std::intrinsics::{fadd_fast, fsub_fast, fmul_fast, fdiv_fast, frem_fast}; - -#[inline(never)] -pub fn test_operations(a: f64, b: f64) { - // make sure they all map to the correct operation - unsafe { - assert_eq!(fadd_fast(a, b), a + b); - assert_eq!(fsub_fast(a, b), a - b); - assert_eq!(fmul_fast(a, b), a * b); - assert_eq!(fdiv_fast(a, b), a / b); - assert_eq!(frem_fast(a, b), a % b); - } -} - -fn main() { - test_operations(1., 2.); - test_operations(10., 5.); -} diff --git a/tests/run-pass/floats.rs b/tests/run-pass/floats.rs deleted file mode 100644 index 9c4d0594d1c9..000000000000 --- a/tests/run-pass/floats.rs +++ /dev/null @@ -1,11 +0,0 @@ - -fn main() { - assert_eq!(6.0_f32*6.0_f32, 36.0_f32); - assert_eq!(6.0_f64*6.0_f64, 36.0_f64); - assert_eq!(-{5.0_f32}, -5.0_f32); - assert!((5.0_f32/0.0).is_infinite()); - assert!((-5.0_f32).sqrt().is_nan()); - let x: u64 = unsafe { std::mem::transmute(42.0_f64) }; - let y: f64 = unsafe { std::mem::transmute(x) }; - assert_eq!(y, 42.0_f64); -} diff --git a/tests/run-pass/fn_item_as_closure_trait_object.rs b/tests/run-pass/fn_item_as_closure_trait_object.rs deleted file mode 100644 index 799f97a4f6fd..000000000000 --- a/tests/run-pass/fn_item_as_closure_trait_object.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn foo() {} - -fn main() { - let f: &Fn() = &foo; - f(); -} diff --git a/tests/run-pass/fn_item_with_args_as_closure_trait_object.rs b/tests/run-pass/fn_item_with_args_as_closure_trait_object.rs deleted file mode 100644 index 79ece75c773b..000000000000 --- a/tests/run-pass/fn_item_with_args_as_closure_trait_object.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn foo(i: i32) { - assert_eq!(i, 42); -} - -fn main() { - let f: &Fn(i32) = &foo; - f(42); -} diff --git a/tests/run-pass/fn_item_with_multiple_args_as_closure_trait_object.rs b/tests/run-pass/fn_item_with_multiple_args_as_closure_trait_object.rs deleted file mode 100644 index f4b5b449aa58..000000000000 --- a/tests/run-pass/fn_item_with_multiple_args_as_closure_trait_object.rs +++ /dev/null @@ -1,18 +0,0 @@ -fn foo(i: i32, j: i32) { - assert_eq!(i, 42); - assert_eq!(j, 55); -} - -fn bar(i: i32, j: i32, k: f32) { - assert_eq!(i, 42); - assert_eq!(j, 55); - assert_eq!(k, 3.14159) -} - - -fn main() { - let f: &Fn(i32, i32) = &foo; - f(42, 55); - let f: &Fn(i32, i32, f32) = &bar; - f(42, 55, 3.14159); -} diff --git a/tests/run-pass/fn_ptr_as_closure_trait_object.rs b/tests/run-pass/fn_ptr_as_closure_trait_object.rs deleted file mode 100644 index 24ae1f35bb60..000000000000 --- a/tests/run-pass/fn_ptr_as_closure_trait_object.rs +++ /dev/null @@ -1,15 +0,0 @@ -fn foo() {} -fn bar(u: u32) { assert_eq!(u, 42); } -fn baa(u: u32, f: f32) { - assert_eq!(u, 42); - assert_eq!(f, 3.141); -} - -fn main() { - let f: &Fn() = &(foo as fn()); - f(); - let f: &Fn(u32) = &(bar as fn(u32)); - f(42); - let f: &Fn(u32, f32) = &(baa as fn(u32, f32)); - f(42, 3.141); -} diff --git a/tests/run-pass/function_pointers.rs b/tests/run-pass/function_pointers.rs deleted file mode 100644 index 4f597d4a2e94..000000000000 --- a/tests/run-pass/function_pointers.rs +++ /dev/null @@ -1,46 +0,0 @@ -fn f() -> i32 { - 42 -} - -fn g(i: i32) -> i32 { - i*42 -} - -fn h(i: i32, j: i32) -> i32 { - j * i * 7 -} - -fn return_fn_ptr() -> fn() -> i32 { - f -} - -fn call_fn_ptr() -> i32 { - return_fn_ptr()() -} - -fn indirect i32>(f: F) -> i32 { f() } -fn indirect_mut i32>(mut f: F) -> i32 { f() } -fn indirect_once i32>(f: F) -> i32 { f() } - -fn indirect2 i32>(f: F) -> i32 { f(10) } -fn indirect_mut2 i32>(mut f: F) -> i32 { f(10) } -fn indirect_once2 i32>(f: F) -> i32 { f(10) } - -fn indirect3 i32>(f: F) -> i32 { f(10, 3) } -fn indirect_mut3 i32>(mut f: F) -> i32 { f(10, 3) } -fn indirect_once3 i32>(f: F) -> i32 { f(10, 3) } - -fn main() { - assert_eq!(call_fn_ptr(), 42); - assert_eq!(indirect(f), 42); - assert_eq!(indirect_mut(f), 42); - assert_eq!(indirect_once(f), 42); - assert_eq!(indirect2(g), 420); - assert_eq!(indirect_mut2(g), 420); - assert_eq!(indirect_once2(g), 420); - assert_eq!(indirect3(h), 210); - assert_eq!(indirect_mut3(h), 210); - assert_eq!(indirect_once3(h), 210); - assert!(return_fn_ptr() == f); - assert!(return_fn_ptr() as unsafe fn() -> i32 == f as fn() -> i32 as unsafe fn() -> i32); -} diff --git a/tests/run-pass/generator_control_flow.rs b/tests/run-pass/generator_control_flow.rs deleted file mode 100644 index f15c7db9c203..000000000000 --- a/tests/run-pass/generator_control_flow.rs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(generators, generator_trait)] - -use std::ops::{GeneratorState, Generator}; - -fn finish(mut amt: usize, mut t: T) -> T::Return - where T: Generator -{ - loop { - match t.resume() { - GeneratorState::Yielded(()) => amt -= 1, - GeneratorState::Complete(ret) => { - assert_eq!(amt, 0); - return ret - } - } - } - -} - -fn main() { - finish(1, || yield); - finish(3, || { - let mut x = 0; - yield; - x += 1; - yield; - x += 1; - yield; - assert_eq!(x, 2); - }); - finish(8, || { - for _ in 0..8 { - yield; - } - }); - finish(1, || { - if true { - yield; - } else { - } - }); - finish(1, || { - if false { - } else { - yield; - } - }); - finish(2, || { - if { yield; false } { - yield; - panic!() - } - yield - }); -} diff --git a/tests/run-pass/intrinsics-integer.rs b/tests/run-pass/intrinsics-integer.rs deleted file mode 100644 index 4896f02da20b..000000000000 --- a/tests/run-pass/intrinsics-integer.rs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(intrinsics)] - -mod rusti { - extern "rust-intrinsic" { - pub fn ctpop(x: T) -> T; - pub fn ctlz(x: T) -> T; - pub fn ctlz_nonzero(x: T) -> T; - pub fn cttz(x: T) -> T; - pub fn cttz_nonzero(x: T) -> T; - pub fn bswap(x: T) -> T; - } -} - -pub fn main() { - unsafe { - use rusti::*; - - assert_eq!(ctpop(0u8), 0); assert_eq!(ctpop(0i8), 0); - assert_eq!(ctpop(0u16), 0); assert_eq!(ctpop(0i16), 0); - assert_eq!(ctpop(0u32), 0); assert_eq!(ctpop(0i32), 0); - assert_eq!(ctpop(0u64), 0); assert_eq!(ctpop(0i64), 0); - - assert_eq!(ctpop(1u8), 1); assert_eq!(ctpop(1i8), 1); - assert_eq!(ctpop(1u16), 1); assert_eq!(ctpop(1i16), 1); - assert_eq!(ctpop(1u32), 1); assert_eq!(ctpop(1i32), 1); - assert_eq!(ctpop(1u64), 1); assert_eq!(ctpop(1i64), 1); - - assert_eq!(ctpop(10u8), 2); assert_eq!(ctpop(10i8), 2); - assert_eq!(ctpop(10u16), 2); assert_eq!(ctpop(10i16), 2); - assert_eq!(ctpop(10u32), 2); assert_eq!(ctpop(10i32), 2); - assert_eq!(ctpop(10u64), 2); assert_eq!(ctpop(10i64), 2); - - assert_eq!(ctpop(100u8), 3); assert_eq!(ctpop(100i8), 3); - assert_eq!(ctpop(100u16), 3); assert_eq!(ctpop(100i16), 3); - assert_eq!(ctpop(100u32), 3); assert_eq!(ctpop(100i32), 3); - assert_eq!(ctpop(100u64), 3); assert_eq!(ctpop(100i64), 3); - - assert_eq!(ctpop(-1i8 as u8), 8); assert_eq!(ctpop(-1i8), 8); - assert_eq!(ctpop(-1i16 as u16), 16); assert_eq!(ctpop(-1i16), 16); - assert_eq!(ctpop(-1i32 as u32), 32); assert_eq!(ctpop(-1i32), 32); - assert_eq!(ctpop(-1i64 as u64), 64); assert_eq!(ctpop(-1i64), 64); - - assert_eq!(ctlz(0u8), 8); assert_eq!(ctlz(0i8), 8); - assert_eq!(ctlz(0u16), 16); assert_eq!(ctlz(0i16), 16); - assert_eq!(ctlz(0u32), 32); assert_eq!(ctlz(0i32), 32); - assert_eq!(ctlz(0u64), 64); assert_eq!(ctlz(0i64), 64); - - assert_eq!(ctlz(1u8), 7); assert_eq!(ctlz(1i8), 7); - assert_eq!(ctlz(1u16), 15); assert_eq!(ctlz(1i16), 15); - assert_eq!(ctlz(1u32), 31); assert_eq!(ctlz(1i32), 31); - assert_eq!(ctlz(1u64), 63); assert_eq!(ctlz(1i64), 63); - - assert_eq!(ctlz(10u8), 4); assert_eq!(ctlz(10i8), 4); - assert_eq!(ctlz(10u16), 12); assert_eq!(ctlz(10i16), 12); - assert_eq!(ctlz(10u32), 28); assert_eq!(ctlz(10i32), 28); - assert_eq!(ctlz(10u64), 60); assert_eq!(ctlz(10i64), 60); - - assert_eq!(ctlz(100u8), 1); assert_eq!(ctlz(100i8), 1); - assert_eq!(ctlz(100u16), 9); assert_eq!(ctlz(100i16), 9); - assert_eq!(ctlz(100u32), 25); assert_eq!(ctlz(100i32), 25); - assert_eq!(ctlz(100u64), 57); assert_eq!(ctlz(100i64), 57); - - assert_eq!(ctlz_nonzero(1u8), 7); assert_eq!(ctlz_nonzero(1i8), 7); - assert_eq!(ctlz_nonzero(1u16), 15); assert_eq!(ctlz_nonzero(1i16), 15); - assert_eq!(ctlz_nonzero(1u32), 31); assert_eq!(ctlz_nonzero(1i32), 31); - assert_eq!(ctlz_nonzero(1u64), 63); assert_eq!(ctlz_nonzero(1i64), 63); - - assert_eq!(ctlz_nonzero(10u8), 4); assert_eq!(ctlz_nonzero(10i8), 4); - assert_eq!(ctlz_nonzero(10u16), 12); assert_eq!(ctlz_nonzero(10i16), 12); - assert_eq!(ctlz_nonzero(10u32), 28); assert_eq!(ctlz_nonzero(10i32), 28); - assert_eq!(ctlz_nonzero(10u64), 60); assert_eq!(ctlz_nonzero(10i64), 60); - - assert_eq!(ctlz_nonzero(100u8), 1); assert_eq!(ctlz_nonzero(100i8), 1); - assert_eq!(ctlz_nonzero(100u16), 9); assert_eq!(ctlz_nonzero(100i16), 9); - assert_eq!(ctlz_nonzero(100u32), 25); assert_eq!(ctlz_nonzero(100i32), 25); - assert_eq!(ctlz_nonzero(100u64), 57); assert_eq!(ctlz_nonzero(100i64), 57); - - assert_eq!(cttz(-1i8 as u8), 0); assert_eq!(cttz(-1i8), 0); - assert_eq!(cttz(-1i16 as u16), 0); assert_eq!(cttz(-1i16), 0); - assert_eq!(cttz(-1i32 as u32), 0); assert_eq!(cttz(-1i32), 0); - assert_eq!(cttz(-1i64 as u64), 0); assert_eq!(cttz(-1i64), 0); - - assert_eq!(cttz(0u8), 8); assert_eq!(cttz(0i8), 8); - assert_eq!(cttz(0u16), 16); assert_eq!(cttz(0i16), 16); - assert_eq!(cttz(0u32), 32); assert_eq!(cttz(0i32), 32); - assert_eq!(cttz(0u64), 64); assert_eq!(cttz(0i64), 64); - - assert_eq!(cttz(1u8), 0); assert_eq!(cttz(1i8), 0); - assert_eq!(cttz(1u16), 0); assert_eq!(cttz(1i16), 0); - assert_eq!(cttz(1u32), 0); assert_eq!(cttz(1i32), 0); - assert_eq!(cttz(1u64), 0); assert_eq!(cttz(1i64), 0); - - assert_eq!(cttz(10u8), 1); assert_eq!(cttz(10i8), 1); - assert_eq!(cttz(10u16), 1); assert_eq!(cttz(10i16), 1); - assert_eq!(cttz(10u32), 1); assert_eq!(cttz(10i32), 1); - assert_eq!(cttz(10u64), 1); assert_eq!(cttz(10i64), 1); - - assert_eq!(cttz(100u8), 2); assert_eq!(cttz(100i8), 2); - assert_eq!(cttz(100u16), 2); assert_eq!(cttz(100i16), 2); - assert_eq!(cttz(100u32), 2); assert_eq!(cttz(100i32), 2); - assert_eq!(cttz(100u64), 2); assert_eq!(cttz(100i64), 2); - - assert_eq!(cttz_nonzero(-1i8 as u8), 0); assert_eq!(cttz_nonzero(-1i8), 0); - assert_eq!(cttz_nonzero(-1i16 as u16), 0); assert_eq!(cttz_nonzero(-1i16), 0); - assert_eq!(cttz_nonzero(-1i32 as u32), 0); assert_eq!(cttz_nonzero(-1i32), 0); - assert_eq!(cttz_nonzero(-1i64 as u64), 0); assert_eq!(cttz_nonzero(-1i64), 0); - - assert_eq!(cttz_nonzero(1u8), 0); assert_eq!(cttz_nonzero(1i8), 0); - assert_eq!(cttz_nonzero(1u16), 0); assert_eq!(cttz_nonzero(1i16), 0); - assert_eq!(cttz_nonzero(1u32), 0); assert_eq!(cttz_nonzero(1i32), 0); - assert_eq!(cttz_nonzero(1u64), 0); assert_eq!(cttz_nonzero(1i64), 0); - - assert_eq!(cttz_nonzero(10u8), 1); assert_eq!(cttz_nonzero(10i8), 1); - assert_eq!(cttz_nonzero(10u16), 1); assert_eq!(cttz_nonzero(10i16), 1); - assert_eq!(cttz_nonzero(10u32), 1); assert_eq!(cttz_nonzero(10i32), 1); - assert_eq!(cttz_nonzero(10u64), 1); assert_eq!(cttz_nonzero(10i64), 1); - - assert_eq!(cttz_nonzero(100u8), 2); assert_eq!(cttz_nonzero(100i8), 2); - assert_eq!(cttz_nonzero(100u16), 2); assert_eq!(cttz_nonzero(100i16), 2); - assert_eq!(cttz_nonzero(100u32), 2); assert_eq!(cttz_nonzero(100i32), 2); - assert_eq!(cttz_nonzero(100u64), 2); assert_eq!(cttz_nonzero(100i64), 2); - - assert_eq!(bswap(0x0Au8), 0x0A); // no-op - assert_eq!(bswap(0x0Ai8), 0x0A); // no-op - assert_eq!(bswap(0x0A0Bu16), 0x0B0A); - assert_eq!(bswap(0x0A0Bi16), 0x0B0A); - assert_eq!(bswap(0x0ABBCC0Du32), 0x0DCCBB0A); - assert_eq!(bswap(0x0ABBCC0Di32), 0x0DCCBB0A); - assert_eq!(bswap(0x0122334455667708u64), 0x0877665544332201); - assert_eq!(bswap(0x0122334455667708i64), 0x0877665544332201); - } -} diff --git a/tests/run-pass/intrinsics-math.rs b/tests/run-pass/intrinsics-math.rs deleted file mode 100644 index a2c55634749c..000000000000 --- a/tests/run-pass/intrinsics-math.rs +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -macro_rules! assert_approx_eq { - ($a:expr, $b:expr) => ({ - let (a, b) = (&$a, &$b); - assert!((*a - *b).abs() < 1.0e-6, - "{} is not approximately equal to {}", *a, *b); - }) -} - -pub fn main() { - use std::f32; - use std::f64; - - assert_approx_eq!(64f32.sqrt(), 8f32); - assert_approx_eq!(64f64.sqrt(), 8f64); - - assert_approx_eq!(25f32.powi(-2), 0.0016f32); - assert_approx_eq!(23.2f64.powi(2), 538.24f64); - - assert_approx_eq!(0f32.sin(), 0f32); - assert_approx_eq!((f64::consts::PI / 2f64).sin(), 1f64); - - assert_approx_eq!(0f32.cos(), 1f32); - assert_approx_eq!((f64::consts::PI * 2f64).cos(), 1f64); - - assert_approx_eq!(25f32.powf(-2f32), 0.0016f32); - assert_approx_eq!(400f64.powf(0.5f64), 20f64); - - assert_approx_eq!((1f32.exp() - f32::consts::E).abs(), 0f32); - assert_approx_eq!(1f64.exp(), f64::consts::E); - - assert_approx_eq!(10f32.exp2(), 1024f32); - assert_approx_eq!(50f64.exp2(), 1125899906842624f64); - - assert_approx_eq!((f32::consts::E.ln() - 1f32).abs(), 0f32); - assert_approx_eq!(1f64.ln(), 0f64); - - assert_approx_eq!(10f32.log10(), 1f32); - assert_approx_eq!(f64::consts::E.log10(), f64::consts::LOG10_E); - - assert_approx_eq!(8f32.log2(), 3f32); - assert_approx_eq!(f64::consts::E.log2(), f64::consts::LOG2_E); - - assert_approx_eq!(1.0f32.mul_add(2.0f32, 5.0f32), 7.0f32); - assert_approx_eq!(0.0f64.mul_add(-2.0f64, f64::consts::E), f64::consts::E); - - assert_approx_eq!((-1.0f32).abs(), 1.0f32); - assert_approx_eq!(34.2f64.abs(), 34.2f64); - - assert_approx_eq!(3.8f32.floor(), 3.0f32); - assert_approx_eq!((-1.1f64).floor(), -2.0f64); - - assert_approx_eq!((-2.3f32).ceil(), -2.0f32); - assert_approx_eq!(3.8f64.ceil(), 4.0f64); - - assert_approx_eq!(0.1f32.trunc(), 0.0f32); - assert_approx_eq!((-0.1f64).trunc(), 0.0f64); -} diff --git a/tests/run-pass/intrinsics.rs b/tests/run-pass/intrinsics.rs deleted file mode 100755 index 3152737a601c..000000000000 --- a/tests/run-pass/intrinsics.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::mem::{size_of, size_of_val}; - -fn main() { - assert_eq!(size_of::>(), 8); - assert_eq!(size_of_val(&()), 0); - assert_eq!(size_of_val(&42), 4); - assert_eq!(size_of_val(&[] as &[i32]), 0); - assert_eq!(size_of_val(&[1, 2, 3] as &[i32]), 12); - assert_eq!(size_of_val("foobar"), 6); -} diff --git a/tests/run-pass/ints.rs b/tests/run-pass/ints.rs deleted file mode 100644 index 4f23b5ec9c38..000000000000 --- a/tests/run-pass/ints.rs +++ /dev/null @@ -1,58 +0,0 @@ -fn ret() -> i64 { - 1 -} - -fn neg() -> i64 { - -1 -} - -fn add() -> i64 { - 1 + 2 -} - -fn indirect_add() -> i64 { - let x = 1; - let y = 2; - x + y -} - -fn arith() -> i32 { - 3*3 + 4*4 -} - -fn match_int() -> i16 { - let n = 2; - match n { - 0 => 0, - 1 => 10, - 2 => 20, - 3 => 30, - _ => 100, - } -} - -fn match_int_range() -> i64 { - let n = 42; - match n { - 0...9 => 0, - 10...19 => 1, - 20...29 => 2, - 30...39 => 3, - 40...49 => 4, - _ => 5, - } -} - -fn main() { - assert_eq!(ret(), 1); - assert_eq!(neg(), -1); - assert_eq!(add(), 3); - assert_eq!(indirect_add(), 3); - assert_eq!(arith(), 5*5); - assert_eq!(match_int(), 20); - assert_eq!(match_int_range(), 4); - assert_eq!(i64::min_value().overflowing_mul(-1), (i64::min_value(), true)); - assert_eq!(i32::min_value().overflowing_mul(-1), (i32::min_value(), true)); - assert_eq!(i16::min_value().overflowing_mul(-1), (i16::min_value(), true)); - assert_eq!(i8::min_value().overflowing_mul(-1), (i8::min_value(), true)); -} diff --git a/tests/run-pass/issue-15063.rs b/tests/run-pass/issue-15063.rs deleted file mode 100644 index 726aee283e29..000000000000 --- a/tests/run-pass/issue-15063.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(dead_code)] - -enum Two { A, B } -impl Drop for Two { - fn drop(&mut self) { - } -} -fn main() { - let _k = Two::A; -} diff --git a/tests/run-pass/issue-15523-big.rs b/tests/run-pass/issue-15523-big.rs deleted file mode 100644 index 33c81cab3817..000000000000 --- a/tests/run-pass/issue-15523-big.rs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Issue 15523: derive(PartialOrd) should use the provided -// discriminant values for the derived ordering. -// -// This test is checking corner cases that arise when you have -// 64-bit values in the variants. - -#[derive(PartialEq, PartialOrd)] -#[repr(u64)] -enum Eu64 { - Pos2 = 2, - PosMax = !0, - Pos1 = 1, -} - -#[derive(PartialEq, PartialOrd)] -#[repr(i64)] -enum Ei64 { - Pos2 = 2, - Neg1 = -1, - NegMin = 1 << 63, - PosMax = !(1 << 63), - Pos1 = 1, -} - -fn main() { - assert!(Eu64::Pos2 > Eu64::Pos1); - assert!(Eu64::Pos2 < Eu64::PosMax); - assert!(Eu64::Pos1 < Eu64::PosMax); - - - assert!(Ei64::Pos2 > Ei64::Pos1); - assert!(Ei64::Pos2 > Ei64::Neg1); - assert!(Ei64::Pos1 > Ei64::Neg1); - assert!(Ei64::Pos2 > Ei64::NegMin); - assert!(Ei64::Pos1 > Ei64::NegMin); - assert!(Ei64::Pos2 < Ei64::PosMax); - assert!(Ei64::Pos1 < Ei64::PosMax); -} diff --git a/tests/run-pass/issue-17877.rs b/tests/run-pass/issue-17877.rs deleted file mode 100644 index b4b74b9905fb..000000000000 --- a/tests/run-pass/issue-17877.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-msvc - -#![feature(slice_patterns)] - -fn main() { - assert_eq!(match [0u8; 1024] { - _ => 42_usize, - }, 42_usize); - - assert_eq!(match [0u8; 1024] { - [1, _..] => 0_usize, - [0, _..] => 1_usize, - _ => 2_usize - }, 1_usize); -} diff --git a/tests/run-pass/issue-20575.rs b/tests/run-pass/issue-20575.rs deleted file mode 100644 index 7db7e3b28e8e..000000000000 --- a/tests/run-pass/issue-20575.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that overloaded calls work with zero arity closures - -// pretty-expanded FIXME #23616 - -fn main() { - let functions: [Box Option<()>>; 1] = [Box::new(|| None)]; - - let _: Option> = functions.iter().map(|f| (*f)()).collect(); -} diff --git a/tests/run-pass/issue-23261.rs b/tests/run-pass/issue-23261.rs deleted file mode 100644 index fc806f5429a4..000000000000 --- a/tests/run-pass/issue-23261.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Matching on a DST struct should not trigger an LLVM assertion. - -struct Foo { - a: i32, - inner: T -} - -trait Get { - fn get(&self) -> i32; -} - -impl Get for i32 { - fn get(&self) -> i32 { - *self - } -} - -fn check_val(val: &Foo<[u8]>) { - match *val { - Foo { a, .. } => { - assert_eq!(a, 32); - } - } -} - -fn check_dst_val(val: &Foo<[u8]>) { - match *val { - Foo { ref inner, .. } => { - assert_eq!(inner, [1, 2, 3]); - } - } -} - -fn check_both(val: &Foo<[u8]>) { - match *val { - Foo { a, ref inner } => { - assert_eq!(a, 32); - assert_eq!(inner, [1, 2, 3]); - } - } -} - -fn check_trait_obj(val: &Foo) { - match *val { - Foo { a, ref inner } => { - assert_eq!(a, 32); - assert_eq!(inner.get(), 32); - } - } -} - -fn main() { - let foo: &Foo<[u8]> = &Foo { a: 32, inner: [1, 2, 3] }; - check_val(foo); - check_dst_val(foo); - check_both(foo); - - let foo: &Foo = &Foo { a: 32, inner: 32 }; - check_trait_obj(foo); -} diff --git a/tests/run-pass/issue-26709.rs b/tests/run-pass/issue-26709.rs deleted file mode 100644 index 62626d75865c..000000000000 --- a/tests/run-pass/issue-26709.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct Wrapper<'a, T: ?Sized>(&'a mut i32, T); - -impl<'a, T: ?Sized> Drop for Wrapper<'a, T> { - fn drop(&mut self) { - *self.0 = 432; - } -} - -fn main() { - let mut x = 0; - { - let wrapper = Box::new(Wrapper(&mut x, 123)); - let _: Box> = wrapper; - } - assert_eq!(432, x) -} diff --git a/tests/run-pass/issue-27901.rs b/tests/run-pass/issue-27901.rs deleted file mode 100644 index b7a9daaf8abd..000000000000 --- a/tests/run-pass/issue-27901.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -trait Stream { type Item; } -impl<'a> Stream for &'a str { type Item = u8; } -fn f<'s>(s: &'s str) -> (&'s str, <&'s str as Stream>::Item) { - (s, 42) -} - -fn main() { - let fx = f as for<'t> fn(&'t str) -> (&'t str, <&'t str as Stream>::Item); - assert_eq!(fx("hi"), ("hi", 42)); -} diff --git a/tests/run-pass/issue-29746.rs b/tests/run-pass/issue-29746.rs deleted file mode 100644 index 61c601ac6a90..000000000000 --- a/tests/run-pass/issue-29746.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// zip!(a1,a2,a3,a4) is equivalent to: -// a1.zip(a2).zip(a3).zip(a4).map(|(((x1,x2),x3),x4)| (x1,x2,x3,x4)) -macro_rules! zip { - // Entry point - ([$a:expr, $b:expr, $($rest:expr),*]) => { - zip!([$($rest),*], $a.zip($b), (x,y), [x,y]) - }; - - // Intermediate steps to build the zipped expression, the match pattern, and - // and the output tuple of the closure, using macro hygene to repeatedly - // introduce new variables named 'x'. - ([$a:expr, $($rest:expr),*], $zip:expr, $pat:pat, [$($flat:expr),*]) => { - zip!([$($rest),*], $zip.zip($a), ($pat,x), [$($flat),*, x]) - }; - - // Final step - ([], $zip:expr, $pat:pat, [$($flat:expr),+]) => { - $zip.map(|$pat| ($($flat),+)) - }; - - // Comma - ([$a:expr], $zip:expr, $pat:pat, [$($flat:expr),*]) => { - zip!([$a,], $zip, $pat, [$($flat),*]) - }; -} - -fn main() { - let p1 = vec![1i32, 2].into_iter(); - let p2 = vec!["10", "20"].into_iter(); - let p3 = vec![100u16, 200].into_iter(); - let p4 = vec![1000i64, 2000].into_iter(); - - let e = zip!([p1,p2,p3,p4]).collect::>(); - assert_eq!(e[0], (1i32,"10",100u16,1000i64)); -} diff --git a/tests/run-pass/issue-30530.rs b/tests/run-pass/issue-30530.rs deleted file mode 100644 index d5139c908bda..000000000000 --- a/tests/run-pass/issue-30530.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2012-2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Regression test for Issue #30530: alloca's created for storing -// intermediate scratch values during brace-less match arms need to be -// initialized with their drop-flag set to "dropped" (or else we end -// up running the destructors on garbage data at the end of the -// function). - -pub enum Handler { - Default, - #[allow(dead_code)] - Custom(*mut Box), -} - -fn main() { - take(Handler::Default, Box::new(main)); -} - -#[inline(never)] -pub fn take(h: Handler, f: Box) -> Box { - unsafe { - match h { - Handler::Custom(ptr) => *Box::from_raw(ptr), - Handler::Default => f, - } - } -} diff --git a/tests/run-pass/issue-31267-additional.rs b/tests/run-pass/issue-31267-additional.rs deleted file mode 100644 index 14e38f43c527..000000000000 --- a/tests/run-pass/issue-31267-additional.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(unused_variables)] - -#[derive(Clone, Copy, Debug)] -struct Bar; - -const BAZ: Bar = Bar; - -#[derive(Debug)] -struct Foo([Bar; 1]); - -struct Biz; - -impl Biz { - const BAZ: Foo = Foo([BAZ; 1]); -} - -fn main() { - let foo = Biz::BAZ; -} diff --git a/tests/run-pass/issue-33387.rs b/tests/run-pass/issue-33387.rs deleted file mode 100644 index edbf2b81ce94..000000000000 --- a/tests/run-pass/issue-33387.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::sync::Arc; - -trait Foo {} - -impl Foo for [u8; 2] {} - -fn main() { - let _: Arc = Arc::new([3, 4]); -} diff --git a/tests/run-pass/issue-34571.rs b/tests/run-pass/issue-34571.rs deleted file mode 100644 index 7d8041565765..000000000000 --- a/tests/run-pass/issue-34571.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2017 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[repr(u8)] -enum Foo { - Foo(u8), -} - -fn main() { - match Foo::Foo(1) { - _ => () - } -} diff --git a/tests/run-pass/issue-35815.rs b/tests/run-pass/issue-35815.rs deleted file mode 100644 index 216e06c0732c..000000000000 --- a/tests/run-pass/issue-35815.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(dead_code)] - -use std::mem; - -struct Foo { - a: i64, - b: bool, - c: T, -} - -fn main() { - let foo: &Foo = &Foo { a: 1, b: false, c: 2i32 }; - let foo_unsized: &Foo = foo; - assert_eq!(mem::size_of_val(foo), mem::size_of_val(foo_unsized)); -} diff --git a/tests/run-pass/issue-36278-prefix-nesting.rs b/tests/run-pass/issue-36278-prefix-nesting.rs deleted file mode 100644 index 95269d0569de..000000000000 --- a/tests/run-pass/issue-36278-prefix-nesting.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Issue 36278: On an unsized struct with >1 level of nontrivial -// nesting, ensure we are computing dynamic size of prefix correctly. - -use std::mem; - -const SZ: usize = 100; -struct P([u8; SZ], T); - -type Ack = P>; - -fn main() { - let size_of_sized; let size_of_unsized; - let x: Box> = Box::new(P([0; SZ], P([0; SZ], [0; 0]))); - size_of_sized = mem::size_of_val::>(&x); - let y: Box> = x; - size_of_unsized = mem::size_of_val::>(&y); - assert_eq!(size_of_sized, size_of_unsized); -} diff --git a/tests/run-pass/issue-5917.rs b/tests/run-pass/issue-5917.rs deleted file mode 100644 index 69b95f2cd7e1..000000000000 --- a/tests/run-pass/issue-5917.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -struct T (&'static [isize]); -static STATIC : T = T (&[5, 4, 3]); -pub fn main () { - let T(ref v) = STATIC; - assert_eq!(v[0], 5); -} diff --git a/tests/run-pass/issue-miri-184.rs b/tests/run-pass/issue-miri-184.rs deleted file mode 100644 index 24775fe8a2d9..000000000000 --- a/tests/run-pass/issue-miri-184.rs +++ /dev/null @@ -1,4 +0,0 @@ -pub fn main() { - let bytes: [u8; 8] = unsafe { ::std::mem::transmute(0u64) }; - let _: &[u8] = &bytes; -} diff --git a/tests/run-pass/iter_slice.rs b/tests/run-pass/iter_slice.rs deleted file mode 100644 index fd7229c3455e..000000000000 --- a/tests/run-pass/iter_slice.rs +++ /dev/null @@ -1,12 +0,0 @@ -fn main() { - for _ in Vec::::new().iter() { // this iterates over a Unique::empty() - panic!("We should never be here."); - } - - // Iterate over a ZST (uses arith_offset internally) - let mut count = 0; - for _ in &[(), (), ()] { - count += 1; - } - assert_eq!(count, 3); -} diff --git a/tests/run-pass/last-use-in-cap-clause.rs b/tests/run-pass/last-use-in-cap-clause.rs deleted file mode 100644 index de2d815ca54e..000000000000 --- a/tests/run-pass/last-use-in-cap-clause.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Make sure #1399 stays fixed - -#[allow(dead_code)] -struct A { a: Box } - -fn foo() -> Box isize + 'static> { - let k: Box<_> = Box::new(22); - let _u = A {a: k.clone()}; - let result = || 22; - Box::new(result) -} - -pub fn main() { - assert_eq!(foo()(), 22); -} diff --git a/tests/run-pass/loops.rs b/tests/run-pass/loops.rs deleted file mode 100644 index 222287cbe09a..000000000000 --- a/tests/run-pass/loops.rs +++ /dev/null @@ -1,35 +0,0 @@ -fn factorial_loop() -> i64 { - let mut product = 1; - let mut i = 1; - - while i <= 10 { - product *= i; - i += 1; - } - - product -} - -fn index_for_loop() -> usize { - let mut sum = 0; - let a = [0, 10, 20, 30]; - for i in 0..a.len() { - sum += a[i]; - } - sum -} - -fn for_loop() -> usize { - let mut sum = 0; - let a = [0, 10, 20, 30]; - for &n in &a { - sum += n; - } - sum -} - -fn main() { - assert_eq!(factorial_loop(), 3628800); - assert_eq!(index_for_loop(), 60); - assert_eq!(for_loop(), 60); -} diff --git a/tests/run-pass/main_fn.rs b/tests/run-pass/main_fn.rs deleted file mode 100644 index 91d183ee6af7..000000000000 --- a/tests/run-pass/main_fn.rs +++ /dev/null @@ -1,5 +0,0 @@ -#![feature(main)] - -#[main] -fn foo() { -} diff --git a/tests/run-pass/many_shr_bor.rs b/tests/run-pass/many_shr_bor.rs deleted file mode 100644 index 393bafebfe4d..000000000000 --- a/tests/run-pass/many_shr_bor.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Make sure validation can handle many overlapping shared borrows for different parts of a data structure -#![allow(unused_variables)] -use std::cell::RefCell; - -struct Test { - a: u32, - b: u32, -} - -fn test1() { - let t = &mut Test { a: 0, b: 0 }; - { - let x; - { - let y = &t.a; - x = &t; - let _y = *y; - } - let _x = x.a; - } - t.b = 42; -} - -fn test2(r: &mut RefCell) { - let x = &*r; // releasing write lock, first suspension recorded - let mut x_ref = x.borrow_mut(); - let x_inner : &mut i32 = &mut *x_ref; // new inner write lock, with same lifetime as outer lock - let x_inner_shr = &*x_inner; // releasing inner write lock, recording suspension - let y = &*r; // second suspension for the outer write lock - let x_inner_shr2 = &*x_inner; // 2nd suspension for inner write lock -} - -fn main() { - test1(); - test2(&mut RefCell::new(0)); -} diff --git a/tests/run-pass/match_slice.rs b/tests/run-pass/match_slice.rs deleted file mode 100644 index 568a1a1c8818..000000000000 --- a/tests/run-pass/match_slice.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - let x = "hello"; - match x { - "foo" => {}, - "bar" => {}, - _ => {}, - } -} diff --git a/tests/run-pass/mir_coercions.rs b/tests/run-pass/mir_coercions.rs deleted file mode 100644 index 36155297e32f..000000000000 --- a/tests/run-pass/mir_coercions.rs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(coerce_unsized, unsize)] - -use std::ops::CoerceUnsized; -use std::marker::Unsize; - -fn identity_coercion(x: &(Fn(u32)->u32 + Send)) -> &Fn(u32)->u32 { - x -} -fn fn_coercions(f: &fn(u32) -> u32) -> - (unsafe fn(u32) -> u32, - &(Fn(u32) -> u32+Send)) -{ - (*f, f) -} - -fn simple_array_coercion(x: &[u8; 3]) -> &[u8] { x } - -fn square(a: u32) -> u32 { a * a } - -#[derive(PartialEq,Eq)] -struct PtrWrapper<'a, T: 'a+?Sized>(u32, u32, (), &'a T); -impl<'a, T: ?Sized+Unsize, U: ?Sized> - CoerceUnsized> for PtrWrapper<'a, T> {} - -struct TrivPtrWrapper<'a, T: 'a+?Sized>(&'a T); -impl<'a, T: ?Sized+Unsize, U: ?Sized> - CoerceUnsized> for TrivPtrWrapper<'a, T> {} - -fn coerce_ptr_wrapper(p: PtrWrapper<[u8; 3]>) -> PtrWrapper<[u8]> { - p -} - -fn coerce_triv_ptr_wrapper(p: TrivPtrWrapper<[u8; 3]>) -> TrivPtrWrapper<[u8]> { - p -} - -fn coerce_fat_ptr_wrapper(p: PtrWrapper u32+Send>) - -> PtrWrapper u32> { - p -} - -fn coerce_ptr_wrapper_poly<'a, T, Trait: ?Sized>(p: PtrWrapper<'a, T>) - -> PtrWrapper<'a, Trait> - where PtrWrapper<'a, T>: CoerceUnsized> -{ - p -} - -fn main() { - let a = [0,1,2]; - let square_local : fn(u32) -> u32 = square; - let (f,g) = fn_coercions(&square_local); - assert_eq!(f as *const (), square as *const()); - assert_eq!(g(4), 16); - assert_eq!(identity_coercion(g)(5), 25); - - assert_eq!(simple_array_coercion(&a), &a); - let w = coerce_ptr_wrapper(PtrWrapper(2,3,(),&a)); - assert!(w == PtrWrapper(2,3,(),&a) as PtrWrapper<[u8]>); - - let w = coerce_triv_ptr_wrapper(TrivPtrWrapper(&a)); - assert_eq!(&w.0, &a); - - let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local)); - assert_eq!((z.3)(6), 36); - - let z: PtrWrapper u32> = - coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local)); - assert_eq!((z.3)(6), 36); -} diff --git a/tests/run-pass/mir_fat_ptr.rs b/tests/run-pass/mir_fat_ptr.rs deleted file mode 100644 index e5c9e3577d1c..000000000000 --- a/tests/run-pass/mir_fat_ptr.rs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// test that ordinary fat pointer operations work. - -struct Wrapper(u32, T); - -struct FatPtrContainer<'a> { - ptr: &'a [u8] -} - -fn fat_ptr_project(a: &Wrapper<[u8]>) -> &[u8] { - &a.1 -} - -fn fat_ptr_simple(a: &[u8]) -> &[u8] { - a -} - -fn fat_ptr_via_local(a: &[u8]) -> &[u8] { - let x = a; - x -} - -fn fat_ptr_from_struct(s: FatPtrContainer) -> &[u8] { - s.ptr -} - -fn fat_ptr_to_struct(a: &[u8]) -> FatPtrContainer { - FatPtrContainer { ptr: a } -} - -fn fat_ptr_store_to<'a>(a: &'a [u8], b: &mut &'a [u8]) { - *b = a; -} - -fn fat_ptr_constant() -> &'static str { - "HELLO" -} - -fn main() { - let a = Wrapper(4, [7,6,5]); - - let p = fat_ptr_project(&a); - let p = fat_ptr_simple(p); - let p = fat_ptr_via_local(p); - let p = fat_ptr_from_struct(fat_ptr_to_struct(p)); - - let mut target : &[u8] = &[42]; - fat_ptr_store_to(p, &mut target); - assert_eq!(target, &a.1); - - assert_eq!(fat_ptr_constant(), "HELLO"); -} diff --git a/tests/run-pass/miri-issue-133.rs b/tests/run-pass/miri-issue-133.rs deleted file mode 100644 index 406b5e102c8b..000000000000 --- a/tests/run-pass/miri-issue-133.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::mem::size_of; - -struct S { - _u: U, - size_of_u: usize, - _v: V, - size_of_v: usize -} - -impl S { - fn new(u: U, v: V) -> Self { - S { - _u: u, - size_of_u: size_of::(), - _v: v, - size_of_v: size_of::() - } - } -} - -impl Drop for S { - fn drop(&mut self) { - assert_eq!(size_of::(), self.size_of_u); - assert_eq!(size_of::(), self.size_of_v); - } -} - -fn main() { - S::new(0u8, 1u16); -} diff --git a/tests/run-pass/move-arg-3-unique.rs b/tests/run-pass/move-arg-3-unique.rs deleted file mode 100644 index 2e6320eb8025..000000000000 --- a/tests/run-pass/move-arg-3-unique.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(unused_features, unused_variables)] -#![feature(box_syntax)] - -pub fn main() { - let x = box 10; - let y = x; - assert_eq!(*y, 10); -} diff --git a/tests/run-pass/move-undef-primval.rs b/tests/run-pass/move-undef-primval.rs deleted file mode 100644 index 2c18c2d3687a..000000000000 --- a/tests/run-pass/move-undef-primval.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Moving around undef is not allowed by validation -// compile-flags: -Zmir-emit-validate=0 - -struct Foo { - _inner: i32, -} - -fn main() { - unsafe { - let foo = Foo { - _inner: std::mem::uninitialized(), - }; - let _bar = foo; - } -} diff --git a/tests/run-pass/multi_arg_closure.rs b/tests/run-pass/multi_arg_closure.rs deleted file mode 100644 index 30cfb5b685b2..000000000000 --- a/tests/run-pass/multi_arg_closure.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn foo(f: &mut FnMut(isize, isize) -> isize) -> isize { - f(1, 2) -} - -fn main() { - let z = foo(&mut |x, y| x * 10 + y); - assert_eq!(z, 12); -} diff --git a/tests/run-pass/negative_discriminant.rs b/tests/run-pass/negative_discriminant.rs deleted file mode 100644 index 16f175e7dfc8..000000000000 --- a/tests/run-pass/negative_discriminant.rs +++ /dev/null @@ -1,13 +0,0 @@ -enum AB { A = -1, B = 1 } - -fn main() { - match AB::A { - AB::A => (), - AB::B => panic!(), - } - - match AB::B { - AB::A => panic!(), - AB::B => (), - } -} diff --git a/tests/run-pass/non_capture_closure_to_fn_ptr.rs b/tests/run-pass/non_capture_closure_to_fn_ptr.rs deleted file mode 100644 index c9daff9c9f46..000000000000 --- a/tests/run-pass/non_capture_closure_to_fn_ptr.rs +++ /dev/null @@ -1,14 +0,0 @@ -// allow(const_err) to work around a bug in warnings -#[allow(const_err)] -static FOO: fn() = || { assert_ne!(42, 43) }; -#[allow(const_err)] -static BAR: fn(i32, i32) = |a, b| { assert_ne!(a, b) }; - -fn main() { - FOO(); - BAR(44, 45); - let bar: unsafe fn(i32, i32) = BAR; - unsafe { bar(46, 47) }; - let boo: &Fn(i32, i32) = &BAR; - boo(48, 49); -} diff --git a/tests/run-pass/observed_local_mut.rs b/tests/run-pass/observed_local_mut.rs deleted file mode 100644 index a4ecf1e635d2..000000000000 --- a/tests/run-pass/observed_local_mut.rs +++ /dev/null @@ -1,21 +0,0 @@ -// This test is intended to guard against the problem described in commit -// 39bb1254d1eaf74f45a4e741097e33fc942168d5. -// -// As written, it might be considered UB in compiled Rust, but of course Miri gives it a safe, -// deterministic behaviour (one that might not correspond with how an eventual Rust spec would -// defined this). -// -// An alternative way to write the test without `unsafe` would be to use `Cell`, but it would -// only surface the bug described by the above commit if `Cell` on the stack got represented -// as a primitive `PrimVal::I32` which is not yet the case. - -fn main() { - let mut x = 0; - let y: *const i32 = &x; - x = 1; - - // When the described bug is in place, this results in `0`, not observing the `x = 1` line. - assert_eq!(unsafe { *y }, 1); - - assert_eq!(x, 1); -} diff --git a/tests/run-pass/option_box_transmute_ptr.rs b/tests/run-pass/option_box_transmute_ptr.rs deleted file mode 100644 index 0786db1ef895..000000000000 --- a/tests/run-pass/option_box_transmute_ptr.rs +++ /dev/null @@ -1,15 +0,0 @@ -// This tests that the size of Option> is the same as *const i32. -fn option_box_deref() -> i32 { - let val = Some(Box::new(42)); - unsafe { - let ptr: *const i32 = std::mem::transmute::>, *const i32>(val); - let ret = *ptr; - // unleak memory - std::mem::transmute::<*const i32, Option>>(ptr); - ret - } -} - -fn main() { - assert_eq!(option_box_deref(), 42); -} diff --git a/tests/run-pass/option_eq.rs b/tests/run-pass/option_eq.rs deleted file mode 100644 index e698f8767746..000000000000 --- a/tests/run-pass/option_eq.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - assert_eq!(std::char::from_u32('x' as u32), Some('x')); -} diff --git a/tests/run-pass/overloaded-calls-simple.rs b/tests/run-pass/overloaded-calls-simple.rs deleted file mode 100644 index 1eeda12ca06f..000000000000 --- a/tests/run-pass/overloaded-calls-simple.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#![feature(lang_items, unboxed_closures, fn_traits)] - -struct S3 { - x: i32, - y: i32, -} - -impl FnOnce<(i32,i32)> for S3 { - type Output = i32; - extern "rust-call" fn call_once(self, (z,zz): (i32,i32)) -> i32 { - self.x * self.y * z * zz - } -} - -fn main() { - let s = S3 { - x: 3, - y: 3, - }; - let ans = s(3, 1); - assert_eq!(ans, 27); -} diff --git a/tests/run-pass/packed_static.rs b/tests/run-pass/packed_static.rs deleted file mode 100644 index 1fa3a369670b..000000000000 --- a/tests/run-pass/packed_static.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[repr(packed)] -struct Foo { - i: i32 -} - -fn main() { - assert_eq!({FOO.i}, 42); -} - -static FOO: Foo = Foo { i: 42 }; diff --git a/tests/run-pass/packed_struct.rs b/tests/run-pass/packed_struct.rs deleted file mode 100644 index e0387a5f405f..000000000000 --- a/tests/run-pass/packed_struct.rs +++ /dev/null @@ -1,69 +0,0 @@ -// FIXME: We have to disable this, force_allocation fails. -// TODO: I think this can be triggered even without validation. -// compile-flags: -Zmir-emit-validate=0 -#![allow(dead_code)] -#![feature(unsize, coerce_unsized)] - -#[repr(packed)] -struct S { - a: i32, - b: i64, -} - -#[repr(packed)] -struct Test1<'a> { - x: u8, - other: &'a u32, -} - -#[repr(packed)] -struct Test2<'a> { - x: u8, - other: &'a Test1<'a>, -} - -fn test(t: Test2) { - let x = *t.other.other; - assert_eq!(x, 42); -} - -fn test_unsizing() { - #[repr(packed)] - struct UnalignedPtr<'a, T: ?Sized> - where T: 'a, - { - data: &'a T, - } - - impl<'a, T, U> std::ops::CoerceUnsized> for UnalignedPtr<'a, T> - where - T: std::marker::Unsize + ?Sized, - U: ?Sized, - { } - - let arr = [1, 2, 3]; - let arr_unaligned: UnalignedPtr<[i32; 3]> = UnalignedPtr { data: &arr }; - let arr_unaligned: UnalignedPtr<[i32]> = arr_unaligned; - let _unused = &arr_unaligned; // forcing an allocation, which could also yield "unaligned write"-errors -} - -fn main() { - let mut x = S { - a: 42, - b: 99, - }; - let a = x.a; - let b = x.b; - assert_eq!(a, 42); - assert_eq!(b, 99); - // can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference - assert_eq!({x.a}, 42); - assert_eq!({x.b}, 99); - - x.b = 77; - assert_eq!({x.b}, 77); - - test(Test2 { x: 0, other: &Test1 { x: 0, other: &42 }}); - - test_unsizing(); -} diff --git a/tests/run-pass/pointers.rs b/tests/run-pass/pointers.rs deleted file mode 100644 index f3ae3ab913a3..000000000000 --- a/tests/run-pass/pointers.rs +++ /dev/null @@ -1,60 +0,0 @@ -fn one_line_ref() -> i16 { - *&1 -} - -fn basic_ref() -> i16 { - let x = &1; - *x -} - -fn basic_ref_mut() -> i16 { - let x = &mut 1; - *x += 2; - *x -} - -fn basic_ref_mut_var() -> i16 { - let mut a = 1; - { - let x = &mut a; - *x += 2; - } - a -} - -fn tuple_ref_mut() -> (i8, i8) { - let mut t = (10, 20); - { - let x = &mut t.1; - *x += 2; - } - t -} - -fn match_ref_mut() -> i8 { - let mut t = (20, 22); - { - let opt = Some(&mut t); - match opt { - Some(&mut (ref mut x, ref mut y)) => *x += *y, - None => {}, - } - } - t.0 -} - -fn dangling_pointer() -> *const i32 { - let b = Box::new(42); - &*b as *const i32 -} - -fn main() { - assert_eq!(one_line_ref(), 1); - assert_eq!(basic_ref(), 1); - assert_eq!(basic_ref_mut(), 3); - assert_eq!(basic_ref_mut_var(), 3); - assert_eq!(tuple_ref_mut(), (10, 22)); - assert_eq!(match_ref_mut(), 42); - // FIXME: improve this test... how? - assert!(dangling_pointer() != std::ptr::null()); -} diff --git a/tests/run-pass/products.rs b/tests/run-pass/products.rs deleted file mode 100644 index 86bb71a0be56..000000000000 --- a/tests/run-pass/products.rs +++ /dev/null @@ -1,32 +0,0 @@ -fn tuple() -> (i16,) { - (1,) -} - -fn tuple_2() -> (i16, i16) { - (1, 2) -} - -fn tuple_5() -> (i16, i16, i16, i16, i16) { - (1, 2, 3, 4, 5) -} - -#[derive(Debug, PartialEq)] -struct Pair { x: i8, y: i8 } - -fn pair() -> Pair { - Pair { x: 10, y: 20 } -} - -fn field_access() -> (i8, i8) { - let mut p = Pair { x: 10, y: 20 }; - p.x += 5; - (p.x, p.y) -} - -fn main() { - assert_eq!(tuple(), (1,)); - assert_eq!(tuple_2(), (1, 2)); - assert_eq!(tuple_5(), (1, 2, 3, 4, 5)); - assert_eq!(pair(), Pair { x: 10, y: 20} ); - assert_eq!(field_access(), (15, 20)); -} diff --git a/tests/run-pass/ptr_arith_offset.rs b/tests/run-pass/ptr_arith_offset.rs deleted file mode 100644 index 7912da9fd437..000000000000 --- a/tests/run-pass/ptr_arith_offset.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - let v = [1i16, 2]; - let x = &v as *const i16; - let x = x.wrapping_offset(1); - assert_eq!(unsafe { *x }, 2); -} diff --git a/tests/run-pass/ptr_arith_offset_overflow.rs b/tests/run-pass/ptr_arith_offset_overflow.rs deleted file mode 100644 index 3383c3b80148..000000000000 --- a/tests/run-pass/ptr_arith_offset_overflow.rs +++ /dev/null @@ -1,9 +0,0 @@ -fn main() { - let v = [1i16, 2]; - let x = &v[1] as *const i16; - // Adding 2*isize::max and then 1 is like substracting 1 - let x = x.wrapping_offset(isize::max_value()); - let x = x.wrapping_offset(isize::max_value()); - let x = x.wrapping_offset(1); - assert_eq!(unsafe { *x }, 1); -} diff --git a/tests/run-pass/ptr_int_casts.rs b/tests/run-pass/ptr_int_casts.rs deleted file mode 100644 index b1b06263056d..000000000000 --- a/tests/run-pass/ptr_int_casts.rs +++ /dev/null @@ -1,35 +0,0 @@ -use std::mem; - -fn eq_ref(x: &T, y: &T) -> bool { - x as *const _ == y as *const _ -} - -fn f() -> i32 { 42 } - -fn main() { - // int-ptr-int - assert_eq!(1 as *const i32 as usize, 1); - assert_eq!((1 as *const i32).wrapping_offset(4) as usize, 1 + 4*4); - - { // ptr-int-ptr - let x = 13; - let mut y = &x as &_ as *const _ as usize; - y += 13; - y -= 13; - let y = y as *const _; - assert!(eq_ref(&x, unsafe { &*y })); - } - - { // fnptr-int-fnptr - let x : fn() -> i32 = f; - let y : *mut u8 = unsafe { mem::transmute(x as fn() -> i32) }; - let mut y = y as usize; - y += 13; - y -= 13; - let x : fn() -> i32 = unsafe { mem::transmute(y as *mut u8) }; - assert_eq!(x(), 42); - } - - // involving types other than usize - assert_eq!((-1i32) as usize as *const i32 as usize, (-1i32) as usize); -} diff --git a/tests/run-pass/ptr_offset.rs b/tests/run-pass/ptr_offset.rs deleted file mode 100644 index 6add5212db9f..000000000000 --- a/tests/run-pass/ptr_offset.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn main() { - let v = [1i16, 2]; - let x = &v as *const i16; - let x = unsafe { x.offset(1) }; - assert_eq!(unsafe { *x }, 2); -} diff --git a/tests/run-pass/rc.rs b/tests/run-pass/rc.rs deleted file mode 100644 index 0bf707503112..000000000000 --- a/tests/run-pass/rc.rs +++ /dev/null @@ -1,39 +0,0 @@ -use std::cell::RefCell; -use std::rc::Rc; - -fn rc_refcell() { - let r = Rc::new(RefCell::new(42)); - *r.borrow_mut() += 10; - let x = *r.borrow(); - assert_eq!(x, 52); -} - -fn rc_raw() { - let r = Rc::new(0); - let r2 = Rc::into_raw(r.clone()); - let r2 = unsafe { Rc::from_raw(r2) }; - assert!(Rc::ptr_eq(&r, &r2)); - drop(r); - assert!(Rc::try_unwrap(r2).is_ok()); -} - -// Make sure this Rc doesn't fall apart when touched -fn check_unique_rc(mut r: Rc) { - let r2 = r.clone(); - assert!(Rc::get_mut(&mut r).is_none()); - drop(r2); - assert!(Rc::get_mut(&mut r).is_some()); -} - -fn rc_from() { - check_unique_rc::<[_]>(Rc::from(&[1,2,3] as &[_])); - check_unique_rc::<[_]>(Rc::from(vec![1,2,3])); - check_unique_rc::<[_]>(Rc::from(Box::new([1,2,3]) as Box<[_]>)); - check_unique_rc::(Rc::from("Hello, World!")); -} - -fn main() { - rc_refcell(); - rc_raw(); - rc_from(); -} diff --git a/tests/run-pass/recursive_static.rs b/tests/run-pass/recursive_static.rs deleted file mode 100644 index d259ca6361c9..000000000000 --- a/tests/run-pass/recursive_static.rs +++ /dev/null @@ -1,12 +0,0 @@ -// FIXME: Disable validation until we figure out how to handle recursive statics. -// compile-flags: -Zmir-emit-validate=0 - -struct S(&'static S); -static S1: S = S(&S2); -static S2: S = S(&S1); - -fn main() { - let p: *const S = S2.0; - let q: *const S = &S1; - assert_eq!(p, q); -} diff --git a/tests/run-pass/ref-invalid-ptr.rs b/tests/run-pass/ref-invalid-ptr.rs deleted file mode 100644 index ebbbb77748d4..000000000000 --- a/tests/run-pass/ref-invalid-ptr.rs +++ /dev/null @@ -1,7 +0,0 @@ -fn main() { - let x = 2usize as *const u32; - let _y = unsafe { &*x as *const u32 }; - - let x = 0usize as *const u32; - let _y = unsafe { &*x as *const u32 }; -} diff --git a/tests/run-pass/regions-lifetime-nonfree-late-bound.rs b/tests/run-pass/regions-lifetime-nonfree-late-bound.rs deleted file mode 100644 index 1aef95d8a3f3..000000000000 --- a/tests/run-pass/regions-lifetime-nonfree-late-bound.rs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// This is a regression test for the ICE from issue #10846. -// -// The original issue causing the ICE: the LUB-computations during -// type inference were encountering late-bound lifetimes, and -// asserting that such lifetimes should have already been substituted -// with a concrete lifetime. -// -// However, those encounters were occurring within the lexical scope -// of the binding for the late-bound lifetime; that is, the late-bound -// lifetimes were perfectly valid. The core problem was that the type -// folding code was over-zealously passing back all lifetimes when -// doing region-folding, when really all clients of the region-folding -// case only want to see FREE lifetime variables, not bound ones. - -// pretty-expanded FIXME #23616 - -#![allow(unused_features)] -#![feature(box_syntax)] - -pub fn main() { - fn explicit() { - fn test(_x: Option>) where F: FnMut(Box FnMut(&'a isize)>) {} - test(Some(box |_f: Box FnMut(&'a isize)>| {})); - } - - // The code below is shorthand for the code above (and more likely - // to represent what one encounters in practice). - fn implicit() { - fn test(_x: Option>) where F: FnMut(Box< FnMut(& isize)>) {} - test(Some(box |_f: Box< FnMut(& isize)>| {})); - } - - explicit(); - implicit(); -} diff --git a/tests/run-pass/rfc1623.rs b/tests/run-pass/rfc1623.rs deleted file mode 100644 index 0ee523a5be00..000000000000 --- a/tests/run-pass/rfc1623.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(dead_code)] - -// very simple test for a 'static static with default lifetime -static STATIC_STR: &str = "&'static str"; -const CONST_STR: &str = "&'static str"; - -// this should be the same as without default: -static EXPLICIT_STATIC_STR: &'static str = "&'static str"; -const EXPLICIT_CONST_STR: &'static str = "&'static str"; - -// a function that elides to an unbound lifetime for both in- and output -fn id_u8_slice(arg: &[u8]) -> &[u8] { - arg -} - -// one with a function, argument elided -static STATIC_SIMPLE_FN: &fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]); -const CONST_SIMPLE_FN: &fn(&[u8]) -> &[u8] = &(id_u8_slice as fn(&[u8]) -> &[u8]); - -// this should be the same as without elision -static STATIC_NON_ELIDED_FN: &for<'a> fn(&'a [u8]) -> &'a [u8] = - &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]); -const CONST_NON_ELIDED_FN: &for<'a> fn(&'a [u8]) -> &'a [u8] = - &(id_u8_slice as for<'a> fn(&'a [u8]) -> &'a [u8]); - -// another function that elides, each to a different unbound lifetime -fn multi_args(_a: &u8, _b: &u8, _c: &u8) {} - -static STATIC_MULTI_FN: &fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8)); -const CONST_MULTI_FN: &fn(&u8, &u8, &u8) = &(multi_args as fn(&u8, &u8, &u8)); - -struct Foo<'a> { - bools: &'a [bool], -} - -static STATIC_FOO: Foo = Foo { bools: &[true, false] }; -const CONST_FOO: Foo = Foo { bools: &[true, false] }; - -type Bar<'a> = Foo<'a>; - -static STATIC_BAR: Bar = Bar { bools: &[true, false] }; -const CONST_BAR: Bar = Bar { bools: &[true, false] }; - -type Baz<'a> = fn(&'a [u8]) -> Option; - -fn baz(e: &[u8]) -> Option { - e.first().map(|x| *x) -} - -static STATIC_BAZ: &Baz = &(baz as Baz); -const CONST_BAZ: &Baz = &(baz as Baz); - -static BYTES: &[u8] = &[1, 2, 3]; - -fn main() { - // make sure that the lifetime is actually elided (and not defaulted) - let x = &[1u8, 2, 3]; - STATIC_SIMPLE_FN(x); - CONST_SIMPLE_FN(x); - - STATIC_BAZ(BYTES); // neees static lifetime - CONST_BAZ(BYTES); - - // make sure this works with different lifetimes - let a = &1; - { - let b = &2; - let c = &3; - CONST_MULTI_FN(a, b, c); - } -} diff --git a/tests/run-pass/rust-lang-org.rs b/tests/run-pass/rust-lang-org.rs deleted file mode 100644 index 7ba68e6b239c..000000000000 --- a/tests/run-pass/rust-lang-org.rs +++ /dev/null @@ -1,21 +0,0 @@ -// This code is editable and runnable! -fn main() { - // A simple integer calculator: - // `+` or `-` means add or subtract by 1 - // `*` or `/` means multiply or divide by 2 - - let program = "+ + * - /"; - let mut accumulator = 0; - - for token in program.chars() { - match token { - '+' => accumulator += 1, - '-' => accumulator -= 1, - '*' => accumulator *= 2, - '/' => accumulator /= 2, - _ => { /* ignore everything else */ } - } - } - - assert_eq!(accumulator, 1); -} diff --git a/tests/run-pass/send-is-not-static-par-for.rs b/tests/run-pass/send-is-not-static-par-for.rs deleted file mode 100644 index 4ac1b5436f52..000000000000 --- a/tests/run-pass/send-is-not-static-par-for.rs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//ignore-windows - -use std::sync::Mutex; - -fn par_for(iter: I, f: F) - where I: Iterator, - I::Item: Send, - F: Fn(I::Item) + Sync -{ - for item in iter { - f(item) - } -} - -fn sum(x: &[i32]) { - let sum_lengths = Mutex::new(0); - par_for(x.windows(4), |x| { - *sum_lengths.lock().unwrap() += x.len() - }); - - assert_eq!(*sum_lengths.lock().unwrap(), (x.len() - 3) * 4); -} - -fn main() { - let mut elements = [0; 20]; - - // iterators over references into this stack frame - par_for(elements.iter_mut().enumerate(), |(i, x)| { - *x = i as i32 - }); - - sum(&elements) -} diff --git a/tests/run-pass/sendable-class.rs b/tests/run-pass/sendable-class.rs deleted file mode 100644 index b3e07d00f010..000000000000 --- a/tests/run-pass/sendable-class.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Test that a class with only sendable fields can be sent - -// pretty-expanded FIXME #23616 - -use std::sync::mpsc::channel; - -#[allow(dead_code)] -struct Foo { - i: isize, - j: char, -} - -fn foo(i:isize, j: char) -> Foo { - Foo { - i: i, - j: j - } -} - -pub fn main() { - let (tx, rx) = channel(); - let _ = tx.send(foo(42, 'c')); - let _ = rx; -} diff --git a/tests/run-pass/simd-intrinsic-generic-elements.rs b/tests/run-pass/simd-intrinsic-generic-elements.rs deleted file mode 100644 index 36567f4c0331..000000000000 --- a/tests/run-pass/simd-intrinsic-generic-elements.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(repr_simd, platform_intrinsics)] - -#[repr(simd)] -#[derive(Copy, Clone, Debug, PartialEq)] -#[allow(non_camel_case_types)] -struct i32x2(i32, i32); -#[repr(simd)] -#[derive(Copy, Clone, Debug, PartialEq)] -#[allow(non_camel_case_types)] -struct i32x3(i32, i32, i32); -#[repr(simd)] -#[derive(Copy, Clone, Debug, PartialEq)] -#[allow(non_camel_case_types)] -struct i32x4(i32, i32, i32, i32); -#[repr(simd)] -#[derive(Copy, Clone, Debug, PartialEq)] -#[allow(non_camel_case_types)] -struct i32x8(i32, i32, i32, i32, - i32, i32, i32, i32); - -fn main() { - let _x2 = i32x2(20, 21); - let _x3 = i32x3(30, 31, 32); - let _x4 = i32x4(40, 41, 42, 43); - let _x8 = i32x8(80, 81, 82, 83, 84, 85, 86, 87); - - let _y2 = i32x2(120, 121); - let _y3 = i32x3(130, 131, 132); - let _y4 = i32x4(140, 141, 142, 143); - let _y8 = i32x8(180, 181, 182, 183, 184, 185, 186, 187); - -} diff --git a/tests/run-pass/slice-of-zero-size-elements.rs b/tests/run-pass/slice-of-zero-size-elements.rs deleted file mode 100644 index dbe8ec9addac..000000000000 --- a/tests/run-pass/slice-of-zero-size-elements.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-flags: -C debug-assertions - -use std::slice; - -fn foo(v: &[T]) -> Option<&[T]> { - let mut it = v.iter(); - for _ in 0..5 { - let _ = it.next(); - } - Some(it.as_slice()) -} - -fn foo_mut(v: &mut [T]) -> Option<&mut [T]> { - let mut it = v.iter_mut(); - for _ in 0..5 { - let _ = it.next(); - } - Some(it.into_slice()) -} - -pub fn main() { - // In a slice of zero-size elements the pointer is meaningless. - // Ensure iteration still works even if the pointer is at the end of the address space. - let slice: &[()] = unsafe { slice::from_raw_parts(-5isize as *const (), 10) }; - assert_eq!(slice.len(), 10); - assert_eq!(slice.iter().count(), 10); - - // .nth() on the iterator should also behave correctly - let mut it = slice.iter(); - assert!(it.nth(5).is_some()); - assert_eq!(it.count(), 4); - - // Converting Iter to a slice should never have a null pointer - assert!(foo(slice).is_some()); - - // Test mutable iterators as well - let slice: &mut [()] = unsafe { slice::from_raw_parts_mut(-5isize as *mut (), 10) }; - assert_eq!(slice.len(), 10); - assert_eq!(slice.iter_mut().count(), 10); - - { - let mut it = slice.iter_mut(); - assert!(it.nth(5).is_some()); - assert_eq!(it.count(), 4); - } - - assert!(foo_mut(slice).is_some()) -} diff --git a/tests/run-pass/small_enum_size_bug.rs b/tests/run-pass/small_enum_size_bug.rs deleted file mode 100644 index 7576a97e36ad..000000000000 --- a/tests/run-pass/small_enum_size_bug.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![allow(dead_code)] - -enum E { - A = 1, - B = 2, - C = 3, -} - -fn main() { - let enone = None::; - if let Some(..) = enone { - panic!(); - } -} diff --git a/tests/run-pass/specialization.rs b/tests/run-pass/specialization.rs deleted file mode 100644 index 13894926d36d..000000000000 --- a/tests/run-pass/specialization.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(specialization)] - -trait IsUnit { - fn is_unit() -> bool; -} - -impl IsUnit for T { - default fn is_unit() -> bool { false } -} - -impl IsUnit for () { - fn is_unit() -> bool { true } -} - -fn specialization() -> (bool, bool) { - (i32::is_unit(), <()>::is_unit()) -} - -fn main() { - assert_eq!(specialization(), (false, true)); -} diff --git a/tests/run-pass/static_memory_modification.rs b/tests/run-pass/static_memory_modification.rs deleted file mode 100644 index a68f727322e2..000000000000 --- a/tests/run-pass/static_memory_modification.rs +++ /dev/null @@ -1,8 +0,0 @@ -static mut X: usize = 5; - -fn main() { - unsafe { - X = 6; - assert_eq!(X, 6); - } -} diff --git a/tests/run-pass/static_mut.rs b/tests/run-pass/static_mut.rs deleted file mode 100644 index be5830698b21..000000000000 --- a/tests/run-pass/static_mut.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![allow(dead_code)] - -static mut FOO: i32 = 42; -static BAR: Foo = Foo(unsafe { &FOO as *const _} ); - -struct Foo(*const i32); - -unsafe impl Sync for Foo {} - -fn main() { - unsafe { - assert_eq!(*BAR.0, 42); - FOO = 5; - assert_eq!(FOO, 5); - assert_eq!(*BAR.0, 5); - } -} diff --git a/tests/run-pass/std.rs b/tests/run-pass/std.rs deleted file mode 100644 index e0e23812d275..000000000000 --- a/tests/run-pass/std.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::cell::{Cell, RefCell}; -use std::rc::Rc; -use std::sync::Arc; - -fn rc_cell() -> Rc> { - let r = Rc::new(Cell::new(42)); - let x = r.get(); - r.set(x + x); - r -} - -fn rc_refcell() -> i32 { - let r = Rc::new(RefCell::new(42)); - *r.borrow_mut() += 10; - let x = *r.borrow(); - x -} - -fn arc() -> Arc { - let a = Arc::new(42); - a -} - -fn true_assert() { - assert_eq!(1, 1); -} - -fn main() { - assert_eq!(*arc(), 42); - assert_eq!(rc_cell().get(), 84); - assert_eq!(rc_refcell(), 52); - true_assert(); -} diff --git a/tests/run-pass/strings.rs b/tests/run-pass/strings.rs deleted file mode 100644 index d5fc80b41f01..000000000000 --- a/tests/run-pass/strings.rs +++ /dev/null @@ -1,27 +0,0 @@ -fn empty() -> &'static str { - "" -} - -fn hello() -> &'static str { - "Hello, world!" -} - -fn hello_bytes() -> &'static [u8; 13] { - b"Hello, world!" -} - -fn hello_bytes_fat() -> &'static [u8] { - b"Hello, world!" -} - -fn fat_pointer_on_32_bit() { - Some(5).expect("foo"); -} - -fn main() { - assert_eq!(empty(), ""); - assert_eq!(hello(), "Hello, world!"); - assert_eq!(hello_bytes(), b"Hello, world!"); - assert_eq!(hello_bytes_fat(), b"Hello, world!"); - fat_pointer_on_32_bit(); // Should run without crashing. -} diff --git a/tests/run-pass/subslice_array.rs b/tests/run-pass/subslice_array.rs deleted file mode 100644 index 468cc9f09416..000000000000 --- a/tests/run-pass/subslice_array.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(advanced_slice_patterns)] -#![feature(slice_patterns)] - -fn bar(a: &'static str, b: &'static str) -> [&'static str; 4] { - [a, b, b, a] -} - -fn main() { - let out = bar("baz", "foo"); - let [a, xs.., d] = out; - assert_eq!(a, "baz"); - assert_eq!(xs, ["foo", "foo"]); - assert_eq!(d, "baz"); -} diff --git a/tests/run-pass/sums.rs b/tests/run-pass/sums.rs deleted file mode 100644 index a8dfd5ed66ae..000000000000 --- a/tests/run-pass/sums.rs +++ /dev/null @@ -1,59 +0,0 @@ -// FIXME(solson): 32-bit mode doesn't test anything currently. -#![cfg_attr(target_pointer_width = "32", allow(dead_code))] - -#[derive(Debug, PartialEq)] -enum Unit { Unit(()) } // Force non-C-enum representation. - -fn return_unit() -> Unit { - Unit::Unit(()) -} - -#[derive(Debug, PartialEq)] -enum MyBool { False(()), True(()) } // Force non-C-enum representation. - -fn return_true() -> MyBool { - MyBool::True(()) -} - -fn return_false() -> MyBool { - MyBool::False(()) -} - -fn return_none() -> Option { - None -} - -fn return_some() -> Option { - Some(42) -} - -fn match_opt_none() -> i8 { - let x = None; - match x { - Some(data) => data, - None => 42, - } -} - -fn match_opt_some() -> i8 { - let x = Some(13); - match x { - Some(data) => data, - None => 20, - } -} - -fn two_nones() -> (Option, Option) { - (None, None) -} - -fn main() { - assert_eq!(two_nones(), (None, None)); - assert_eq!(match_opt_some(), 13); - assert_eq!(match_opt_none(), 42); - assert_eq!(return_some(), Some(42)); - assert_eq!(return_none(), None); - assert_eq!(return_false(), MyBool::False(())); - assert_eq!(return_true(), MyBool::True(())); - assert_eq!(return_unit(), Unit::Unit(())); -} diff --git a/tests/run-pass/tag-align-dyn-u64.rs b/tests/run-pass/tag-align-dyn-u64.rs deleted file mode 100644 index 81c19022ab08..000000000000 --- a/tests/run-pass/tag-align-dyn-u64.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(dead_code)] - -use std::mem; - -enum Tag { - Tag2(A) -} - -struct Rec { - c8: u8, - t: Tag -} - -fn mk_rec() -> Rec { - return Rec { c8:0, t:Tag::Tag2(0) }; -} - -fn is_u64_aligned(u: &Tag) -> bool { - let p: usize = unsafe { mem::transmute(u) }; - let u64_align = std::mem::align_of::(); - return (p & (u64_align - 1)) == 0; -} - -pub fn main() { - let x = mk_rec(); - assert!(is_u64_aligned(&x.t)); -} diff --git a/tests/run-pass/thread-local.rs b/tests/run-pass/thread-local.rs deleted file mode 100644 index db00e42d99ac..000000000000 --- a/tests/run-pass/thread-local.rs +++ /dev/null @@ -1,67 +0,0 @@ -//ignore-windows - -#![feature(libc)] -extern crate libc; - -use std::mem; - -pub type Key = libc::pthread_key_t; - -static mut RECORD : usize = 0; -static mut KEYS : [Key; 2] = [0; 2]; -static mut GLOBALS : [u64; 2] = [1, 0]; - -static mut CANNARY : *mut u64 = 0 as *mut _; // this serves as a cannary: if TLS dtors are not run properly, this will not get deallocated, making the test fail. - -pub unsafe fn create(dtor: Option) -> Key { - let mut key = 0; - assert_eq!(libc::pthread_key_create(&mut key, mem::transmute(dtor)), 0); - key -} - -pub unsafe fn set(key: Key, value: *mut u8) { - let r = libc::pthread_setspecific(key, value as *mut _); - assert_eq!(r, 0); -} - -pub fn record(r: usize) { - assert!(r < 10); - unsafe { RECORD = RECORD*10 + r }; -} - -unsafe extern fn dtor(ptr: *mut u64) { - assert!(CANNARY != 0 as *mut _); // make sure we do not get run too often - let val = *ptr; - - let which_key = GLOBALS.iter().position(|global| global as *const _ == ptr).expect("Should find my global"); - record(which_key); - - if val > 0 { - *ptr = val-1; - set(KEYS[which_key], ptr as *mut _); - } - - // Check if the records matches what we expect. If yes, clear the cannary. - // If the record is wrong, the cannary will never get cleared, leading to a leak -> test fails. - // If the record is incomplete (i.e., more dtor calls happen), the check at the beginning of this function will fail -> test fails. - // The correct sequence is: First key 0, then key 1, then key 0. - if RECORD == 0_1_0 { - drop(Box::from_raw(CANNARY)); - CANNARY = 0 as *mut _; - } -} - -fn main() { - unsafe { - create(None); // check that the no-dtor case works - - // Initialize the keys we use to check destructor ordering - for (key, global) in KEYS.iter_mut().zip(GLOBALS.iter()) { - *key = create(Some(mem::transmute(dtor as unsafe extern fn(*mut u64)))); - set(*key, global as *const _ as *mut _); - } - - // Initialize cannary - CANNARY = Box::into_raw(Box::new(0u64)); - } -} diff --git a/tests/run-pass/too-large-primval-write-problem.rs b/tests/run-pass/too-large-primval-write-problem.rs deleted file mode 100644 index 1bbe45277c43..000000000000 --- a/tests/run-pass/too-large-primval-write-problem.rs +++ /dev/null @@ -1,23 +0,0 @@ -// PrimVals in Miri are represented with 8 bytes (u64) and at the time of writing, the `-x` -// will sign extend into the entire 8 bytes. Then, if you tried to write the `-x` into -// something smaller than 8 bytes, like a 4 byte pointer, it would crash in byteorder crate -// code that assumed only the low 4 bytes would be set. Actually, we were masking properly for -// everything except pointers before I fixed it, so this was probably impossible to reproduce on -// 64-bit. -// -// This is just intended as a regression test to make sure we don't reintroduce this problem. - -#[cfg(target_pointer_width = "32")] -fn main() { - use std::mem::transmute; - - // Make the weird PrimVal. - let x = 1i32; - let bad = unsafe { transmute::(-x) }; - - // Force it through the Memory::write_primval code. - Box::new(bad); -} - -#[cfg(not(target_pointer_width = "32"))] -fn main() {} diff --git a/tests/run-pass/traits.rs b/tests/run-pass/traits.rs deleted file mode 100644 index b2eae5d04f41..000000000000 --- a/tests/run-pass/traits.rs +++ /dev/null @@ -1,30 +0,0 @@ -struct Struct(i32); - -trait Trait { - fn method(&self); -} - -impl Trait for Struct { - fn method(&self) { - assert_eq!(self.0, 42); - } -} - -struct Foo(T); - -fn main() { - let y: &Trait = &Struct(42); - y.method(); - let x: Foo = Foo(Struct(42)); - let y: &Foo = &x; - y.0.method(); - - let x: Box i32> = Box::new(|x| x * 2); - assert_eq!(x(21), 42); - let mut i = 5; - { - let mut x: Box = Box::new(|| i *= 2); - x(); x(); - } - assert_eq!(i, 20); -} diff --git a/tests/run-pass/trivial.rs b/tests/run-pass/trivial.rs deleted file mode 100644 index 891d11520656..000000000000 --- a/tests/run-pass/trivial.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn empty() {} - -fn unit_var() { - let x = (); - x -} - -fn main() { - empty(); - unit_var(); -} diff --git a/tests/run-pass/try-operator-custom.rs b/tests/run-pass/try-operator-custom.rs deleted file mode 100644 index 3b447f36ece1..000000000000 --- a/tests/run-pass/try-operator-custom.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - assert!(Ok::(42) == Ok(42)); -} diff --git a/tests/run-pass/tuple_like_enum_variant_constructor.rs b/tests/run-pass/tuple_like_enum_variant_constructor.rs deleted file mode 100644 index 5cf91b3f4d19..000000000000 --- a/tests/run-pass/tuple_like_enum_variant_constructor.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - assert_eq!(Some(42).map(Some), Some(Some(42))); -} diff --git a/tests/run-pass/tuple_like_enum_variant_constructor_pointer_opt.rs b/tests/run-pass/tuple_like_enum_variant_constructor_pointer_opt.rs deleted file mode 100644 index fb57d4f4c165..000000000000 --- a/tests/run-pass/tuple_like_enum_variant_constructor_pointer_opt.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let x = 5; - assert_eq!(Some(&x).map(Some), Some(Some(&x))); -} diff --git a/tests/run-pass/tuple_like_enum_variant_constructor_struct_pointer_opt.rs b/tests/run-pass/tuple_like_enum_variant_constructor_struct_pointer_opt.rs deleted file mode 100644 index 44441ed1d36c..000000000000 --- a/tests/run-pass/tuple_like_enum_variant_constructor_struct_pointer_opt.rs +++ /dev/null @@ -1,33 +0,0 @@ -#[derive(Copy, Clone, PartialEq, Debug)] -struct A<'a> { - x: i32, - y: &'a i32, -} - -#[derive(Copy, Clone, PartialEq, Debug)] -struct B<'a>(i32, &'a i32); - -#[derive(Copy, Clone, PartialEq, Debug)] -enum C<'a> { - Value(i32, &'a i32), - #[allow(dead_code)] - NoValue, -} - -fn main() { - let x = 5; - let a = A { x: 99, y: &x }; - assert_eq!(Some(a).map(Some), Some(Some(a))); - let f = B; - assert_eq!(Some(B(42, &x)), Some(f(42, &x))); - // the following doesn't compile :( - //let f: for<'a> fn(i32, &'a i32) -> B<'a> = B; - //assert_eq!(Some(B(42, &x)), Some(f(42, &x))); - assert_eq!(B(42, &x), foo(&x, B)); - let f = C::Value; - assert_eq!(C::Value(42, &x), f(42, &x)); -} - -fn foo<'a, F: Fn(i32, &'a i32) -> B<'a>>(i: &'a i32, f: F) -> B<'a> { - f(42, i) -} diff --git a/tests/run-pass/tuple_like_struct_constructor.rs b/tests/run-pass/tuple_like_struct_constructor.rs deleted file mode 100644 index 05e8893de178..000000000000 --- a/tests/run-pass/tuple_like_struct_constructor.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn main() { - #[derive(PartialEq, Eq, Debug)] - struct A(i32); - assert_eq!(Some(42).map(A), Some(A(42))); -} diff --git a/tests/run-pass/union-overwrite.rs b/tests/run-pass/union-overwrite.rs deleted file mode 100644 index df2ff6e51a59..000000000000 --- a/tests/run-pass/union-overwrite.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(untagged_unions)] -#![allow(unions_with_drop_fields)] - -#[repr(C)] -struct Pair(T, U); -#[repr(C)] -struct Triple(T, T, T); - -#[repr(C)] -union U { - a: Pair, - b: B, -} - -#[repr(C)] -union W { - a: A, - b: B, -} - -#[cfg(target_endian = "little")] -unsafe fn check() { - let mut u = U:: { b: 0xDE_DE }; - u.a.0 = 0xBE; - assert_eq!(u.b, 0xDE_BE); - - let mut u = U:: { b: 0xDEAD_DEAD }; - u.a.0 = 0xBEEF; - assert_eq!(u.b, 0xDEAD_BEEF); - - let mut u = U:: { b: 0xDEADBEEF_DEADBEEF }; - u.a.0 = 0xBAADF00D; - assert_eq!(u.b, 0xDEADBEEF_BAADF00D); - - let mut w = W::, u8>, u32> { b: 0xDEAD_DEAD }; - w.a.0 = Triple(0, 0, 0); - assert_eq!(w.b, 0xDE00_0000); - - let mut w = W::>, u32> { b: 0xDEAD_DEAD }; - w.a.1 = Triple(0, 0, 0); - assert_eq!(w.b, 0x0000_00AD); -} - -#[cfg(target_endian = "big")] -unsafe fn check() { - let mut u = U:: { b: 0xDE_DE }; - u.a.0 = 0xBE; - assert_eq!(u.b, 0xBE_DE); - - let mut u = U:: { b: 0xDEAD_DEAD }; - u.a.0 = 0xBEEF; - assert_eq!(u.b, 0xBEEF_DEAD); - - let mut u = U:: { b: 0xDEADBEEF_DEADBEEF }; - u.a.0 = 0xBAADF00D; - assert_eq!(u.b, 0xBAADF00D_DEADBEEF); - - let mut w = W::, u8>, u32> { b: 0xDEAD_DEAD }; - w.a.0 = Triple(0, 0, 0); - assert_eq!(w.b, 0x0000_00AD); - - let mut w = W::>, u32> { b: 0xDEAD_DEAD }; - w.a.1 = Triple(0, 0, 0); - assert_eq!(w.b, 0xDE00_0000); -} - -fn main() { - unsafe { - check(); - } -} diff --git a/tests/run-pass/union.rs b/tests/run-pass/union.rs deleted file mode 100644 index 342c94f3d4a3..000000000000 --- a/tests/run-pass/union.rs +++ /dev/null @@ -1,88 +0,0 @@ -#![feature(untagged_unions)] -#![allow(dead_code, unused_variables)] - -fn main() { - a(); - b(); - c(); - d(); -} - -fn a() { - union U { - f1: u32, - f2: f32, - } - let mut u = U { f1: 1 }; - unsafe { - let b1 = &mut u.f1; - *b1 = 5; - } - assert_eq!(unsafe { u.f1 }, 5); -} - -fn b() { - struct S { - x: u32, - y: u32, - } - - union U { - s: S, - both: u64, - } - let mut u = U { s: S { x: 1, y: 2 } }; - unsafe { - let bx = &mut u.s.x; - let by = &mut u.s.y; - *bx = 5; - *by = 10; - } - assert_eq!(unsafe { u.s.x }, 5); - assert_eq!(unsafe { u.s.y }, 10); -} - -fn c() { - #[repr(u32)] - enum Tag { I, F } - - #[repr(C)] - union U { - i: i32, - f: f32, - } - - #[repr(C)] - struct Value { - tag: Tag, - u: U, - } - - fn is_zero(v: Value) -> bool { - unsafe { - match v { - Value { tag: Tag::I, u: U { i: 0 } } => true, - Value { tag: Tag::F, u: U { f } } => f == 0.0, - _ => false, - } - } - } - assert!(is_zero(Value { tag: Tag::I, u: U { i: 0 }})); - assert!(is_zero(Value { tag: Tag::F, u: U { f: 0.0 }})); - assert!(!is_zero(Value { tag: Tag::I, u: U { i: 1 }})); - assert!(!is_zero(Value { tag: Tag::F, u: U { f: 42.0 }})); -} - -fn d() { - union MyUnion { - f1: u32, - f2: f32, - } - let u = MyUnion { f1: 10 }; - unsafe { - match u { - MyUnion { f1: 10 } => { } - MyUnion { f2 } => { panic!("foo"); } - } - } -} diff --git a/tests/run-pass/unique-send.rs b/tests/run-pass/unique-send.rs deleted file mode 100644 index 7644da08e4af..000000000000 --- a/tests/run-pass/unique-send.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![feature(box_syntax)] - -use std::sync::mpsc::channel; - -pub fn main() { - let (tx, rx) = channel::>(); - tx.send(box 100).unwrap(); - let v = rx.recv().unwrap(); - assert_eq!(v, box 100); -} diff --git a/tests/run-pass/validation_lifetime_resolution.rs b/tests/run-pass/validation_lifetime_resolution.rs deleted file mode 100644 index 4d919f735255..000000000000 --- a/tests/run-pass/validation_lifetime_resolution.rs +++ /dev/null @@ -1,30 +0,0 @@ -trait Id { - type Out; - - fn id(self) -> Self::Out; -} - -impl<'a> Id for &'a mut i32 { - type Out = &'a mut i32; - - fn id(self) -> Self { self } -} - -impl<'a> Id for &'a mut u32 { - type Out = &'a mut u32; - - fn id(self) -> Self { self } -} - -fn foo(mut x: T) where for<'a> &'a mut T: Id -{ - let x = &mut x; - let _y = x.id(); - // Inspecting the trace should show that _y has a type involving a local lifetime, when it gets validated. - // Unfortunately, there doesn't seem to be a way to actually have a test fail if it does not have the right - // type. Currently, this is NOT working correctly; see . -} - -fn main() { - foo(3) -} diff --git a/tests/run-pass/vec-matching-fold.rs b/tests/run-pass/vec-matching-fold.rs deleted file mode 100644 index ac80a4211ada..000000000000 --- a/tests/run-pass/vec-matching-fold.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - - -#![feature(advanced_slice_patterns)] -#![feature(slice_patterns)] - -use std::fmt::Debug; - -fn foldl(values: &[T], - initial: U, - mut function: F) - -> U where - U: Clone+Debug, T:Debug, - F: FnMut(U, &T) -> U, -{ match values { - &[ref head, ref tail..] => - foldl(tail, function(initial, head), function), - &[] => { - // FIXME: call guards - let res = initial.clone(); res - } - } -} - -fn foldr(values: &[T], - initial: U, - mut function: F) - -> U where - U: Clone, - F: FnMut(&T, U) -> U, -{ - match values { - &[ref head.., ref tail] => - foldr(head, function(tail, initial), function), - &[] => { - // FIXME: call guards - let res = initial.clone(); res - } - } -} - -pub fn main() { - let x = &[1, 2, 3, 4, 5]; - - let product = foldl(x, 1, |a, b| a * *b); - assert_eq!(product, 120); - - let sum = foldr(x, 0, |a, b| *a + b); - assert_eq!(sum, 15); -} diff --git a/tests/run-pass/write-bytes.rs b/tests/run-pass/write-bytes.rs deleted file mode 100644 index 7c9a38fca696..000000000000 --- a/tests/run-pass/write-bytes.rs +++ /dev/null @@ -1,45 +0,0 @@ -#[repr(C)] -#[derive(Copy, Clone)] -struct Foo { - a: u64, - b: u64, - c: u64, -} - -fn main() { - const LENGTH: usize = 10; - let mut v: [u64; LENGTH] = [0; LENGTH]; - - for idx in 0..LENGTH { - assert_eq!(v[idx], 0); - } - - unsafe { - let p = v.as_mut_ptr(); - ::std::ptr::write_bytes(p, 0xab, LENGTH); - } - - for idx in 0..LENGTH { - assert_eq!(v[idx], 0xabababababababab); - } - - // ----- - - let mut w: [Foo; LENGTH] = [Foo { a: 0, b: 0, c: 0 }; LENGTH]; - for idx in 0..LENGTH { - assert_eq!(w[idx].a, 0); - assert_eq!(w[idx].b, 0); - assert_eq!(w[idx].c, 0); - } - - unsafe { - let p = w.as_mut_ptr(); - ::std::ptr::write_bytes(p, 0xcd, LENGTH); - } - - for idx in 0..LENGTH { - assert_eq!(w[idx].a, 0xcdcdcdcdcdcdcdcd); - assert_eq!(w[idx].b, 0xcdcdcdcdcdcdcdcd); - assert_eq!(w[idx].c, 0xcdcdcdcdcdcdcdcd); - } -} diff --git a/tests/run-pass/zero-sized-binary-heap-push.rs b/tests/run-pass/zero-sized-binary-heap-push.rs deleted file mode 100644 index 63a0d65f017d..000000000000 --- a/tests/run-pass/zero-sized-binary-heap-push.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::collections::BinaryHeap; -use std::iter::Iterator; - -fn main() { - const N: usize = 8; - - for len in 0..N { - let mut tester = BinaryHeap::with_capacity(len); - assert_eq!(tester.len(), 0); - assert!(tester.capacity() >= len); - for _ in 0..len { - tester.push(()); - } - assert_eq!(tester.len(), len); - assert_eq!(tester.iter().count(), len); - tester.clear(); - } -} diff --git a/tests/run-pass/zst.rs b/tests/run-pass/zst.rs deleted file mode 100644 index c1c88875c5c8..000000000000 --- a/tests/run-pass/zst.rs +++ /dev/null @@ -1,18 +0,0 @@ -#[derive(PartialEq, Debug)] -struct A; - -fn zst_ret() -> A { - A -} - -fn use_zst() -> A { - let a = A; - a -} - -fn main() { - assert_eq!(zst_ret(), A); - assert_eq!(use_zst(), A); - let x = 42 as *mut (); - unsafe { *x = (); } -} diff --git a/tests/run-pass/zst2.rs b/tests/run-pass/zst2.rs deleted file mode 100644 index c2d7b88ea075..000000000000 --- a/tests/run-pass/zst2.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![allow(dead_code)] - -#[derive(Debug)] -struct A; - -fn main() { - // can't use assert_eq, b/c that will try to print the pointer addresses with full MIR enabled - - // FIXME: Test disabled for now, see . - //assert!(&A as *const A as *const () == &() as *const _); - //assert!(&A as *const A == &A as *const A); -} diff --git a/tests/run-pass/zst_box.rs b/tests/run-pass/zst_box.rs deleted file mode 100644 index 12138be5af97..000000000000 --- a/tests/run-pass/zst_box.rs +++ /dev/null @@ -1,8 +0,0 @@ -fn main() { - let x = Box::new(()); - let y = Box::new(()); - drop(y); - let z = Box::new(()); - drop(x); - drop(z); -} diff --git a/tests/run-pass/zst_variant_drop.rs b/tests/run-pass/zst_variant_drop.rs deleted file mode 100644 index a76f64ce29df..000000000000 --- a/tests/run-pass/zst_variant_drop.rs +++ /dev/null @@ -1,23 +0,0 @@ -struct Foo; -impl Drop for Foo { - fn drop(&mut self) { - unsafe { - FOO = true; - } - } -} - -static mut FOO: bool = false; - -enum Bar { - A(Box), - B(Foo), -} - -fn main() { - assert!(unsafe { !FOO }); - drop(Bar::A(Box::new(42))); - assert!(unsafe { !FOO }); - drop(Bar::B(Foo)); - assert!(unsafe { FOO }); -} diff --git a/tex/final-presentation/latexmkrc b/tex/final-presentation/latexmkrc deleted file mode 100644 index 23aa1a481b3e..000000000000 --- a/tex/final-presentation/latexmkrc +++ /dev/null @@ -1,12 +0,0 @@ -# vim: ft=perl - -$pdf_mode = 1; -$pdflatex = 'lualatex --shell-escape %O %S'; -$out_dir = 'out'; - -# This improves latexmk's detection of source files and generated files. -$recorder = 1; - -# Ignore always-regenerated *.pyg files from the minted package when considering -# whether to run pdflatex again. -$hash_calc_ignore_pattern{'pyg'} = '.*'; diff --git a/tex/final-presentation/rust-logo-512x512.png b/tex/final-presentation/rust-logo-512x512.png deleted file mode 100644 index 38484c670e01..000000000000 Binary files a/tex/final-presentation/rust-logo-512x512.png and /dev/null differ diff --git a/tex/final-presentation/slides.tex b/tex/final-presentation/slides.tex deleted file mode 100644 index c5e1f51ba19c..000000000000 --- a/tex/final-presentation/slides.tex +++ /dev/null @@ -1,444 +0,0 @@ -\documentclass{beamer} -\usecolortheme{beaver} -\beamertemplatenavigationsymbolsempty - -% Fonts -\usepackage{fontspec} -\setmainfont{Source Serif Pro}[Ligatures=TeX] -\setsansfont{Source Sans Pro}[Ligatures=TeX] -\setmonofont{Source Code Pro}[ - BoldFont={* Medium}, - BoldItalicFont={* Medium Italic}, -] - -\usepackage[outputdir=out]{minted} -\usepackage{tikz} -\usetikzlibrary{positioning, fit} - -\tikzset{ - invisible/.style={opacity=0,text opacity=0}, - highlight/.style={color=red}, - intro/.code args={<#1>}{% - \only<#1>{\pgfkeysalso{highlight}} - \alt<#1->{}{\pgfkeysalso{invisible}} - }, -} - -\title{Miri} -\subtitle{An interpreter for Rust's mid-level intermediate representation} -\author{ - Scott Olson - \texorpdfstring{\\ \scriptsize{Supervisor: Christopher Dutchyn}}{} -} -\institute{ - CMPT 400 \\ - University of Saskatchewan -} -\date{} -\titlegraphic{ - \includegraphics[width=64px,height=64px]{rust-logo-512x512.png} \\ - \scriptsize{\url{https://www.rust-lang.org}} -} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Intro slides -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\begin{document} - -\maketitle - -\begin{frame}[fragile] - \frametitle{What is Rust? \small{[review]}} - - According to the website\dots - - \begin{quote} - \textbf{Rust} is a systems programming language that runs blazingly fast, - prevents nearly all segfaults, and guarantees thread safety. - \end{quote} - - It's a new programming language from Mozilla, and it looks like this: - - \begin{minted}[ - autogobble, - fontsize=\footnotesize, - mathescape, - xleftmargin=.3in, - ]{rust} - fn factorial(n: u64) -> u64 { - (1..n).fold(1, |a, b| a * b) - } - - fn main() { - for x in 1..6 { - println!("{}", factorial(x)); - } - // $\Rightarrow$ 1 - // $\Rightarrow$ 1 - // $\Rightarrow$ 2 - // $\Rightarrow$ 6 - // $\Rightarrow$ 24 - } - \end{minted} -\end{frame} - -\begin{frame} - \frametitle{How does Rust compile code? \onslide<-6>{\small{[review]}}} - - \begin{center} - \begin{tikzpicture}[x=4cm, y=3.5cm, auto, rounded corners] - \tikzstyle{basic-stage}=[rectangle, draw, thick, align=center] - \tikzstyle{stage}=[basic-stage, font=\tiny] - \tikzstyle{pass}=[thick, -stealth] - \tikzstyle{pass-label}=[font=\footnotesize] - - \node[basic-stage] (src) at (0,0) {Source\\Code}; - \node[basic-stage] (mach) at (2,-1) {Machine\\Code}; - - \draw<1>[pass, out=0, in=180] - (src.east) to node[font=\Huge] {?} (mach.west); - - \node[stage, intro=<2>] (ast) at (1,0) - {\normalsize{AST} \\ Abstract Syntax Tree}; - \draw[pass, intro=<2>] - (src) -- node[pass-label] {Parse} (ast); - - \node[stage, intro=<3>] (hir) at (2,0) - {\normalsize{HIR} \\ High-level Intermediate\\Representation}; - \draw[pass, intro=<3>] - (ast) -- node[pass-label] {Simplify} (hir); - - \node[stage, intro=<4>] (mir) at (0,-1) - {\normalsize{MIR} \\ Mid-level Intermediate\\Representation}; - \path (hir.south) -- coordinate (middle) (mir.north); - \draw[pass, intro=<4>] - (hir.south) |- (middle) -| (mir.north); - \node[pass-label, above, intro=<4>] at (middle) {Lower}; - - \node[stage, intro=<5>] (llvm) at (1,-1) - {\normalsize{LLVM IR} \\ Low-level Intermediate\\Representation}; - \draw[pass, intro=<5>] - (mir) -- node[pass-label] {Translate} (llvm); - - \draw<6->[pass, intro=<6>] - (llvm) -- node[pass-label] {Magic} (mach); - - \node[stage, intro=<7>] (exec) at (1,-1.75) - {\normalsize{Execution}}; - \draw[pass, intro=<7>] - (mach) -- node[pass-label] {CPU} (exec); - - \draw[pass, intro=<8>] - (mir) -- node[pass-label] {Miri} (exec); - \end{tikzpicture} - \end{center} -\end{frame} - -\begin{frame} - \frametitle{Why build Miri?} - \begin{itemize} - \item For fun and learning. - - \item I originally planned to use it for testing the compiler and execution - of unsafe code, but shifted my goals along the way. \pause - - \item Now it serves as an experimental implementation of the upcoming - compile-time function evaluation feature in Rust. \pause - - \begin{itemize} - \item Similar to C++14's \mintinline{cpp}{constexpr} feature. - - \item You can do complicated calculations at compile time and compile - their \emph{results} into the executable. \pause - - \item For example, you can compute a ``perfect hash function'' for a - statically-known map at compile-time and have guaranteed no-collision - lookup at runtime. \pause - - \item Miri actually supports far more of Rust than C++14's - \mintinline{cpp}{constexpr} does of C++ --- even heap allocation and - unsafe code. - \end{itemize} - \end{itemize} -\end{frame} - -\begin{frame} - \frametitle{How was it built?} - - At first I wrote a naive version with a number of downsides: - - \begin{itemize} - \item represented values in a traditional dynamic language format, where - every value was the same size. - - \item didn't work well for aggregates (structs, enums, arrays, etc.). - - \item made unsafe programming tricks that make assumptions about low-level - value layout essentially impossible. - \end{itemize} -\end{frame} - -\begin{frame} - \frametitle{How was it built?} - \begin{itemize} - \item Later, a Rust compiler team member proposed a ``Rust abstract - machine'' with specialized value layout which solved my previous problems. - \pause - - \item His proposal was intended for a compile-time function evaluator in the - Rust compiler, so I effectively implemented an experimental version of - that. \pause - - \item After this point, making Miri work well was primarily a software - engineering problem. - \end{itemize} -\end{frame} - -\begin{frame} - \frametitle{Data layout} - \begin{itemize} - \item Memory in Miri is literally a HashMap from ``allocation IDs'' to - ``abstract allocations''. - - \item Allocations are represented by: \pause - \begin{enumerate} - \item An array of \textbf{raw bytes} with a size based on the type of - the value \pause - \item A set of \textbf{relocations} --- pointers into other abstract - allocations \pause - \item A mask determining which bytes are \textbf{undefined} - \end{enumerate} - \end{itemize} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{square} example} - \begin{center} - \begin{minted}[autogobble,fontsize=\scriptsize]{rust} - // Rust - fn square(n: u64) -> u64 { - n * n - } - - // Generated MIR - fn square(arg0: u64) -> u64 { - let var0: u64; // n // On function entry, Miri creates - // virtual allocations for all the - // arguments, variables, and - // temporaries. - - bb0: { - var0 = arg0; // Copy the argument into `n`. - return = Mul(var0, var0); // Multiply `n` with itself. - goto -> bb1; // Jump to basic block `bb1`. - } - - bb1: { - return; // Return from the current fn. - } - } - \end{minted} - \end{center} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{sum} example} - \begin{center} - \begin{minted}[autogobble,fontsize=\tiny]{rust} - // Rust - fn sum() -> u64 { - let mut sum = 0; let mut i = 0; - while i < 10 { sum += i; i += 1; } - sum - } - - // Generated MIR - fn sum() -> u64 { - let mut var0: u64; // sum - let mut var1: u64; // i - let mut tmp0: bool; - - bb0: { - // sum = 0; i = 0; - var0 = const 0u64; var1 = const 0u64; goto -> bb1; - } - bb1: { - // if i < 10 { goto bb2; } else { goto bb3; } - tmp0 = Lt(var1, const 10u64); - if(tmp0) -> [true: bb2, false: bb3]; - } - bb2: { - var0 = Add(var0, var1); // sum = sum + i; - var1 = Add(var1, const 1u64); // i = i + 1; - goto -> bb1; - } - bb3: { - return = var0; goto -> bb4; - } - bb4: { return; } - } - \end{minted} - \end{center} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Heap allocations!} - \begin{minted}[autogobble,fontsize=\scriptsize]{rust} - fn make_vec() -> Vec { - // Empty array with space for 4 bytes - allocated on the heap! - let mut vec = Vec::with_capacity(4); - // Initialize the first two slots. - vec.push(1); - vec.push(2); - vec - } - - // For reference: - // struct Vec { capacity: usize, data: *mut T, length: usize } - - // Resulting allocations (on 32-bit little-endian architectures): - // Region A: - // 04 00 00 00 00 00 00 00 02 00 00 00 - // └───(B)───┘ - // - // Region B: - // 01 02 __ __ (underscores denote undefined bytes) - \end{minted} - - \footnotesize{Evaluating the above involves a number of compiler built-ins, - ``unsafe'' code blocks, and more inside the standard library, - but Miri handles it all.} -\end{frame} - -\begin{frame}[fragile] - \frametitle{Unsafe code!} - \begin{minted}[autogobble,fontsize=\scriptsize]{rust} - fn out_of_bounds() -> u8 { - let mut vec = vec![1, 2] - unsafe { *vec.get_unchecked(5) } - } - - // test.rs:3: error: pointer offset outside bounds of allocation - // test.rs:3: unsafe { *vec.get_unchecked(5) } - // ^~~~~~~~~~~~~~~~~~~~~ - - fn undefined_bytes() -> u8 { - let mut vec = Vec::with_capacity(10); - unsafe { *vec.get_unchecked(5) } - } - - // test.rs:3: error: attempted to read undefined bytes - // test.rs:3: unsafe { *vec.get_unchecked(5) } - // ^~~~~~~~~~~~~~~~~~~~~ - \end{minted} -\end{frame} - -\begin{frame} - \frametitle{What can't Miri do?} - \begin{itemize} - \item Miri can't do all the stuff I didn't implement yet. :) - \begin{itemize} - \item non-trivial casts - \item function pointers - \item calling destructors and freeing memory - \item taking target architecture endianess and alignment information - into account when computing data layout - \item handling all constants properly (but, well, Miri might be - replacing the old constants system) - \end{itemize} - \pause - - \item Miri can't do foreign function calls (e.g. calling functions defined - in C or C++), but there is a reasonable way it could be done with libffi. - \begin{itemize} - \item On the other hand, for constant evaluation in the compiler, you - want the evaluator to be deterministic and safe, so FFI calls might be - banned anyway. - \end{itemize} - \pause - - \item Without quite some effort, Miri will probably never handle inline - assembly... - \end{itemize} -\end{frame} - -\begin{frame} - \begin{center} - \LARGE{Questions?} - \end{center} -\end{frame} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Extra slides -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\begin{frame}[fragile] - \frametitle{\texttt{varN} vs. \texttt{argN}} - \begin{center} - \begin{minted}[autogobble,fontsize=\scriptsize]{rust} - // Rust - type Pair = (u64, u64); - fn swap((a, b): Pair) -> Pair { - (b, a) - } - - // Generated MIR - fn swap(arg0: (u64, u64)) -> (u64, u64) { - let var0: u64; // a - let var1: u64; // b - - bb0: { - var0 = arg0.0; // get the 1st part of the pair - var1 = arg0.1; // get the 2nd part of the pair - return = (var1, var0); // build a new pair in the result - goto -> bb1; - } - - bb1: { - return; - } - } - \end{minted} - \end{center} -\end{frame} - -\begin{frame}[fragile] - \frametitle{\texttt{factorial} example} - \begin{center} - \begin{minted}[autogobble,fontsize=\tiny]{rust} - // Rust - fn factorial(n: u64) -> u64 { - (1..n).fold(1, |a, b| a * b) - } - - // Generated MIR - fn factorial(arg0: u64) -> u64 { - let var0: u64; // n - let mut tmp0: Range; // Miri calculates sizes for generics like Range. - let mut tmp1: [closure]; - - bb0: { - var0 = arg0; - - // tmp0 = 1..n - tmp0 = Range { start: const 1u64, end: var0 }; - - // tmp1 = |a, b| a * b - tmp1 = [closure]; - - // This loads the MIR for the `fold` fn from the standard library. - // In general, MIR for any function from any library can be loaded. - // return tmp0.fold(1, tmp1) - return = Range::fold(tmp0, const 1u64, tmp1) -> bb1; - } - - bb1: { - return; - } - } - \end{minted} - \end{center} -\end{frame} - -\end{document} diff --git a/tex/report/latexmkrc b/tex/report/latexmkrc deleted file mode 100644 index 23aa1a481b3e..000000000000 --- a/tex/report/latexmkrc +++ /dev/null @@ -1,12 +0,0 @@ -# vim: ft=perl - -$pdf_mode = 1; -$pdflatex = 'lualatex --shell-escape %O %S'; -$out_dir = 'out'; - -# This improves latexmk's detection of source files and generated files. -$recorder = 1; - -# Ignore always-regenerated *.pyg files from the minted package when considering -# whether to run pdflatex again. -$hash_calc_ignore_pattern{'pyg'} = '.*'; diff --git a/tex/report/miri-report.tex b/tex/report/miri-report.tex deleted file mode 100644 index f8bb37b91133..000000000000 --- a/tex/report/miri-report.tex +++ /dev/null @@ -1,663 +0,0 @@ -% vim: tw=100 - -\documentclass[twocolumn]{article} -\usepackage{blindtext} -\usepackage[hypcap]{caption} -\usepackage{fontspec} -\usepackage[colorlinks, urlcolor={blue!80!black}]{hyperref} -\usepackage[outputdir=out]{minted} -\usepackage{relsize} -\usepackage{xcolor} - -\setmonofont{Source Code Pro}[ - BoldFont={* Medium}, - BoldItalicFont={* Medium Italic}, - Scale=MatchLowercase, -] - -\newcommand{\rust}[1]{\mintinline{rust}{#1}} - -\begin{document} - -\title{Miri: \\ \smaller{An interpreter for Rust's mid-level intermediate representation}} -\author{Scott Olson\footnote{\href{mailto:scott@solson.me}{scott@solson.me}} \\ - \smaller{Supervised by Christopher Dutchyn}} -\date{April 12th, 2016} -\maketitle - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Abstract} - -The increasing need for safe low-level code in contexts like operating systems and browsers is -driving the development of Rust\footnote{\url{https://www.rust-lang.org}}, a programming language -promising high performance without the risk of memory unsafety. To make programming more convenient, -it's often desirable to be able to generate code or perform some computation at compile-time. The -former is mostly covered by Rust's existing macro feature or build-time code generation, but the -latter is currently restricted to a limited form of constant evaluation capable of little beyond -simple math. - -The architecture of the compiler at the time the existing constant evaluator was built limited its -potential for future extension. However, a new intermediate representation was recently -added\footnote{\href{https://github.com/rust-lang/rfcs/blob/master/text/1211-mir.md}{Rust RFC \#1211: Mid-level IR (MIR)}} -to the Rust compiler between the abstract syntax tree and the back-end LLVM IR, called mid-level -intermediate representation, or MIR for short. This report will demonstrate that writing an -interpreter for MIR is a surprisingly effective approach for supporting a large proportion of Rust's -features in compile-time execution. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Background} - -The Rust compiler generates an instance of \rust{Mir} for each function [\autoref{fig:mir}]. Each -\rust{Mir} structure represents a control-flow graph for a given function, and contains a list of -``basic blocks'' which in turn contain a list of statements followed by a single terminator. Each -statement is of the form \rust{lvalue = rvalue}. An \rust{Lvalue} is used for referencing variables -and calculating addresses such as when dereferencing pointers, accessing fields, or indexing arrays. -An \rust{Rvalue} represents the core set of operations possible in MIR, including reading a value -from an lvalue, performing math operations, creating new pointers, structures, and arrays, and so -on. Finally, a terminator decides where control will flow next, optionally based on the value of a -boolean or integer. - -\begin{figure}[ht] - \begin{minted}[autogobble]{rust} - struct Mir { - basic_blocks: Vec, - // ... - } - - struct BasicBlockData { - statements: Vec, - terminator: Terminator, - // ... - } - - struct Statement { - lvalue: Lvalue, - rvalue: Rvalue - } - - enum Terminator { - Goto { target: BasicBlock }, - If { - cond: Operand, - targets: [BasicBlock; 2] - }, - // ... - } - \end{minted} - \caption{MIR (simplified)} - \label{fig:mir} -\end{figure} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{First implementation} - -\subsection{Basic operation} - -To investigate the possibility of executing Rust at compile-time I wrote an interpreter for MIR -called Miri\footnote{\url{https://github.com/solson/miri}}. The structure of the interpreter closely -mirrors the structure of MIR itself. It starts executing a function by iterating the statement list -in the starting basic block, translating the lvalue into a pointer and using the rvalue to decide -what to write into that pointer. Evaluating the rvalue may involve reads (such as for the two sides -of a binary operation) or construction of new values. When the terminator is reached, it is used to -decide which basic block to jump to next. Finally, Miri repeats this entire process, reading -statements from the new block. - -\subsection{Function calls} - -To handle function call terminators\footnote{Calls occur only as terminators, never as rvalues.}, -Miri is required to store some information in a virtual call stack so that it may pick up where it -left off when the callee returns. Each stack frame stores a reference to the \rust{Mir} for the -function being executed, its local variables, its return value location\footnote{Return value -pointers are passed in by callers.}, and the basic block where execution should resume. When Miri -encounters a \rust{Return} terminator in the MIR, it pops one frame off the stack and resumes the -previous function. Miri's execution ends when the function it was initially invoked with returns, -leaving the call stack empty. - -It should be noted that Miri does not itself recurse when a function is called; it merely pushes a -virtual stack frame and jumps to the top of the interpreter loop. Consequently, Miri can interpret -deeply recursive programs without overflowing its native call stack. This approach would allow Miri -to set a virtual stack depth limit and report an error when a program exceeds it. - -\subsection{Flaws} - -This version of Miri supported quite a bit of the Rust language, including booleans, integers, -if-conditions, while-loops, structures, enums, arrays, tuples, pointers, and function calls, -requiring approximately 400 lines of Rust code. However, it had a particularly naive value -representation with a number of downsides. It resembled the data layout of a dynamic language like -Ruby or Python, where every value has the same size\footnote{An \rust{enum} is a discriminated union -with a tag and space to fit the largest variant, regardless of which variant it contains.} in the -interpreter: - -\begin{minted}[autogobble]{rust} - enum Value { - Uninitialized, - Bool(bool), - Int(i64), - Pointer(Pointer), // index into stack - Aggregate { - variant: usize, - data: Pointer, - }, - } -\end{minted} - -This representation did not work well for aggregate types\footnote{That is, structures, enums, -arrays, tuples, and closures.} and required strange hacks to support them. Their contained values -were allocated elsewhere on the stack and pointed to by the aggregate value, which made it more -complicated to implement copying aggregate values from place to place. - -Moreover, while the aggregate issues could be worked around, this value representation made common -unsafe programming tricks (which make assumptions about the low-level value layout) fundamentally -impossible. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Current implementation} - -Roughly halfway through my time working on Miri, Eduard -Burtescu\footnote{\href{https://github.com/eddyb}{eddyb on GitHub}} from the Rust compiler -team\footnote{\url{https://www.rust-lang.org/team.html\#Compiler}} made a post on Rust's internal -forums about a ``Rust Abstract Machine'' -specification\footnote{\href{https://internals.rust-lang.org/t/mir-constant-evaluation/3143/31}{Burtescu's -reply on ``MIR constant evaluation''}} which could be used to implement more powerful compile-time -function execution, similar to what is supported by C++14's \mintinline{cpp}{constexpr} feature. -After clarifying some of the details of the data layout with Burtescu via IRC, I started -implementing it in Miri. - -\subsection{Raw value representation} - -The main difference in the new value representation was to represent values by ``abstract -allocations'' containing arrays of raw bytes with different sizes depending on their types. This -mimics how Rust values are represented when compiled for physical machines. In addition to the raw -bytes, allocations carry information about pointers and undefined bytes. - -\begin{minted}[autogobble]{rust} - struct Memory { - map: HashMap, - next_id: AllocId, - } - - struct Allocation { - bytes: Vec, - relocations: BTreeMap, - undef_mask: UndefMask, - } -\end{minted} - -\subsubsection{Relocations} - -The abstract machine represents pointers through ``relocations'', which are analogous to relocations -in linkers\footnote{\href{https://en.wikipedia.org/wiki/Relocation_(computing)}{Relocation -(computing) - Wikipedia}}. Instead of storing a global memory address in the raw byte representation -like on a physical machine, we store an offset from the start of the target allocation and add an -entry to the relocation table which maps the index of the offset bytes to the target allocation. - -In \autoref{fig:reloc}, the relocation stored at offset 0 in \rust{y} points to offset 2 in \rust{x} -(the 2nd 16-bit integer). Thus, the relocation table for \rust{y} is \texttt{\{0 => -x\}}, meaning the next $N$ bytes after offset 0 denote an offset into allocation \rust{x} where $N$ -is the size of a pointer (4 in this example). The example shows this as a labelled line beneath the -offset bytes. - -In effect, the abstract machine represents pointers as \rust{(allocation_id, offset)} pairs. This -makes it easy to detect when pointer accesses go out of bounds. - -\begin{figure}[hb] - \begin{minted}[autogobble]{rust} - let x: [i16; 3] = [0xAABB, 0xCCDD, 0xEEFF]; - let y = &x[1]; - // x: BB AA DD CC FF EE (6 bytes) - // y: 02 00 00 00 (4 bytes) - // └───(x)───┘ - \end{minted} - \caption{Example relocation on 32-bit little-endian} - \label{fig:reloc} -\end{figure} - -\subsubsection{Undefined byte mask} - -The final piece of an abstract allocation is the undefined byte mask. Logically, we store a boolean -for the definedness of every byte in the allocation, but there are multiple ways to make the storage -more compact. I tried two implementations: one based on the endpoints of alternating ranges of -defined and undefined bytes and the other based on a bitmask. The former is more compact but I found -it surprisingly difficult to update cleanly. I currently use the much simpler bitmask system. - -See \autoref{fig:undef} for an example of an undefined byte in a value, represented by underscores. -Note that there is a value for the second byte in the byte array, but it doesn't matter what it is. -The bitmask would be $10_2$, i.e.\ \rust{[true, false]}. - -\begin{figure}[hb] - \begin{minted}[autogobble]{rust} - let x: [u8; 2] = unsafe { - [1, std::mem::uninitialized()] - }; - // x: 01 __ (2 bytes) - \end{minted} - \caption{Example undefined byte} - \label{fig:undef} -\end{figure} - -\subsection{Computing data layout} - -Currently, the Rust compiler's data layouts for types are hidden from Miri, so it does its own data -layout computation which will not always match what the compiler does, since Miri doesn't take -target type alignments into account. In the future, the Rust compiler may be modified so that Miri -can use the exact same data layout. - -Miri's data layout calculation is a relatively simple transformation from Rust types to a structure -with constant size values for primitives and sets of fields with offsets for aggregate types. These -layouts are cached for performance. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Deterministic execution} -\label{sec:deterministic} - -In order to be effective as a compile-time evaluator, Miri must have \emph{deterministic execution}, -as explained by Burtescu in the ``Rust Abstract Machine'' post. That is, given a function and -arguments to that function, Miri should always produce identical results. This is important for -coherence in the type checker when constant evaluations are involved in types, such as for sizes of -array types: - -\begin{minted}[autogobble,mathescape]{rust} - const fn get_size() -> usize { /* $\ldots$ */ } - let array: [i32; get_size()]; -\end{minted} - -Since Miri allows execution of unsafe code\footnote{In fact, the distinction between safe and unsafe -doesn't exist at the MIR level.}, it is specifically designed to remain safe while interpreting -potentially unsafe code. When Miri encounters an unrecoverable error, it reports it via the Rust -compiler's usual error reporting mechanism, pointing to the part of the original code where the -error occurred. Below is an example from Miri's -repository.\footnote{\href{https://github.com/solson/miri/blob/master/test/errors.rs}{miri/test/errors.rs}} - -\begin{minted}[autogobble]{rust} - let b = Box::new(42); - let p: *const i32 = &*b; - drop(b); - unsafe { *p } - // ~~ error: dangling pointer - // was dereferenced -\end{minted} -\label{dangling-pointer} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Language support} - -In its current state, Miri supports a large proportion of the Rust language, detailed below. The -major exception is a lack of support for FFI\footnote{Foreign Function Interface, e.g.\ calling -functions defined in Assembly, C, or C++.}, which eliminates possibilities like reading and writing -files, user input, graphics, and more. However, for compile-time evaluation in Rust, this limitation -is desired. - -\subsection{Primitives} - -Miri supports booleans, integers of various sizes and signed-ness (i.e.\ \rust{i8}, \rust{i16}, -\rust{i32}, \rust{i64}, \rust{isize}, \rust{u8}, \rust{u16}, \rust{u32}, \rust{u64}, \rust{usize}), -and unary and binary operations over these types. The \rust{isize} and \rust{usize} types will be -sized according to the target machine's pointer size just like in compiled Rust. The \rust{char} and -float types (\rust{f32}, \rust{f64}) are not supported yet, but there are no known barriers to doing -so. - -When examining a boolean in an \rust{if} condition, Miri will report an error if its byte -representation is not precisely 0 or 1, since having any other value for a boolean is undefined -behaviour in Rust. The \rust{char} type will have similar restrictions once it is implemented. - -\subsection{Pointers} - -Both references and raw pointers are supported, with essentially no difference between them in Miri. -It is also possible to do pointer comparisons and math. However, a few operations are considered -errors and a few require special support. - -Firstly, pointers into the same allocations may be compared for ordering, but pointers into -different allocations are considered unordered and Miri will complain if you attempt this. The -reasoning is that different allocations may have different orderings in the global address space at -runtime, making this non-deterministic. However, pointers into different allocations \emph{may} be -compared for direct equality (they are always unequal). - -Secondly, pointers represented using relocations may be compared against pointers casted from -integers (e.g.\ \rust{0 as *const i32}) for things like null pointer checks. To handle these cases, -Miri has a concept of ``integer pointers'' which are always unequal to abstract pointers. Integer -pointers can be compared and operated upon freely. However, note that it is impossible to go from an -integer pointer to an abstract pointer backed by a relocation. It is not valid to dereference an -integer pointer. - -\subsubsection{Slice pointers} - -Rust supports pointers to ``dynamically-sized types'' such as \rust{[T]} and \rust{str} which -represent arrays of indeterminate size. Pointers to such types contain an address \emph{and} the -length of the referenced array. Miri supports these fully. - -\subsubsection{Trait objects} - -Rust also supports pointers to ``trait objects'' which represent some type that implements a trait, -with the specific type unknown at compile-time. These are implemented using virtual dispatch with a -vtable, similar to virtual methods in C++. Miri does not currently support these at all. - -\subsection{Aggregates} - -Aggregates include types declared with \rust{struct} or \rust{enum} as well as tuples, arrays, and -closures. Miri supports all common usage of all of these types. The main missing piece is to handle -\texttt{\#[repr(..)]} annotations which adjust the layout of a \rust{struct} or \rust{enum}. - -\subsection{Lvalue projections} - -This category includes field accesses, dereferencing, accessing data in an \rust{enum} variant, and -indexing arrays. Miri supports all of these, including nested projections such as -\rust{*foo.bar[2]}. - -\subsection{Control flow} - -All of Rust's standard control flow features, including \rust{loop}, \rust{while}, \rust{for}, -\rust{if}, \rust{if let}, \rust{while let}, \rust{match}, \rust{break}, \rust{continue}, and -\rust{return} are supported. In fact, supporting these was quite easy since the Rust compiler -reduces them all down to a small set of control-flow graph primitives in MIR. - -\subsection{Function calls} - -As previously described, Miri supports arbitrary function calls without growing the native stack -(only its virtual call stack). It is somewhat limited by the fact that cross-crate\footnote{A crate -is a single Rust library (or executable).} calls only work for functions whose MIR is stored in -crate metadata. This is currently true for \rust{const}, generic, and inline functions. -A branch of the compiler could be made that stores MIR for all functions. This would be a non-issue -for a compile-time evaluator based on Miri, since it would only call \rust{const fn}s. - -\subsubsection{Method calls} - -Miri supports trait method calls, including invoking all the compiler-internal lookup needed to find -the correct implementation of the method. - -\subsubsection{Closures} - -Calls to closures are also supported with the exception of one edge case\footnote{Calling a closure -that takes a reference to its captures via a closure interface that passes the captures by value is -not yet supported.}. The value part of a closure that holds the captured variables is handled as an -aggregate and the function call part is mostly the same as a trait method call, but with the added -complication that closures use a separate calling convention within the compiler. - -\subsubsection{Function pointers} - -Function pointers are not currently supported by Miri, but there is a relatively simple way they -could be encoded using a relocation with a special reserved allocation identifier. The offset of the -relocation would determine which function it points to in a special array of functions in the -interpreter. - -\subsubsection{Intrinsics} - -To support unsafe code, and in particular to support Rust's standard library, it became clear that -Miri would have to support calls to compiler -intrinsics\footnote{\url{https://doc.rust-lang.org/stable/std/intrinsics/index.html}}. Intrinsics -are function calls which cause the Rust compiler to produce special-purpose code instead of a -regular function call. Miri simply recognizes intrinsic calls by their unique -ABI\footnote{Application Binary Interface, which defines calling conventions. Includes ``C'', -``Rust'', and ``rust-intrinsic''.} and name and runs special-purpose code to handle them. - -An example of an important intrinsic is \rust{size_of} which will cause Miri to write the size of -the type in question to the return value location. The Rust standard library uses intrinsics heavily -to implement various data structures, so this was a major step toward supporting them. Intrinsics -have been implemented on a case-by-case basis as tests which required them were written, and not all -intrinsics are supported yet. - -\subsubsection{Generic function calls} - -Miri needs special support for generic function calls since Rust is a \emph{monomorphizing} -compiler, meaning it generates a special version of each function for each distinct set of type -parameters it gets called with. Since functions in MIR are still polymorphic, Miri has to do the -same thing and substitute function type parameters into all types it encounters to get fully -concrete, monomorphized types. For example, in\ldots - -\begin{minted}[autogobble]{rust} - fn some(t: T) -> Option { Some(t) } -\end{minted} - -\ldots{}Miri needs to know the size of \rust{T} to copy the right amount of bytes from the argument -to the return value. If we call \rust{some(10i32)} Miri will execute \rust{some} knowing that -\rust{T = i32} and generate a representation for \rust{Option}. - -Miri currently does this monomorphization lazily on-demand unlike the Rust back-end which does it -all ahead of time. - -\subsection{Heap allocations} - -The next piece of the puzzle for supporting interesting programs (and the standard library) was heap -allocations. There are two main interfaces for heap allocation in Rust: the built-in \rust{Box} -rvalue in MIR and a set of C ABI foreign functions including \rust{__rust_allocate}, -\rust{__rust_reallocate}, and \rust{__rust_deallocate}. These correspond approximately to -\mintinline{c}{malloc}, \mintinline{c}{realloc}, and \mintinline{c}{free} in C. - -The \rust{Box} rvalue allocates enough space for a single value of a given type. This was easy to -support in Miri. It simply creates a new abstract allocation in the same manner as for -stack-allocated values, since there's no major difference between them in Miri. - -The allocator functions, which are used to implement things like Rust's standard \rust{Vec} type, -were a bit trickier. Rust declares them as \rust{extern "C" fn} so that different allocator -libraries can be linked in at the user's option. Since Miri doesn't actually support FFI and wants -full control of allocations for safety, it ``cheats'' and recognizes these allocator functions in -essentially the same way it recognizes compiler intrinsics. Then, a call to \rust{__rust_allocate} -simply creates another abstract allocation with the requested size and \rust{__rust_reallocate} -grows one. - -In the future, Miri should also track which allocations came from \rust{__rust_allocate} so it can -reject reallocate or deallocate calls on stack allocations. - -\subsection{Destructors} - -When a value which ``owns'' some resource (like a heap allocation or file handle) goes out of scope, -Rust inserts \emph{drop glue} that calls the user-defined destructor for the type if it has one, and -then drops all of the subfields. Destructors for types like \rust{Box} and \rust{Vec} -deallocate heap memory. - -Miri doesn't yet support calling user-defined destructors, but it has most of the machinery in place -to do so already. There \emph{is} support for dropping \rust{Box} types, including deallocating -their associated allocations. This is enough to properly execute the dangling pointer example in -\autoref{sec:deterministic}. - -\subsection{Constants} - -Only basic integer, boolean, string, and byte-string literals are currently supported. Evaluating -more complicated constant expressions in their current form would be a somewhat pointless exercise -for Miri. Instead, we should lower constant expressions to MIR so Miri can run them directly, which -is precisely what would need be done to use Miri as the compiler's constant evaluator. - -\subsection{Static variables} - -Miri doesn't currently support statics, but they would need support similar to constants. Also note -that while it would be invalid to write to static (i.e.\ global) variables in Miri executions, it -would probably be fine to allow reads. - -\subsection{Standard library} - -Throughout the implementation of the above features, I often followed this process: - -\begin{enumerate} - \item Try using a feature from the standard library. - \item See where Miri runs into stuff it can't handle. - \item Fix the problem. - \item Go to 1. -\end{enumerate} - -At present, Miri supports a number of major non-trivial features from the standard library along -with tons of minor features. Smart pointer types such as \rust{Box}, \rust{Rc}\footnote{Reference -counted shared pointer} and \rust{Arc}\footnote{Atomically reference-counted thread-safe shared -pointer} all seem to work. I've also tested using the shared smart pointer types with \rust{Cell} -and \rust{RefCell}\footnote{\href{https://doc.rust-lang.org/stable/std/cell/index.html}{Rust -documentation for cell types}} for internal mutability, and that works as well, although -\rust{RefCell} can't ever be borrowed twice until I implement destructor calls, since a destructor -is what releases the borrow. - -But the standard library collection I spent the most time on was \rust{Vec}, the standard -dynamically-growable array type, similar to C++'s \texttt{std::vector} or Java's -\texttt{java.util.ArrayList}. In Rust, \rust{Vec} is an extremely pervasive collection, so -supporting it is a big win for supporting a larger swath of Rust programs in Miri. - -See \autoref{fig:vec} for an example (working in Miri today) of initializing a \rust{Vec} with a -small amount of space on the heap and then pushing enough elements to force it to reallocate its -data array. This involves cross-crate generic function calls, unsafe code using raw pointers, heap -allocation, handling of uninitialized memory, compiler intrinsics, and more. - -\begin{figure}[t] - \begin{minted}[autogobble]{rust} - struct Vec { - data: *mut T, // 4 byte pointer - capacity: usize, // 4 byte integer - length: usize, // 4 byte integer - } - - let mut v: Vec = - Vec::with_capacity(2); - // v: 00 00 00 00 02 00 00 00 00 00 00 00 - // └─(data)──┘ - // data: __ __ - - v.push(1); - // v: 00 00 00 00 02 00 00 00 01 00 00 00 - // └─(data)──┘ - // data: 01 __ - - v.push(2); - // v: 00 00 00 00 02 00 00 00 02 00 00 00 - // └─(data)──┘ - // data: 01 02 - - v.push(3); - // v: 00 00 00 00 04 00 00 00 03 00 00 00 - // └─(data)──┘ - // data: 01 02 03 __ - \end{minted} - \caption{\rust{Vec} example on 32-bit little-endian} - \label{fig:vec} -\end{figure} - -Miri supports unsafe operations on \rust{Vec} like \rust{v.set_len(10)} or -\rust{v.get_unchecked(2)}, provided that such calls do no invoke undefined behaviour. If a call -\emph{does} invoke undefined behaviour, Miri will abort with an appropriate error message (see -\autoref{fig:vec-error}). - -\begin{figure}[t] - \begin{minted}[autogobble]{rust} - fn out_of_bounds() -> u8 { - let v = vec![1, 2]; - let p = unsafe { v.get_unchecked(5) }; - *p + 10 - // ~~ error: pointer offset outside - // bounds of allocation - } - - fn undefined_bytes() -> u8 { - let v = Vec::::with_capacity(10); - let p = unsafe { v.get_unchecked(5) }; - *p + 10 - // ~~~~~~~ error: attempted to read - // undefined bytes - } - \end{minted} - \caption{\rust{Vec} examples with undefined behaviour} - \label{fig:vec-error} -\end{figure} - -\newpage - -Here is one final code sample Miri can execute that demonstrates many features at once, including -vectors, heap allocation, iterators, closures, raw pointers, and math: - -\begin{minted}[autogobble]{rust} - let x: u8 = vec![1, 2, 3, 4] - .into_iter() - .map(|x| x * x) - .fold(0, |x, y| x + y); - // x: 1e (that is, the hex value - // 0x1e = 30 = 1 + 4 + 9 + 16) -\end{minted} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Future directions} - -\subsection{Finishing the implementation} - -There are a number of pressing items on my to-do list for Miri, including: - -\begin{itemize} - \item A much more comprehensive and automated test suite. - \item User-defined destructor calls. - \item Non-trivial casts between primitive types like integers and pointers. - \item Handling statics and global memory. - \item Reporting errors for all undefined behaviour.\footnote{\href{https://doc.rust-lang.org/reference.html\#behavior-considered-undefined}{The Rust reference on what is considered undefined behaviour}} - \item Function pointers. - \item Accounting for target machine primitive type alignment and endianness. - \item Optimizations (undefined byte masks, tail-calls). - \item Benchmarking Miri vs. unoptimized Rust. - \item Various \texttt{TODO}s and \texttt{FIXME}s left in the code. - \item Integrating into the compiler proper. -\end{itemize} - -\subsection{Future projects} - -Other possible Miri-related projects include: - -\begin{itemize} - \item A read-eval-print-loop (REPL) for Rust, which may be easier to implement on top of Miri than - the usual LLVM back-end. - \item A graphical or text-mode debugger that steps through MIR execution one statement at a time, - for figuring out why some compile-time execution is raising an error or simply learning how Rust - works at a low level. - \item A less restricted version of Miri that is able to run foreign functions from C/C++ and - generally has full access to the operating system. Such an interpreter could be used to more - quickly prototype changes to the Rust language that would otherwise require changes to the LLVM - back-end. - \item Unit-testing the compiler by comparing the results of Miri's execution against the results - of LLVM-compiled machine code's execution. This would help to guarantee that compile-time - execution works the same as runtime execution. - \item Some kind of Miri-based symbolic evaluator that examines multiple possible code paths at - once to determine if undefined behaviour could be observed on any of them. -\end{itemize} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Final thoughts} - -Writing an interpreter which models values of varying sizes, stack and heap allocation, unsafe -memory operations, and more requires some unconventional techniques compared to conventional -interpreters targeting dynamically-typed languages. However, aside from the somewhat complicated -abstract memory model, making Miri work was primarily a software engineering problem, and not a -particularly tricky one. This is a testament to MIR's suitability as an intermediate representation -for Rust---removing enough unnecessary abstraction to keep it simple. For example, Miri doesn't even -need to know that there are different kinds of loops, or how to match patterns in a \rust{match} -expression. - -Another advantage to targeting MIR is that any new features at the syntax-level or type-level -generally require little to no change in Miri. For example, when the new ``question mark'' syntax -for error handling\footnote{ - \href{https://github.com/rust-lang/rfcs/blob/master/text/0243-trait-based-exception-handling.md} - {Question mark syntax RFC}} -was added to rustc, Miri required no change to support it. -When specialization\footnote{ - \href{https://github.com/rust-lang/rfcs/blob/master/text/1210-impl-specialization.md} - {Specialization RFC}} -was added, Miri supported it with just minor changes to trait method lookup. - -Of course, Miri also has limitations. The inability to execute FFI and inline assembly reduces the -amount of Rust programs Miri could ever execute. The good news is that in the constant evaluator, -FFI can be stubbed out in cases where it makes sense, like I did with \rust{__rust_allocate}. For a -version of Miri not intended for constant evaluation, it may be possible to use libffi to call C -functions from the interpreter. - -In conclusion, Miri is a surprisingly effective project, and a lot of fun to implement. Due to MIR's -tendency to collapse multiple source-level features into one, I often ended up supporting features I -hadn't explicitly intended to. I am excited to work with the compiler team going forward to try to -make Miri useful for constant evaluation in Rust. - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\section{Thanks} - -A big thanks goes to Eduard Burtescu for writing the abstract machine specification and answering my -incessant questions on IRC, to Niko Matsakis for coming up with the idea for Miri and supporting my -desire to work with the Rust compiler, and to my research supervisor Christopher Dutchyn. Thanks -also to everyone else on the compiler team and on Mozilla IRC who helped me figure stuff out. -Finally, thanks to Daniel Keep and everyone else who helped fix my numerous writing mistakes. - -\end{document} diff --git a/xargo/Cargo.lock b/xargo/Cargo.lock deleted file mode 100644 index 031ad9a87954..000000000000 --- a/xargo/Cargo.lock +++ /dev/null @@ -1,4 +0,0 @@ -[root] -name = "miri-xargo" -version = "0.0.0" - diff --git a/xargo/Cargo.toml b/xargo/Cargo.toml deleted file mode 100644 index 9129c105b112..000000000000 --- a/xargo/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "miri-xargo" -description = "A dummy project for building libstd with xargo." -version = "0.0.0" - -[dependencies] diff --git a/xargo/Xargo.toml b/xargo/Xargo.toml deleted file mode 100644 index 4b650b97de56..000000000000 --- a/xargo/Xargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[dependencies] -std = {features = ["panic_unwind", "jemalloc", "backtrace"]} diff --git a/xargo/build.sh b/xargo/build.sh deleted file mode 100755 index 15a7c770910d..000000000000 --- a/xargo/build.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -cd "$(dirname "$0")" -RUSTFLAGS='-Zalways-encode-mir -Zmir-emit-validate=1' xargo build diff --git a/xargo/src/lib.rs b/xargo/src/lib.rs deleted file mode 100644 index e69de29bb2d1..000000000000