about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAmanieu d'Antras <amanieu@gmail.com>2020-01-07 16:41:59 +0100
committerAmanieu d'Antras <amanieu@gmail.com>2020-03-02 11:43:07 +0000
commit01d04944cefc61cd684e3554e48068926a5f30ab (patch)
tree46acb587cf4decf0b11de1999de8a59e892a94ee
parent35349abeb33893e9d683e507f819c16063e4797e (diff)
downloadrust-01d04944cefc61cd684e3554e48068926a5f30ab.tar.gz
rust-01d04944cefc61cd684e3554e48068926a5f30ab.zip
Apply review feedback
-rw-r--r--Cargo.lock1
-rw-r--r--src/libpanic_abort/Cargo.toml1
-rw-r--r--src/libpanic_abort/lib.rs5
-rw-r--r--src/libpanic_unwind/dummy.rs2
-rw-r--r--src/libpanic_unwind/emcc.rs2
-rw-r--r--src/libpanic_unwind/gcc.rs2
-rw-r--r--src/libpanic_unwind/hermit.rs2
-rw-r--r--src/libpanic_unwind/lib.rs12
-rw-r--r--src/libpanic_unwind/payload.rs21
-rw-r--r--src/libpanic_unwind/seh.rs2
-rw-r--r--src/libstd/panicking.rs34
-rw-r--r--src/test/ui/no-landing-pads.rs24
12 files changed, 40 insertions, 68 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f639095fae7..08c0462a1dc 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2308,6 +2308,7 @@ dependencies = [
 name = "panic_abort"
 version = "0.0.0"
 dependencies = [
+ "cfg-if",
  "compiler_builtins",
  "core",
  "libc",
diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml
index 2bee0b716c7..8ebd95047ac 100644
--- a/src/libpanic_abort/Cargo.toml
+++ b/src/libpanic_abort/Cargo.toml
@@ -14,3 +14,4 @@ doc = false
 core = { path = "../libcore" }
 libc = { version = "0.2", default-features = false }
 compiler_builtins = "0.1.0"
+cfg-if = "0.1.8"
diff --git a/src/libpanic_abort/lib.rs b/src/libpanic_abort/lib.rs
index fe9196ef231..6ea818ecef8 100644
--- a/src/libpanic_abort/lib.rs
+++ b/src/libpanic_abort/lib.rs
@@ -20,8 +20,11 @@
 
 use core::any::Any;
 
+// We need the definition of TryPayload for __rust_panic_cleanup.
+include!("../libpanic_unwind/payload.rs");
+
 #[rustc_std_internal_symbol]
-pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Send + 'static) {
+pub unsafe extern "C" fn __rust_panic_cleanup(_: TryPayload) -> *mut (dyn Any + Send + 'static) {
     unreachable!()
 }
 
diff --git a/src/libpanic_unwind/dummy.rs b/src/libpanic_unwind/dummy.rs
index 30593d3b88a..4667ede2baa 100644
--- a/src/libpanic_unwind/dummy.rs
+++ b/src/libpanic_unwind/dummy.rs
@@ -6,8 +6,6 @@ use alloc::boxed::Box;
 use core::any::Any;
 use core::intrinsics;
 
-pub type Payload = *mut u8;
-
 pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
     intrinsics::abort()
 }
diff --git a/src/libpanic_unwind/emcc.rs b/src/libpanic_unwind/emcc.rs
index 873135414bd..e541ec30025 100644
--- a/src/libpanic_unwind/emcc.rs
+++ b/src/libpanic_unwind/emcc.rs
@@ -48,8 +48,6 @@ static EXCEPTION_TYPE_INFO: TypeInfo = TypeInfo {
     name: b"rust_panic\0".as_ptr(),
 };
 
-pub type Payload = *mut u8;
-
 struct Exception {
     // This needs to be an Option because the object's lifetime follows C++
     // semantics: when catch_unwind moves the Box out of the exception it must
diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs
index dd84a814f48..20ae5edaa2a 100644
--- a/src/libpanic_unwind/gcc.rs
+++ b/src/libpanic_unwind/gcc.rs
@@ -82,8 +82,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
     }
 }
 
-pub type Payload = *mut u8;
-
 pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
     let exception = Box::from_raw(ptr as *mut Exception);
     exception.cause
diff --git a/src/libpanic_unwind/hermit.rs b/src/libpanic_unwind/hermit.rs
index 8ffb4bcd3df..6bded4dd499 100644
--- a/src/libpanic_unwind/hermit.rs
+++ b/src/libpanic_unwind/hermit.rs
@@ -6,8 +6,6 @@ use alloc::boxed::Box;
 use core::any::Any;
 use core::ptr;
 
-pub type Payload = *mut u8;
-
 pub unsafe fn cleanup(_ptr: *mut u8) -> Box<dyn Any + Send> {
     extern "C" {
         pub fn __rust_abort() -> !;
diff --git a/src/libpanic_unwind/lib.rs b/src/libpanic_unwind/lib.rs
index ad82f22510c..87d24841d04 100644
--- a/src/libpanic_unwind/lib.rs
+++ b/src/libpanic_unwind/lib.rs
@@ -35,8 +35,8 @@ use alloc::boxed::Box;
 use core::any::Any;
 use core::panic::BoxMeUp;
 
-// If adding to this list, you should also look at libstd::panicking's identical
-// list of Payload types and likely add to there as well.
+// If adding to this list, you should also look at the list of TryPayload types
+// defined in payload.rs and likely add to there as well.
 cfg_if::cfg_if! {
     if #[cfg(target_os = "emscripten")] {
         #[path = "emcc.rs"]
@@ -62,6 +62,8 @@ cfg_if::cfg_if! {
     }
 }
 
+include!("payload.rs");
+
 extern "C" {
     /// Handler in libstd called when a panic object is dropped outside of
     /// `catch_unwind`.
@@ -71,9 +73,9 @@ extern "C" {
 mod dwarf;
 
 #[no_mangle]
-pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static) {
-    let payload = payload as *mut imp::Payload;
-    let payload = *(payload);
+pub unsafe extern "C" fn __rust_panic_cleanup(
+    payload: TryPayload,
+) -> *mut (dyn Any + Send + 'static) {
     Box::into_raw(imp::cleanup(payload))
 }
 
diff --git a/src/libpanic_unwind/payload.rs b/src/libpanic_unwind/payload.rs
new file mode 100644
index 00000000000..1234db7da0f
--- /dev/null
+++ b/src/libpanic_unwind/payload.rs
@@ -0,0 +1,21 @@
+// Type definition for the payload argument of the try intrinsic.
+//
+// This must be kept in sync with the implementations of the try intrinsic.
+//
+// This file is included by both panic runtimes and libstd. It is part of the
+// panic runtime ABI.
+cfg_if::cfg_if! {
+    if #[cfg(target_os = "emscripten")] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(target_arch = "wasm32")] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(target_os = "hermit")] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
+        type TryPayload = *mut u8;
+    } else if #[cfg(target_env = "msvc")] {
+        type TryPayload = [u64; 2];
+    } else {
+        type TryPayload = *mut u8;
+    }
+}
diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs
index 6f464c1ab68..da5ee5369e0 100644
--- a/src/libpanic_unwind/seh.rs
+++ b/src/libpanic_unwind/seh.rs
@@ -308,8 +308,6 @@ pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
     _CxxThrowException(throw_ptr, &mut THROW_INFO as *mut _ as *mut _);
 }
 
-pub type Payload = [u64; 2];
-
 pub unsafe fn cleanup(payload: [u64; 2]) -> Box<dyn Any + Send> {
     mem::transmute(raw::TraitObject { data: payload[0] as *mut _, vtable: payload[1] as *mut _ })
 }
diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs
index b02cedd5da5..38cb4418dd0 100644
--- a/src/libstd/panicking.rs
+++ b/src/libstd/panicking.rs
@@ -28,30 +28,8 @@ use crate::io::set_panic;
 #[cfg(test)]
 use realstd::io::set_panic;
 
-// This must be kept in sync with the implementations in libpanic_unwind.
-//
-// This is *not* checked in anyway; the compiler does not allow us to use a
-// type/macro/anything from panic_unwind, since we're then linking in the
-// panic_unwind runtime even during -Cpanic=abort.
-//
-// Essentially this must be the type of `imp::Payload` in libpanic_unwind.
-cfg_if::cfg_if! {
-    if #[cfg(not(feature = "panic_unwind"))] {
-        type Payload = ();
-    } else if #[cfg(target_os = "emscripten")] {
-        type Payload = *mut u8;
-    } else if #[cfg(target_arch = "wasm32")] {
-        type Payload = *mut u8;
-    } else if #[cfg(target_os = "hermit")] {
-        type Payload = *mut u8;
-    } else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
-        type Payload = *mut u8;
-    } else if #[cfg(target_env = "msvc")] {
-        type Payload = [u64; 2];
-    } else {
-        type Payload = *mut u8;
-    }
-}
+// Include the definition of UnwindPayload from libpanic_unwind.
+include!("../libpanic_unwind/payload.rs");
 
 // Binary interface to the panic runtime that the standard library depends on.
 //
@@ -67,7 +45,7 @@ cfg_if::cfg_if! {
 extern "C" {
     /// The payload ptr here is actually the same as the payload ptr for the try
     /// intrinsic (i.e., is really `*mut [u64; 2]` or `*mut *mut u8`).
-    fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any + Send + 'static);
+    fn __rust_panic_cleanup(payload: TryPayload) -> *mut (dyn Any + Send + 'static);
 
     /// `payload` is actually a `*mut &mut dyn BoxMeUp` but that would cause FFI warnings.
     /// It cannot be `Box<dyn BoxMeUp>` because the other end of this call does not depend
@@ -297,7 +275,7 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
     // method of calling a catch panic whilst juggling ownership.
     let mut data = Data { f: ManuallyDrop::new(f) };
 
-    let mut payload: MaybeUninit<Payload> = MaybeUninit::uninit();
+    let mut payload: MaybeUninit<TryPayload> = MaybeUninit::uninit();
 
     let data_ptr = &mut data as *mut _ as *mut u8;
     let payload_ptr = payload.as_mut_ptr() as *mut _;
@@ -312,8 +290,8 @@ pub unsafe fn r#try<R, F: FnOnce() -> R>(f: F) -> Result<R, Box<dyn Any + Send>>
     // optimizer (in most cases this function is not inlined even as a normal,
     // non-cold function, though, as of the writing of this comment).
     #[cold]
-    unsafe fn cleanup(mut payload: Payload) -> Box<dyn Any + Send + 'static> {
-        let obj = Box::from_raw(__rust_panic_cleanup(&mut payload as *mut _ as *mut u8));
+    unsafe fn cleanup(payload: TryPayload) -> Box<dyn Any + Send + 'static> {
+        let obj = Box::from_raw(__rust_panic_cleanup(payload));
         update_panic_count(-1);
         obj
     }
diff --git a/src/test/ui/no-landing-pads.rs b/src/test/ui/no-landing-pads.rs
deleted file mode 100644
index 44af25f7f8f..00000000000
--- a/src/test/ui/no-landing-pads.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-// run-pass
-// compile-flags: -Z no-landing-pads -C codegen-units=1
-// ignore-emscripten no threads support
-// ignore-test fails because catch_unwind doesn't work with no-landing-pads
-
-use std::thread;
-
-static mut HIT: bool = false;
-
-struct A;
-
-impl Drop for A {
-    fn drop(&mut self) {
-        unsafe { HIT = true; }
-    }
-}
-
-fn main() {
-    thread::spawn(move|| -> () {
-        let _a = A;
-        panic!();
-    }).join().unwrap_err();
-    assert!(unsafe { !HIT });
-}