]> git.lizzy.rs Git - rust.git/commitdiff
Apply review feedback
authorAmanieu d'Antras <amanieu@gmail.com>
Tue, 7 Jan 2020 15:41:59 +0000 (16:41 +0100)
committerAmanieu d'Antras <amanieu@gmail.com>
Mon, 2 Mar 2020 11:43:07 +0000 (11:43 +0000)
12 files changed:
Cargo.lock
src/libpanic_abort/Cargo.toml
src/libpanic_abort/lib.rs
src/libpanic_unwind/dummy.rs
src/libpanic_unwind/emcc.rs
src/libpanic_unwind/gcc.rs
src/libpanic_unwind/hermit.rs
src/libpanic_unwind/lib.rs
src/libpanic_unwind/payload.rs [new file with mode: 0644]
src/libpanic_unwind/seh.rs
src/libstd/panicking.rs
src/test/ui/no-landing-pads.rs [deleted file]

index f639095fae75984792f72b3540d1e127eabe740c..08c0462a1dc737e0a7f4389fea217395110a90eb 100644 (file)
@@ -2308,6 +2308,7 @@ dependencies = [
 name = "panic_abort"
 version = "0.0.0"
 dependencies = [
+ "cfg-if",
  "compiler_builtins",
  "core",
  "libc",
index 2bee0b716c750f4836068ea38b85e74cceb09b7d..8ebd95047ac232d5340df929d51e7da6c7a123f1 100644 (file)
@@ -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"
index fe9196ef2314b09d06f2a358a8e32a7770d277b7..6ea818ecef82784a089f9dd079ad2091994239ab 100644 (file)
 
 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!()
 }
 
index 30593d3b88af9bcea9ce6010c31ff75e178e98e6..4667ede2baad5131ef5587f06c2c3b153f8f9bb8 100644 (file)
@@ -6,8 +6,6 @@
 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()
 }
index 873135414bd9d46b46cb4397386a3fb3795891a5..e541ec3002510489cb0dcfa38bcda601cb1425f8 100644 (file)
@@ -48,8 +48,6 @@ unsafe impl Sync for 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
index dd84a814f48b16a7afe76cf89ef8bd2466e2bcd4..20ae5edaa2a690cd2fdfd6ddf6acccddb139a0f2 100644 (file)
@@ -82,8 +82,6 @@ extern "C" fn exception_cleanup(
     }
 }
 
-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
index 8ffb4bcd3df23697d0fe691d5f7c55527f8dbfa1..6bded4dd499bd7b0a6774f9df07eb31787390004 100644 (file)
@@ -6,8 +6,6 @@
 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() -> !;
index ad82f22510c41d80bae791587d0de1351bbd3d84..87d24841d04a345e4c296a41fabe315ab26f5b5a 100644 (file)
@@ -35,8 +35,8 @@
 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 @@
     }
 }
 
+include!("payload.rs");
+
 extern "C" {
     /// Handler in libstd called when a panic object is dropped outside of
     /// `catch_unwind`.
@@ -71,9 +73,9 @@
 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 (file)
index 0000000..1234db7
--- /dev/null
@@ -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;
+    }
+}
index 6f464c1ab680e5550f398aef809167147a66d333..da5ee5369e08267924476a77adc88351e0d8f960 100644 (file)
@@ -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 _ })
 }
index b02cedd5da5bf321d088329658fcd53afc695a53..38cb4418dd036cd3c8c887d5a80adea341a96e87 100644 (file)
 #[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 @@
 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 @@ union Data<F, R> {
     // 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 @@ union Data<F, R> {
     // 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 (file)
index 44af25f..0000000
+++ /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 });
-}