summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/src
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2021-05-24 18:55:30 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2021-05-24 18:55:30 +0200
commit0bc60c09701a0d5c61875bdfceb11f1418ac7f77 (patch)
tree495687e9a633266c56445503d37880bf213fb754 /compiler/rustc_codegen_cranelift/src
parent048fe539e4a976c1aa193398d64f55648365aea4 (diff)
downloadrust-0bc60c09701a0d5c61875bdfceb11f1418ac7f77.tar.gz
rust-0bc60c09701a0d5c61875bdfceb11f1418ac7f77.zip
Change the ice hook for cg_clif to refer to cg_clif's issue tracker
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src')
-rw-r--r--compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs25
1 files changed, 23 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs b/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
index 983839d48d2..2643fae0a81 100644
--- a/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
+++ b/compiler/rustc_codegen_cranelift/src/bin/cg_clif.rs
@@ -1,4 +1,4 @@
-#![feature(rustc_private)]
+#![feature(rustc_private, once_cell)]
 
 extern crate rustc_data_structures;
 extern crate rustc_driver;
@@ -6,12 +6,33 @@ extern crate rustc_interface;
 extern crate rustc_session;
 extern crate rustc_target;
 
+use std::panic;
+use std::lazy::SyncLazy;
+
 use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
 use rustc_interface::interface;
 use rustc_session::config::ErrorOutputType;
 use rustc_session::early_error;
 use rustc_target::spec::PanicStrategy;
 
+const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new";
+
+static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
+    SyncLazy::new(|| {
+        let hook = panic::take_hook();
+        panic::set_hook(Box::new(|info| {
+            // Invoke the default handler, which prints the actual panic message and optionally a backtrace
+            (*DEFAULT_HOOK)(info);
+
+            // Separate the output with an empty line
+            eprintln!();
+
+            // Print the ICE message
+            rustc_driver::report_ice(info, BUG_REPORT_URL);
+        }));
+        hook
+    });
+
 #[derive(Default)]
 pub struct CraneliftPassesCallbacks {
     time_passes: bool,
@@ -37,7 +58,7 @@ fn main() {
     let start_rss = get_resident_set_size();
     rustc_driver::init_rustc_env_logger();
     let mut callbacks = CraneliftPassesCallbacks::default();
-    rustc_driver::install_ice_hook();
+    SyncLazy::force(&DEFAULT_HOOK); // Install ice hook
     let exit_code = rustc_driver::catch_with_exit_code(|| {
         let args = std::env::args_os()
             .enumerate()