From f8a484e81cff505dd29c7054ee72e2cd0b0e6c97 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 15 Apr 2023 13:24:28 +0000 Subject: [PATCH 1/7] Add miri tests. --- .../dangling_pointer_deref_match_never.rs | 17 +++++++++++++++++ .../dangling_pointer_deref_match_never.stderr | 15 +++++++++++++++ .../dangling_pointer_deref_match_underscore.rs | 14 ++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs create mode 100644 tests/fail/dangling_pointers/dangling_pointer_deref_match_never.stderr create mode 100644 tests/pass/dangling_pointer_deref_match_underscore.rs diff --git a/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs b/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs new file mode 100644 index 0000000000..723c3f1e15 --- /dev/null +++ b/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs @@ -0,0 +1,17 @@ +// Make sure we find these even with many checks disabled. +//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation + +#![allow(unreachable_code)] +#![feature(never_type)] + +fn main() { + let p = { + let b = Box::new(42); + &*b as *const i32 as *const ! + }; + unsafe { + match *p {} //~ ERROR: entering unreachable code + } + panic!("this should never print"); +} + diff --git a/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.stderr b/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.stderr new file mode 100644 index 0000000000..2ca6fd028b --- /dev/null +++ b/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: entering unreachable code + --> $DIR/dangling_pointer_deref_match_never.rs:LL:CC + | +LL | match *p {} + | ^^ entering unreachable code + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/dangling_pointer_deref_match_never.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + diff --git a/tests/pass/dangling_pointer_deref_match_underscore.rs b/tests/pass/dangling_pointer_deref_match_underscore.rs new file mode 100644 index 0000000000..c3cff1f428 --- /dev/null +++ b/tests/pass/dangling_pointer_deref_match_underscore.rs @@ -0,0 +1,14 @@ +// A `_` binding in a match is a nop, so we do not detect that the pointer is dangling. +//@compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation + +fn main() { + let p = { + let b = Box::new(42); + &*b as *const i32 + }; + unsafe { + match *p { + _ => {} + } + } +} From 2e6e707c3f0f58f9c988f53563b360700232df8c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 10 Sep 2023 09:38:04 +0000 Subject: [PATCH 2/7] Add miri test matching on `!`. --- tests/fail/never_match_never.rs | 10 ++++++++++ tests/fail/never_match_never.stderr | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/fail/never_match_never.rs create mode 100644 tests/fail/never_match_never.stderr diff --git a/tests/fail/never_match_never.rs b/tests/fail/never_match_never.rs new file mode 100644 index 0000000000..5f2f471bf6 --- /dev/null +++ b/tests/fail/never_match_never.rs @@ -0,0 +1,10 @@ +// This should fail even without validation +//@compile-flags: -Zmiri-disable-validation + +#![feature(never_type)] +#![allow(unreachable_code)] + +fn main() { + let ptr: *const (i32, !) = &0i32 as *const i32 as *const _; + unsafe { match (*ptr).1 {} } //~ ERROR: entering unreachable code +} diff --git a/tests/fail/never_match_never.stderr b/tests/fail/never_match_never.stderr new file mode 100644 index 0000000000..33dab81d5b --- /dev/null +++ b/tests/fail/never_match_never.stderr @@ -0,0 +1,15 @@ +error: Undefined Behavior: entering unreachable code + --> $DIR/never_match_never.rs:LL:CC + | +LL | unsafe { match (*ptr).1 {} } + | ^^^^^^^^ entering unreachable code + | + = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior + = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information + = note: BACKTRACE: + = note: inside `main` at $DIR/never_match_never.rs:LL:CC + +note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace + +error: aborting due to previous error + From 479374f241a2fa7a44910fa0a92c0ac4c73a14c3 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Tue, 24 Oct 2023 16:22:32 +0000 Subject: [PATCH 3/7] Test match underscore on void from union. --- .../pass/union-uninhabited-match-underscore.rs | 17 +++++++++++++++++ .../union-uninhabited-match-underscore.stdout | 1 + 2 files changed, 18 insertions(+) create mode 100644 tests/pass/union-uninhabited-match-underscore.rs create mode 100644 tests/pass/union-uninhabited-match-underscore.stdout diff --git a/tests/pass/union-uninhabited-match-underscore.rs b/tests/pass/union-uninhabited-match-underscore.rs new file mode 100644 index 0000000000..33db9c2d34 --- /dev/null +++ b/tests/pass/union-uninhabited-match-underscore.rs @@ -0,0 +1,17 @@ +fn main() { + #[derive(Copy, Clone)] + enum Void {} + union Uninit { + value: T, + uninit: (), + } + unsafe { + let x: Uninit = Uninit { uninit: () }; + match x.value { + // rustc warns about un unreachable pattern, + // but is wrong in unsafe code. + #[allow(unreachable_patterns)] + _ => println!("hi from the void!"), + } + } +} diff --git a/tests/pass/union-uninhabited-match-underscore.stdout b/tests/pass/union-uninhabited-match-underscore.stdout new file mode 100644 index 0000000000..ff731696f0 --- /dev/null +++ b/tests/pass/union-uninhabited-match-underscore.stdout @@ -0,0 +1 @@ +hi from the void! From 0a1036dd755f378e35fc85ed9874b1a7ab2732cf Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Mon, 16 Oct 2023 22:11:57 +0200 Subject: [PATCH 4/7] Stop telling people to submit bugs for internal feature ICEs This keeps track of usage of internal features, and changes the message to instead tell them that using internal features is not supported. See MCP 620. --- src/bin/miri.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index fc6151772a..531128ed2e 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -241,6 +241,7 @@ fn run_compiler( mut args: Vec, target_crate: bool, callbacks: &mut (dyn rustc_driver::Callbacks + Send), + using_internal_features: std::sync::Arc ) -> ! { if target_crate { // Miri needs a custom sysroot for target crates. @@ -273,7 +274,8 @@ fn run_compiler( // Invoke compiler, and handle return code. let exit_code = rustc_driver::catch_with_exit_code(move || { - rustc_driver::RunCompiler::new(&args, callbacks).run() + rustc_driver::RunCompiler::new(&args, callbacks) + .set_using_internal_features(using_internal_features).run() }); std::process::exit(exit_code) } @@ -295,7 +297,7 @@ fn main() { // If the environment asks us to actually be rustc, then do that. if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") { // Earliest rustc setup. - rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); + let using_internal_features = rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); rustc_driver::init_rustc_env_logger(&handler); let target_crate = if crate_kind == "target" { @@ -311,11 +313,12 @@ fn main() { env::args().collect(), target_crate, &mut MiriBeRustCompilerCalls { target_crate }, + using_internal_features, ) } // Add an ICE bug report hook. - rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); + let using_internal_features = rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); // Init loggers the Miri way. init_early_loggers(&handler); @@ -578,5 +581,5 @@ fn main() { debug!("rustc arguments: {:?}", rustc_args); debug!("crate arguments: {:?}", miri_config.args); - run_compiler(rustc_args, /* target_crate: */ true, &mut MiriCompilerCalls { miri_config }) + run_compiler(rustc_args, /* target_crate: */ true, &mut MiriCompilerCalls { miri_config }, using_internal_features) } From ca04ddf3ffb47048039dcc20aeeea28b0626fdad Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sun, 4 Sep 2022 21:13:44 +0400 Subject: [PATCH 5/7] Stabilize `[const_]pointer_byte_offsets` --- tests/fail/dangling_pointers/out_of_bounds_read.rs | 2 -- tests/fail/dangling_pointers/out_of_bounds_write.rs | 2 -- tests/pass/provenance.rs | 1 - 3 files changed, 5 deletions(-) diff --git a/tests/fail/dangling_pointers/out_of_bounds_read.rs b/tests/fail/dangling_pointers/out_of_bounds_read.rs index f6b8a1ad55..658fbd16c2 100644 --- a/tests/fail/dangling_pointers/out_of_bounds_read.rs +++ b/tests/fail/dangling_pointers/out_of_bounds_read.rs @@ -1,5 +1,3 @@ -#![feature(pointer_byte_offsets)] - fn main() { let v: Vec = vec![1, 2]; // This read is also misaligned. We make sure that the OOB message has priority. diff --git a/tests/fail/dangling_pointers/out_of_bounds_write.rs b/tests/fail/dangling_pointers/out_of_bounds_write.rs index 4ead91744c..2ff537b1ff 100644 --- a/tests/fail/dangling_pointers/out_of_bounds_write.rs +++ b/tests/fail/dangling_pointers/out_of_bounds_write.rs @@ -1,5 +1,3 @@ -#![feature(pointer_byte_offsets)] - fn main() { let mut v: Vec = vec![1, 2]; // This read is also misaligned. We make sure that the OOB message has priority. diff --git a/tests/pass/provenance.rs b/tests/pass/provenance.rs index 835daa36cf..9e8a9651b3 100644 --- a/tests/pass/provenance.rs +++ b/tests/pass/provenance.rs @@ -1,7 +1,6 @@ //@revisions: stack tree //@[tree]compile-flags: -Zmiri-tree-borrows #![feature(strict_provenance)] -#![feature(pointer_byte_offsets)] use std::{mem, ptr}; const PTR_SIZE: usize = mem::size_of::<&i32>(); From 735a3ef1d918423f04897d6a495e830f5eaf3520 Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Sat, 28 Oct 2023 05:11:15 +0000 Subject: [PATCH 6/7] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 60ae5d1259..6ded1ea1c5 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -2e4e2a8f288f642cafcc41fff211955ceddc453d +20952db40d5220e8a15c2e569ae480877bbc8417 From 06a78be752b361bc28774c2dfdc121224a7db39c Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Sat, 28 Oct 2023 05:22:14 +0000 Subject: [PATCH 7/7] fmt --- src/bin/miri.rs | 18 +++++++++++++----- .../dangling_pointer_deref_match_never.rs | 1 - 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/bin/miri.rs b/src/bin/miri.rs index 531128ed2e..cd628444fe 100644 --- a/src/bin/miri.rs +++ b/src/bin/miri.rs @@ -241,7 +241,7 @@ fn run_compiler( mut args: Vec, target_crate: bool, callbacks: &mut (dyn rustc_driver::Callbacks + Send), - using_internal_features: std::sync::Arc + using_internal_features: std::sync::Arc, ) -> ! { if target_crate { // Miri needs a custom sysroot for target crates. @@ -275,7 +275,8 @@ fn run_compiler( // Invoke compiler, and handle return code. let exit_code = rustc_driver::catch_with_exit_code(move || { rustc_driver::RunCompiler::new(&args, callbacks) - .set_using_internal_features(using_internal_features).run() + .set_using_internal_features(using_internal_features) + .run() }); std::process::exit(exit_code) } @@ -297,7 +298,8 @@ fn main() { // If the environment asks us to actually be rustc, then do that. if let Some(crate_kind) = env::var_os("MIRI_BE_RUSTC") { // Earliest rustc setup. - let using_internal_features = rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); + let using_internal_features = + rustc_driver::install_ice_hook(rustc_driver::DEFAULT_BUG_REPORT_URL, |_| ()); rustc_driver::init_rustc_env_logger(&handler); let target_crate = if crate_kind == "target" { @@ -318,7 +320,8 @@ fn main() { } // Add an ICE bug report hook. - let using_internal_features = rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); + let using_internal_features = + rustc_driver::install_ice_hook("https://github.com/rust-lang/miri/issues/new", |_| ()); // Init loggers the Miri way. init_early_loggers(&handler); @@ -581,5 +584,10 @@ fn main() { debug!("rustc arguments: {:?}", rustc_args); debug!("crate arguments: {:?}", miri_config.args); - run_compiler(rustc_args, /* target_crate: */ true, &mut MiriCompilerCalls { miri_config }, using_internal_features) + run_compiler( + rustc_args, + /* target_crate: */ true, + &mut MiriCompilerCalls { miri_config }, + using_internal_features, + ) } diff --git a/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs b/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs index 723c3f1e15..e77c8e06a0 100644 --- a/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs +++ b/tests/fail/dangling_pointers/dangling_pointer_deref_match_never.rs @@ -14,4 +14,3 @@ fn main() { } panic!("this should never print"); } -