Skip to content

Commit e475efb

Browse files
committed
Auto merge of #85640 - bjorn3:custom_ice_hook, r=jackh726
Allow changing the bug report url for the ice hook cc https://github.com/bjorn3/rustc_codegen_cranelift/issues/1174
2 parents 9be7ca0 + 8b08cbd commit e475efb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/bin/cg_clif.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1-
#![feature(rustc_private)]
1+
#![feature(rustc_private, once_cell)]
22

33
extern crate rustc_data_structures;
44
extern crate rustc_driver;
55
extern crate rustc_interface;
66
extern crate rustc_session;
77
extern crate rustc_target;
88

9+
use std::panic;
10+
use std::lazy::SyncLazy;
11+
912
use rustc_data_structures::profiling::{get_resident_set_size, print_time_passes_entry};
1013
use rustc_interface::interface;
1114
use rustc_session::config::ErrorOutputType;
1215
use rustc_session::early_error;
1316
use rustc_target::spec::PanicStrategy;
1417

18+
const BUG_REPORT_URL: &str = "https://github.com/bjorn3/rustc_codegen_cranelift/issues/new";
19+
20+
static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
21+
SyncLazy::new(|| {
22+
let hook = panic::take_hook();
23+
panic::set_hook(Box::new(|info| {
24+
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
25+
(*DEFAULT_HOOK)(info);
26+
27+
// Separate the output with an empty line
28+
eprintln!();
29+
30+
// Print the ICE message
31+
rustc_driver::report_ice(info, BUG_REPORT_URL);
32+
}));
33+
hook
34+
});
35+
1536
#[derive(Default)]
1637
pub struct CraneliftPassesCallbacks {
1738
time_passes: bool,
@@ -37,7 +58,7 @@ fn main() {
3758
let start_rss = get_resident_set_size();
3859
rustc_driver::init_rustc_env_logger();
3960
let mut callbacks = CraneliftPassesCallbacks::default();
40-
rustc_driver::install_ice_hook();
61+
SyncLazy::force(&DEFAULT_HOOK); // Install ice hook
4162
let exit_code = rustc_driver::catch_with_exit_code(|| {
4263
let args = std::env::args_os()
4364
.enumerate()

0 commit comments

Comments
 (0)