From df3a5693dd053f9e8d7df4432682808cd189e0a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Thu, 9 Nov 2023 00:00:00 +0000 Subject: [PATCH 1/2] Custom MIR: Support cleanup blocks Cleanup blocks are declared with `bb (cleanup) = { ... }`. `Call` and `Drop` terminators take an additional argument describing the unwind action, which is one of the following: * `UnwindContinue()` * `UnwindUnreachable()` * `UnwindTerminate(reason)`, where reason is `ReasonAbi` or `ReasonInCleanup` * `UnwindCleanup(block)` Also support unwind resume and unwind terminate terminators: * `UnwindResume()` * `UnwindTerminate(reason)` --- tests/fail/function_calls/arg_inplace_mutate.rs | 2 +- tests/fail/function_calls/arg_inplace_mutate.stack.stderr | 4 ++-- tests/fail/function_calls/arg_inplace_mutate.tree.stderr | 4 ++-- tests/fail/function_calls/arg_inplace_observe_after.rs | 2 +- .../function_calls/arg_inplace_observe_during.none.stderr | 4 ++-- tests/fail/function_calls/arg_inplace_observe_during.rs | 2 +- .../function_calls/arg_inplace_observe_during.stack.stderr | 4 ++-- .../function_calls/arg_inplace_observe_during.tree.stderr | 4 ++-- tests/fail/function_calls/return_pointer_aliasing.none.stderr | 4 ++-- tests/fail/function_calls/return_pointer_aliasing.rs | 2 +- .../fail/function_calls/return_pointer_aliasing.stack.stderr | 4 ++-- tests/fail/function_calls/return_pointer_aliasing.tree.stderr | 4 ++-- tests/fail/function_calls/return_pointer_aliasing2.rs | 2 +- .../fail/function_calls/return_pointer_aliasing2.stack.stderr | 4 ++-- .../fail/function_calls/return_pointer_aliasing2.tree.stderr | 4 ++-- tests/fail/function_calls/return_pointer_on_unwind.rs | 4 ++-- tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs | 2 +- tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr | 4 ++-- tests/pass/function_calls/return_place_on_heap.rs | 2 +- 19 files changed, 31 insertions(+), 31 deletions(-) diff --git a/tests/fail/function_calls/arg_inplace_mutate.rs b/tests/fail/function_calls/arg_inplace_mutate.rs index d47af50d40..e79bd70e91 100644 --- a/tests/fail/function_calls/arg_inplace_mutate.rs +++ b/tests/fail/function_calls/arg_inplace_mutate.rs @@ -14,7 +14,7 @@ fn main() { let ptr = std::ptr::addr_of_mut!(non_copy); // Inside `callee`, the first argument and `*ptr` are basically // aliasing places! - Call(_unit = callee(Move(*ptr), ptr), after_call) + Call(_unit = callee(Move(*ptr), ptr), after_call, UnwindContinue()) } after_call = { Return() diff --git a/tests/fail/function_calls/arg_inplace_mutate.stack.stderr b/tests/fail/function_calls/arg_inplace_mutate.stack.stderr index 381442e69b..ccf9732ed0 100644 --- a/tests/fail/function_calls/arg_inplace_mutate.stack.stderr +++ b/tests/fail/function_calls/arg_inplace_mutate.stack.stderr @@ -27,8 +27,8 @@ LL | unsafe { ptr.write(S(0)) }; note: inside `main` --> $DIR/arg_inplace_mutate.rs:LL:CC | -LL | Call(_unit = callee(Move(*ptr), ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_unit = callee(Move(*ptr), ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/arg_inplace_mutate.tree.stderr b/tests/fail/function_calls/arg_inplace_mutate.tree.stderr index 3d8ba68547..e7baf6e23d 100644 --- a/tests/fail/function_calls/arg_inplace_mutate.tree.stderr +++ b/tests/fail/function_calls/arg_inplace_mutate.tree.stderr @@ -35,8 +35,8 @@ LL | unsafe { ptr.write(S(0)) }; note: inside `main` --> $DIR/arg_inplace_mutate.rs:LL:CC | -LL | Call(_unit = callee(Move(*ptr), ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_unit = callee(Move(*ptr), ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/arg_inplace_observe_after.rs b/tests/fail/function_calls/arg_inplace_observe_after.rs index ea773048dd..e4c00fdd84 100644 --- a/tests/fail/function_calls/arg_inplace_observe_after.rs +++ b/tests/fail/function_calls/arg_inplace_observe_after.rs @@ -11,7 +11,7 @@ fn main() { { let non_copy = S(42); // This could change `non_copy` in-place - Call(_unit = change_arg(Move(non_copy)), after_call) + Call(_unit = change_arg(Move(non_copy)), after_call, UnwindContinue()) } after_call = { // So now we must not be allowed to observe non-copy again. diff --git a/tests/fail/function_calls/arg_inplace_observe_during.none.stderr b/tests/fail/function_calls/arg_inplace_observe_during.none.stderr index cba23c21d1..f8140d0236 100644 --- a/tests/fail/function_calls/arg_inplace_observe_during.none.stderr +++ b/tests/fail/function_calls/arg_inplace_observe_during.none.stderr @@ -11,8 +11,8 @@ LL | unsafe { ptr.read() }; note: inside `main` --> $DIR/arg_inplace_observe_during.rs:LL:CC | -LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/arg_inplace_observe_during.rs b/tests/fail/function_calls/arg_inplace_observe_during.rs index 8c6a7df7a6..517abd733a 100644 --- a/tests/fail/function_calls/arg_inplace_observe_during.rs +++ b/tests/fail/function_calls/arg_inplace_observe_during.rs @@ -14,7 +14,7 @@ fn main() { let non_copy = S(42); let ptr = std::ptr::addr_of_mut!(non_copy); // This could change `non_copy` in-place - Call(_unit = change_arg(Move(*ptr), ptr), after_call) + Call(_unit = change_arg(Move(*ptr), ptr), after_call, UnwindContinue()) } after_call = { Return() diff --git a/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr b/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr index f8532186be..c37e788e6b 100644 --- a/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr +++ b/tests/fail/function_calls/arg_inplace_observe_during.stack.stderr @@ -27,8 +27,8 @@ LL | x.0 = 0; note: inside `main` --> $DIR/arg_inplace_observe_during.rs:LL:CC | -LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr b/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr index 7b1846a32d..7557d3710d 100644 --- a/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr +++ b/tests/fail/function_calls/arg_inplace_observe_during.tree.stderr @@ -35,8 +35,8 @@ LL | x.0 = 0; note: inside `main` --> $DIR/arg_inplace_observe_during.rs:LL:CC | -LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_unit = change_arg(Move(*ptr), ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/return_pointer_aliasing.none.stderr b/tests/fail/function_calls/return_pointer_aliasing.none.stderr index 0a31adabf7..dd951066c3 100644 --- a/tests/fail/function_calls/return_pointer_aliasing.none.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing.none.stderr @@ -11,8 +11,8 @@ LL | unsafe { ptr.read() }; note: inside `main` --> $DIR/return_pointer_aliasing.rs:LL:CC | -LL | Call(*ptr = myfun(ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(*ptr = myfun(ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/return_pointer_aliasing.rs b/tests/fail/function_calls/return_pointer_aliasing.rs index 3d560af3d5..23b1e38b99 100644 --- a/tests/fail/function_calls/return_pointer_aliasing.rs +++ b/tests/fail/function_calls/return_pointer_aliasing.rs @@ -15,7 +15,7 @@ pub fn main() { let ptr = &raw mut x; // We arrange for `myfun` to have a pointer that aliases // its return place. Even just reading from that pointer is UB. - Call(*ptr = myfun(ptr), after_call) + Call(*ptr = myfun(ptr), after_call, UnwindContinue()) } after_call = { diff --git a/tests/fail/function_calls/return_pointer_aliasing.stack.stderr b/tests/fail/function_calls/return_pointer_aliasing.stack.stderr index 875cc5edad..cf13be6da0 100644 --- a/tests/fail/function_calls/return_pointer_aliasing.stack.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing.stack.stderr @@ -27,8 +27,8 @@ LL | unsafe { ptr.read() }; note: inside `main` --> $DIR/return_pointer_aliasing.rs:LL:CC | -LL | Call(*ptr = myfun(ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(*ptr = myfun(ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/return_pointer_aliasing.tree.stderr b/tests/fail/function_calls/return_pointer_aliasing.tree.stderr index deafbf0207..e16c4c0ebb 100644 --- a/tests/fail/function_calls/return_pointer_aliasing.tree.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing.tree.stderr @@ -35,8 +35,8 @@ LL | unsafe { ptr.read() }; note: inside `main` --> $DIR/return_pointer_aliasing.rs:LL:CC | -LL | Call(*ptr = myfun(ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(*ptr = myfun(ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/return_pointer_aliasing2.rs b/tests/fail/function_calls/return_pointer_aliasing2.rs index c1bbc748e1..56706cdb63 100644 --- a/tests/fail/function_calls/return_pointer_aliasing2.rs +++ b/tests/fail/function_calls/return_pointer_aliasing2.rs @@ -15,7 +15,7 @@ pub fn main() { let ptr = &raw mut _x; // We arrange for `myfun` to have a pointer that aliases // its return place. Even just reading from that pointer is UB. - Call(_x = myfun(ptr), after_call) + Call(_x = myfun(ptr), after_call, UnwindContinue()) } after_call = { diff --git a/tests/fail/function_calls/return_pointer_aliasing2.stack.stderr b/tests/fail/function_calls/return_pointer_aliasing2.stack.stderr index 0666db34fe..5d76d9eab6 100644 --- a/tests/fail/function_calls/return_pointer_aliasing2.stack.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing2.stack.stderr @@ -30,8 +30,8 @@ LL | unsafe { ptr.write(0) }; note: inside `main` --> $DIR/return_pointer_aliasing2.rs:LL:CC | -LL | Call(_x = myfun(ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_x = myfun(ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/return_pointer_aliasing2.tree.stderr b/tests/fail/function_calls/return_pointer_aliasing2.tree.stderr index e1b40a6bc1..e8165a73ff 100644 --- a/tests/fail/function_calls/return_pointer_aliasing2.tree.stderr +++ b/tests/fail/function_calls/return_pointer_aliasing2.tree.stderr @@ -35,8 +35,8 @@ LL | unsafe { ptr.write(0) }; note: inside `main` --> $DIR/return_pointer_aliasing2.rs:LL:CC | -LL | Call(_x = myfun(ptr), after_call) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Call(_x = myfun(ptr), after_call, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in the macro `::core::intrinsics::mir::__internal_remove_let` which comes from the expansion of the macro `mir` (in Nightly builds, run with -Z macro-backtrace for more info) note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace diff --git a/tests/fail/function_calls/return_pointer_on_unwind.rs b/tests/fail/function_calls/return_pointer_on_unwind.rs index 79e29b79d6..923c59e742 100644 --- a/tests/fail/function_calls/return_pointer_on_unwind.rs +++ b/tests/fail/function_calls/return_pointer_on_unwind.rs @@ -14,7 +14,7 @@ struct S(i32, [u8; 128]); fn docall(out: &mut S) { mir! { { - Call(*out = callee(), after_call) + Call(*out = callee(), after_call, UnwindContinue()) } after_call = { @@ -37,7 +37,7 @@ fn callee() -> S { // become visible to the outside. In codegen we can see them // but Miri should detect this as UB! RET.0 = 42; - Call(_unit = startpanic(), after_call) + Call(_unit = startpanic(), after_call, UnwindContinue()) } after_call = { diff --git a/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs b/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs index ee80186d4b..9357b37250 100644 --- a/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs +++ b/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.rs @@ -20,7 +20,7 @@ fn call(f: fn(NonZeroU32)) { let tmp = ptr::addr_of!(c); let ptr = tmp as *const NonZeroU32; // The call site now is a NonZeroU32-to-u32 transmute. - Call(_res = f(*ptr), retblock) //~ERROR: expected something greater or equal to 1 + Call(_res = f(*ptr), retblock, UnwindContinue()) //~ERROR: expected something greater or equal to 1 } retblock = { Return() diff --git a/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr b/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr index 234c280400..b40d99f7bc 100644 --- a/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr +++ b/tests/fail/validity/cast_fn_ptr_invalid_caller_arg.stderr @@ -1,8 +1,8 @@ error: Undefined Behavior: constructing invalid value: encountered 0, but expected something greater or equal to 1 --> $DIR/cast_fn_ptr_invalid_caller_arg.rs:LL:CC | -LL | Call(_res = f(*ptr), retblock) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 +LL | Call(_res = f(*ptr), retblock, UnwindContinue()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0, but expected something greater or equal to 1 | = 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 diff --git a/tests/pass/function_calls/return_place_on_heap.rs b/tests/pass/function_calls/return_place_on_heap.rs index d410a875b1..89ee689fab 100644 --- a/tests/pass/function_calls/return_place_on_heap.rs +++ b/tests/pass/function_calls/return_place_on_heap.rs @@ -11,7 +11,7 @@ pub fn main() { { let x = 0; let ptr = &raw mut x; - Call(*ptr = myfun(), after_call) + Call(*ptr = myfun(), after_call, UnwindContinue()) } after_call = { From 9cf1a17d79e9f173f215bdfb1190f00bae62c8af Mon Sep 17 00:00:00 2001 From: The Miri Conjob Bot Date: Wed, 15 Nov 2023 05:05:53 +0000 Subject: [PATCH 2/2] Preparing for merge from rustc --- rust-version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-version b/rust-version index 2beb3bfef9..0d677d36e3 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -3aaa0f57b7b877ef58532a8de075d1e5a79142bf +6d069a0ac7a423db87d86320edd39974f9f0c492