about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-02-06 10:43:51 +0100
committerGitHub <noreply@github.com>2022-02-06 10:43:51 +0100
commit4695c2157c394ff00bf624adbc8ac566d4b7c791 (patch)
tree2b07baa9bc94ebb84f8f8941a6fea269e27956c6
parent9f4559c3452239205015a02f2695ae1ec7d5c0f2 (diff)
parentf738669b636eae466fef00f62af5d393169c676d (diff)
downloadrust-4695c2157c394ff00bf624adbc8ac566d4b7c791.tar.gz
rust-4695c2157c394ff00bf624adbc8ac566d4b7c791.zip
Rollup merge of #93489 - Amanieu:panic_no_unwind, r=nagisa
Mark the panic_no_unwind lang item as nounwind

This has 2 effects:
- It helps LLVM when inlining since it doesn't need to generate landing pads for `panic_no_unwind`.
- It makes it sound for a panic handler to unwind even if `PanicInfo::can_unwind` returns true. This will simply cause another panic once the unwind tries to go past the `panic_no_unwind` lang item. Eventually this will cause a stack overflow, which is safe.
-rw-r--r--compiler/rustc_typeck/src/collect.rs7
-rw-r--r--library/core/src/panic/panic_info.rs4
2 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs
index cf519a9ab32..7c8a47d5d65 100644
--- a/compiler/rustc_typeck/src/collect.rs
+++ b/compiler/rustc_typeck/src/collect.rs
@@ -2778,6 +2778,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
         }
     }
 
+    // The panic_no_unwind function called by TerminatorKind::Abort will never
+    // unwind. If the panic handler that it invokes unwind then it will simply
+    // call the panic handler again.
+    if Some(id) == tcx.lang_items().panic_no_unwind() {
+        codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
+    }
+
     let supported_target_features = tcx.supported_target_features(LOCAL_CRATE);
 
     let mut inline_span = None;
diff --git a/library/core/src/panic/panic_info.rs b/library/core/src/panic/panic_info.rs
index 405224f8fb0..be8598fae09 100644
--- a/library/core/src/panic/panic_info.rs
+++ b/library/core/src/panic/panic_info.rs
@@ -136,6 +136,10 @@ impl<'a> PanicInfo<'a> {
     /// This is true for most kinds of panics with the exception of panics
     /// caused by trying to unwind out of a `Drop` implementation or a function
     /// whose ABI does not support unwinding.
+    ///
+    /// It is safe for a panic handler to unwind even when this function returns
+    /// true, however this will simply cause the panic handler to be called
+    /// again.
     #[must_use]
     #[unstable(feature = "panic_can_unwind", issue = "92988")]
     pub fn can_unwind(&self) -> bool {