Skip to content

Commit 50a9081

Browse files
committed
Auto merge of rust-lang#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 079aa83 + 0bc60c0 commit 50a9081

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

compiler/rustc_codegen_cranelift/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()

compiler/rustc_driver/src/lib.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -1167,23 +1167,26 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
11671167
static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
11681168
SyncLazy::new(|| {
11691169
let hook = panic::take_hook();
1170-
panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL)));
1170+
panic::set_hook(Box::new(|info| {
1171+
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
1172+
(*DEFAULT_HOOK)(info);
1173+
1174+
// Separate the output with an empty line
1175+
eprintln!();
1176+
1177+
// Print the ICE message
1178+
report_ice(info, BUG_REPORT_URL);
1179+
}));
11711180
hook
11721181
});
11731182

1174-
/// Prints the ICE message, including backtrace and query stack.
1183+
/// Prints the ICE message, including query stack, but without backtrace.
11751184
///
11761185
/// The message will point the user at `bug_report_url` to report the ICE.
11771186
///
11781187
/// When `install_ice_hook` is called, this function will be called as the panic
11791188
/// hook.
11801189
pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
1181-
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
1182-
(*DEFAULT_HOOK)(info);
1183-
1184-
// Separate the output with an empty line
1185-
eprintln!();
1186-
11871190
let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
11881191
rustc_errors::ColorConfig::Auto,
11891192
None,

0 commit comments

Comments
 (0)