1- #![ feature( rustc_private) ]
1+ #![ feature( rustc_private, once_cell ) ]
22
33extern crate rustc_data_structures;
44extern crate rustc_driver;
55extern crate rustc_interface;
66extern crate rustc_session;
77extern crate rustc_target;
88
9+ use std:: panic;
10+ use std:: lazy:: SyncLazy ;
11+
912use rustc_data_structures:: profiling:: { get_resident_set_size, print_time_passes_entry} ;
1013use rustc_interface:: interface;
1114use rustc_session:: config:: ErrorOutputType ;
1215use rustc_session:: early_error;
1316use 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 ) ]
1637pub 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