about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2022-07-02 19:38:23 +0200
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2022-07-02 19:38:50 +0200
commit14b2f8f98d2df5287662d1d43b38bf7efc839f4f (patch)
treee03788e4d0073609fb4e1df47bf342042b0e0172
parent45b6cd6a8a2a3b364d22d4fabc0d72f9e37e3e50 (diff)
downloadrust-14b2f8f98d2df5287662d1d43b38bf7efc839f4f.tar.gz
rust-14b2f8f98d2df5287662d1d43b38bf7efc839f4f.zip
Add code to print clif ir on panics during define_function
-rw-r--r--src/base.rs29
-rw-r--r--src/pretty_clif.rs3
2 files changed, 30 insertions, 2 deletions
diff --git a/src/base.rs b/src/base.rs
index 7110edb0d63..bdcf2f806eb 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -175,10 +175,37 @@ fn compile_fn<'tcx>(
         );
     });
 
+    #[cfg(any())] // This is never true
+    let _clif_guard = {
+        use std::fmt::Write;
+
+        let func_clone = context.func.clone();
+        let clif_comments_clone = clif_comments.clone();
+        let mut clif = String::new();
+        for flag in module.isa().flags().iter() {
+            writeln!(clif, "set {}", flag).unwrap();
+        }
+        write!(clif, "target {}", module.isa().triple().architecture.to_string()).unwrap();
+        for isa_flag in module.isa().isa_flags().iter() {
+            write!(clif, " {}", isa_flag).unwrap();
+        }
+        writeln!(clif, "\n").unwrap();
+        crate::PrintOnPanic(move || {
+            let mut clif = clif.clone();
+            ::cranelift_codegen::write::decorate_function(
+                &mut &clif_comments_clone,
+                &mut clif,
+                &func_clone,
+            )
+            .unwrap();
+            clif
+        })
+    };
+
     // Define function
     tcx.sess.time("define function", || {
         context.want_disasm = crate::pretty_clif::should_write_ir(tcx);
-        module.define_function(func_id, context).unwrap()
+        module.define_function(func_id, context).unwrap();
     });
 
     // Write optimized function to file for debugging
diff --git a/src/pretty_clif.rs b/src/pretty_clif.rs
index ca7116b887d..1d1ec21680e 100644
--- a/src/pretty_clif.rs
+++ b/src/pretty_clif.rs
@@ -66,7 +66,7 @@ use rustc_session::config::OutputType;
 
 use crate::prelude::*;
 
-#[derive(Debug)]
+#[derive(Clone, Debug)]
 pub(crate) struct CommentWriter {
     enabled: bool,
     global_comments: Vec<String>,
@@ -237,6 +237,7 @@ pub(crate) fn write_clif_file<'tcx>(
     func: &cranelift_codegen::ir::Function,
     mut clif_comments: &CommentWriter,
 ) {
+    // FIXME work around filename too long errors
     write_ir_file(
         tcx,
         || format!("{}.{}.clif", tcx.symbol_name(instance).name, postfix),