From e54619b5e18ce9781faed975f5101db621608ea0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 27 Jun 2020 14:43:37 +0200 Subject: [PATCH] with this, we support panics on Windows --- src/shims/foreign_items.rs | 1 - src/shims/mod.rs | 8 -------- src/shims/panic.rs | 8 -------- tests/compile-fail/abort-terminator.rs | 1 - tests/compile-fail/panic/double_panic.rs | 1 - tests/compile-fail/panic/windows1.rs | 9 --------- tests/compile-fail/panic/windows2.rs | 9 --------- tests/compile-fail/panic/windows3.rs | 10 ---------- tests/run-pass/panic/catch_panic.rs | 2 +- tests/run-pass/panic/div-by-zero-2.rs | 1 - tests/run-pass/panic/div-by-zero-2.stderr | 2 +- tests/run-pass/panic/overflowing-lsh-neg.rs | 1 - tests/run-pass/panic/overflowing-lsh-neg.stderr | 2 +- tests/run-pass/panic/overflowing-rsh-1.rs | 1 - tests/run-pass/panic/overflowing-rsh-1.stderr | 2 +- tests/run-pass/panic/overflowing-rsh-2.rs | 1 - tests/run-pass/panic/overflowing-rsh-2.stderr | 2 +- tests/run-pass/panic/panic1.rs | 1 - tests/run-pass/panic/panic1.stderr | 2 +- tests/run-pass/panic/panic2.rs | 1 - tests/run-pass/panic/panic2.stderr | 2 +- tests/run-pass/panic/panic3.rs | 1 - tests/run-pass/panic/panic3.stderr | 2 +- tests/run-pass/panic/panic4.rs | 1 - tests/run-pass/panic/panic4.stderr | 2 +- tests/run-pass/panic/std-panic-locations.rs | 1 - tests/run-pass/transmute_fat2.rs | 1 - tests/run-pass/transmute_fat2.stderr | 2 +- 28 files changed, 10 insertions(+), 67 deletions(-) delete mode 100644 tests/compile-fail/panic/windows1.rs delete mode 100644 tests/compile-fail/panic/windows2.rs delete mode 100644 tests/compile-fail/panic/windows3.rs diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 14c5aac4899..a7495beef72 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -129,7 +129,6 @@ fn emulate_foreign_item( // This matches calls to the foreign item `panic_impl`. // The implementation is provided by the function with the `#[panic_handler]` attribute. "panic_impl" => { - this.check_panic_supported()?; let panic_impl_id = tcx.lang_items().panic_impl().unwrap(); let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id); return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?)); diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 37e7b8c4046..56754a9ebde 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -52,14 +52,6 @@ fn find_mir_or_eval_fn( return this.emulate_foreign_item(instance.def_id(), args, ret, unwind); } - // Better error message for panics on Windows. - let def_id = instance.def_id(); - if Some(def_id) == this.tcx.lang_items().begin_panic_fn() || - Some(def_id) == this.tcx.lang_items().panic_impl() - { - this.check_panic_supported()?; - } - // Otherwise, load the MIR. Ok(Some(&*this.load_mir(instance.def, None)?)) } diff --git a/src/shims/panic.rs b/src/shims/panic.rs index 43f90f1b04f..8e291c20121 100644 --- a/src/shims/panic.rs +++ b/src/shims/panic.rs @@ -34,14 +34,6 @@ pub struct CatchUnwindData<'tcx> { impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for crate::MiriEvalContext<'mir, 'tcx> {} pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx> { - /// Check if panicking is supported on this target, and give a good error otherwise. - fn check_panic_supported(&self) -> InterpResult<'tcx> { - match self.eval_context_ref().tcx.sess.target.target.target_os.as_str() { - "linux" | "macos" => Ok(()), - _ => throw_unsup_format!("panicking is not supported on this target"), - } - } - /// Handles the special `miri_start_panic` intrinsic, which is called /// by libpanic_unwind to delegate the actual unwinding process to Miri. fn handle_miri_start_panic( diff --git a/tests/compile-fail/abort-terminator.rs b/tests/compile-fail/abort-terminator.rs index af1a155435f..1bfa289a52b 100644 --- a/tests/compile-fail/abort-terminator.rs +++ b/tests/compile-fail/abort-terminator.rs @@ -1,5 +1,4 @@ // error-pattern: the evaluated program aborted -// ignore-windows (panics dont work on Windows) #![feature(unwind_attributes)] #[unwind(aborts)] diff --git a/tests/compile-fail/panic/double_panic.rs b/tests/compile-fail/panic/double_panic.rs index 3085d0b0065..80d74f02623 100644 --- a/tests/compile-fail/panic/double_panic.rs +++ b/tests/compile-fail/panic/double_panic.rs @@ -1,5 +1,4 @@ // error-pattern: the evaluated program aborted -// ignore-windows (panics dont work on Windows) struct Foo; impl Drop for Foo { diff --git a/tests/compile-fail/panic/windows1.rs b/tests/compile-fail/panic/windows1.rs deleted file mode 100644 index 142ba85c42c..00000000000 --- a/tests/compile-fail/panic/windows1.rs +++ /dev/null @@ -1,9 +0,0 @@ -// ignore-linux -// ignore-macos - -// Test that panics on Windows give a reasonable error message. - -// error-pattern: panicking is not supported on this target -fn main() { - core::panic!("this is {}", "Windows"); -} diff --git a/tests/compile-fail/panic/windows2.rs b/tests/compile-fail/panic/windows2.rs deleted file mode 100644 index da2cfb59362..00000000000 --- a/tests/compile-fail/panic/windows2.rs +++ /dev/null @@ -1,9 +0,0 @@ -// ignore-linux -// ignore-macos - -// Test that panics on Windows give a reasonable error message. - -// error-pattern: panicking is not supported on this target -fn main() { - std::panic!("this is Windows"); -} diff --git a/tests/compile-fail/panic/windows3.rs b/tests/compile-fail/panic/windows3.rs deleted file mode 100644 index a2e7bf5a7d4..00000000000 --- a/tests/compile-fail/panic/windows3.rs +++ /dev/null @@ -1,10 +0,0 @@ -// ignore-linux -// ignore-macos - -// Test that panics on Windows give a reasonable error message. - -// error-pattern: panicking is not supported on this target -#[allow(unconditional_panic)] -fn main() { - let _val = 1/0; -} diff --git a/tests/run-pass/panic/catch_panic.rs b/tests/run-pass/panic/catch_panic.rs index 288ae1965a6..ac41de586e8 100644 --- a/tests/run-pass/panic/catch_panic.rs +++ b/tests/run-pass/panic/catch_panic.rs @@ -1,7 +1,7 @@ -// ignore-windows: Unwind panicking does not currently work on Windows // normalize-stderr-test "[^ ]*libcore/[a-z/]+.rs[0-9:]*" -> "$$LOC" #![feature(never_type)] #![allow(unconditional_panic)] + use std::panic::{catch_unwind, AssertUnwindSafe}; use std::cell::Cell; diff --git a/tests/run-pass/panic/div-by-zero-2.rs b/tests/run-pass/panic/div-by-zero-2.rs index cfacc9db0d6..fac5415696f 100644 --- a/tests/run-pass/panic/div-by-zero-2.rs +++ b/tests/run-pass/panic/div-by-zero-2.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows #![allow(unconditional_panic)] fn main() { diff --git a/tests/run-pass/panic/div-by-zero-2.stderr b/tests/run-pass/panic/div-by-zero-2.stderr index 77dca2aac1e..d255811be2a 100644 --- a/tests/run-pass/panic/div-by-zero-2.stderr +++ b/tests/run-pass/panic/div-by-zero-2.stderr @@ -1 +1 @@ -thread 'main' panicked at 'attempt to divide by zero', $DIR/div-by-zero-2.rs:5:14 +thread 'main' panicked at 'attempt to divide by zero', $DIR/div-by-zero-2.rs:4:14 diff --git a/tests/run-pass/panic/overflowing-lsh-neg.rs b/tests/run-pass/panic/overflowing-lsh-neg.rs index ee15ca0284e..bf5eed1c550 100644 --- a/tests/run-pass/panic/overflowing-lsh-neg.rs +++ b/tests/run-pass/panic/overflowing-lsh-neg.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows #![allow(arithmetic_overflow)] fn main() { diff --git a/tests/run-pass/panic/overflowing-lsh-neg.stderr b/tests/run-pass/panic/overflowing-lsh-neg.stderr index e1e7daa119a..04d98a0a2f1 100644 --- a/tests/run-pass/panic/overflowing-lsh-neg.stderr +++ b/tests/run-pass/panic/overflowing-lsh-neg.stderr @@ -1 +1 @@ -thread 'main' panicked at 'attempt to shift left with overflow', $DIR/overflowing-lsh-neg.rs:5:14 +thread 'main' panicked at 'attempt to shift left with overflow', $DIR/overflowing-lsh-neg.rs:4:14 diff --git a/tests/run-pass/panic/overflowing-rsh-1.rs b/tests/run-pass/panic/overflowing-rsh-1.rs index 36ab948a5ef..4c0106f0fb1 100644 --- a/tests/run-pass/panic/overflowing-rsh-1.rs +++ b/tests/run-pass/panic/overflowing-rsh-1.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows #![allow(arithmetic_overflow)] fn main() { diff --git a/tests/run-pass/panic/overflowing-rsh-1.stderr b/tests/run-pass/panic/overflowing-rsh-1.stderr index 20a45739ae2..a9a72f46222 100644 --- a/tests/run-pass/panic/overflowing-rsh-1.stderr +++ b/tests/run-pass/panic/overflowing-rsh-1.stderr @@ -1 +1 @@ -thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-1.rs:5:14 +thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-1.rs:4:14 diff --git a/tests/run-pass/panic/overflowing-rsh-2.rs b/tests/run-pass/panic/overflowing-rsh-2.rs index 27cc65fa768..19d16e7bc84 100644 --- a/tests/run-pass/panic/overflowing-rsh-2.rs +++ b/tests/run-pass/panic/overflowing-rsh-2.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows #![allow(arithmetic_overflow)] fn main() { diff --git a/tests/run-pass/panic/overflowing-rsh-2.stderr b/tests/run-pass/panic/overflowing-rsh-2.stderr index 3381116ae6c..24b61194565 100644 --- a/tests/run-pass/panic/overflowing-rsh-2.stderr +++ b/tests/run-pass/panic/overflowing-rsh-2.stderr @@ -1 +1 @@ -thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-2.rs:6:14 +thread 'main' panicked at 'attempt to shift right with overflow', $DIR/overflowing-rsh-2.rs:5:14 diff --git a/tests/run-pass/panic/panic1.rs b/tests/run-pass/panic/panic1.rs index 61321c65816..9d9ad28df5a 100644 --- a/tests/run-pass/panic/panic1.rs +++ b/tests/run-pass/panic/panic1.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows fn main() { std::panic!("panicking from libstd"); } diff --git a/tests/run-pass/panic/panic1.stderr b/tests/run-pass/panic/panic1.stderr index 305fc1a1a6e..954b8799a08 100644 --- a/tests/run-pass/panic/panic1.stderr +++ b/tests/run-pass/panic/panic1.stderr @@ -1 +1 @@ -thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:3:5 +thread 'main' panicked at 'panicking from libstd', $DIR/panic1.rs:2:5 diff --git a/tests/run-pass/panic/panic2.rs b/tests/run-pass/panic/panic2.rs index d6ab864795e..d90e3f2e0ac 100644 --- a/tests/run-pass/panic/panic2.rs +++ b/tests/run-pass/panic/panic2.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows fn main() { std::panic!("{}-panicking from libstd", 42); } diff --git a/tests/run-pass/panic/panic2.stderr b/tests/run-pass/panic/panic2.stderr index cd40559c81e..e90e3502cbf 100644 --- a/tests/run-pass/panic/panic2.stderr +++ b/tests/run-pass/panic/panic2.stderr @@ -1 +1 @@ -thread 'main' panicked at '42-panicking from libstd', $DIR/panic2.rs:3:5 +thread 'main' panicked at '42-panicking from libstd', $DIR/panic2.rs:2:5 diff --git a/tests/run-pass/panic/panic3.rs b/tests/run-pass/panic/panic3.rs index 10a42c7e6c0..418ee4f8411 100644 --- a/tests/run-pass/panic/panic3.rs +++ b/tests/run-pass/panic/panic3.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows fn main() { core::panic!("panicking from libcore"); } diff --git a/tests/run-pass/panic/panic3.stderr b/tests/run-pass/panic/panic3.stderr index e3aa902f0cb..0a3c191b282 100644 --- a/tests/run-pass/panic/panic3.stderr +++ b/tests/run-pass/panic/panic3.stderr @@ -1 +1 @@ -thread 'main' panicked at 'panicking from libcore', $DIR/panic3.rs:3:5 +thread 'main' panicked at 'panicking from libcore', $DIR/panic3.rs:2:5 diff --git a/tests/run-pass/panic/panic4.rs b/tests/run-pass/panic/panic4.rs index 06e2dd008ff..0fcc53813b5 100644 --- a/tests/run-pass/panic/panic4.rs +++ b/tests/run-pass/panic/panic4.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows fn main() { core::panic!("{}-panicking from libcore", 42); } diff --git a/tests/run-pass/panic/panic4.stderr b/tests/run-pass/panic/panic4.stderr index 1a242a868ca..946059b1e49 100644 --- a/tests/run-pass/panic/panic4.stderr +++ b/tests/run-pass/panic/panic4.stderr @@ -1 +1 @@ -thread 'main' panicked at '42-panicking from libcore', $DIR/panic4.rs:3:5 +thread 'main' panicked at '42-panicking from libcore', $DIR/panic4.rs:2:5 diff --git a/tests/run-pass/panic/std-panic-locations.rs b/tests/run-pass/panic/std-panic-locations.rs index d5f38fc2672..ac2e8d5305d 100644 --- a/tests/run-pass/panic/std-panic-locations.rs +++ b/tests/run-pass/panic/std-panic-locations.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows #![feature(option_expect_none, option_unwrap_none)] //! Test that panic locations for `#[track_caller]` functions in std have the correct //! location reported. diff --git a/tests/run-pass/transmute_fat2.rs b/tests/run-pass/transmute_fat2.rs index c667aab6bb5..3dff2cc1e0c 100644 --- a/tests/run-pass/transmute_fat2.rs +++ b/tests/run-pass/transmute_fat2.rs @@ -1,4 +1,3 @@ -// ignore-windows: Unwind panicking does not currently work on Windows fn main() { #[cfg(target_pointer_width="64")] let bad = unsafe { diff --git a/tests/run-pass/transmute_fat2.stderr b/tests/run-pass/transmute_fat2.stderr index 2539e58814d..08849a5b517 100644 --- a/tests/run-pass/transmute_fat2.stderr +++ b/tests/run-pass/transmute_fat2.stderr @@ -1 +1 @@ -thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', $DIR/transmute_fat2.rs:12:5 +thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', $DIR/transmute_fat2.rs:11:5 -- 2.44.0