about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2024-03-17 22:26:39 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2024-03-22 09:55:50 -0400
commit05783c8ed68f7b393d28f5df64f98d3d1eee5537 (patch)
treed3765003e7e8c08489c97702a205d6f3058dc81f /src
parent06ef32c86251ba3a54ced4d8bf074f95ee30bc62 (diff)
downloadrust-05783c8ed68f7b393d28f5df64f98d3d1eee5537.tar.gz
rust-05783c8ed68f7b393d28f5df64f98d3d1eee5537.zip
Codegen const panic messages as function calls
This skips emitting extra arguments at every callsite (of which there
can be many). For a librustc_driver build with overflow checks enabled,
this cuts 0.7MB from the resulting binary.
Diffstat (limited to 'src')
-rw-r--r--src/base.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/base.rs b/src/base.rs
index 2415c2c90b2..f597f084e70 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -369,8 +369,14 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
                         );
                     }
                     _ => {
-                        let msg_str = msg.description();
-                        codegen_panic(fx, msg_str, source_info);
+                        let location = fx.get_caller_location(source_info).load_scalar(fx);
+
+                        codegen_panic_inner(
+                            fx,
+                            msg.panic_function(),
+                            &[location],
+                            Some(source_info.span),
+                        );
                     }
                 }
             }
@@ -954,20 +960,6 @@ pub(crate) fn codegen_operand<'tcx>(
     }
 }
 
-pub(crate) fn codegen_panic<'tcx>(
-    fx: &mut FunctionCx<'_, '_, 'tcx>,
-    msg_str: &str,
-    source_info: mir::SourceInfo,
-) {
-    let location = fx.get_caller_location(source_info).load_scalar(fx);
-
-    let msg_ptr = fx.anonymous_str(msg_str);
-    let msg_len = fx.bcx.ins().iconst(fx.pointer_type, i64::try_from(msg_str.len()).unwrap());
-    let args = [msg_ptr, msg_len, location];
-
-    codegen_panic_inner(fx, rustc_hir::LangItem::Panic, &args, Some(source_info.span));
-}
-
 pub(crate) fn codegen_panic_nounwind<'tcx>(
     fx: &mut FunctionCx<'_, '_, 'tcx>,
     msg_str: &str,