]> git.lizzy.rs Git - rust.git/blobdiff - src/trap.rs
Rustup to rustc 1.42.0-nightly (3ebcfa145 2020-01-12)
[rust.git] / src / trap.rs
index c4e2cf35766bce5f3565dd9d8a4fa504fea914d2..316a26781dab49b55936a02ea9ddab31d460eaad 100644 (file)
@@ -1,13 +1,21 @@
 use crate::prelude::*;
 
 fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: &str) {
-    let puts = fx.module.declare_function("puts", Linkage::Import, &Signature {
-        call_conv: CallConv::SystemV,
-        params: vec![AbiParam::new(pointer_ty(fx.tcx))],
-        returns: vec![],
-    }).unwrap();
+    let puts = fx
+        .module
+        .declare_function(
+            "puts",
+            Linkage::Import,
+            &Signature {
+                call_conv: CallConv::triple_default(fx.triple()),
+                params: vec![AbiParam::new(pointer_ty(fx.tcx))],
+                returns: vec![],
+            },
+        )
+        .unwrap();
     let puts = fx.module.declare_func_in_func(puts, &mut fx.bcx.func);
-    #[cfg(debug_assertions)] {
+    #[cfg(debug_assertions)]
+    {
         fx.add_entity_comment(puts, "puts");
     }
 
@@ -15,13 +23,22 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
     let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, symbol_name, msg);
     let mut data_ctx = DataContext::new();
     data_ctx.define(real_msg.as_bytes().to_vec().into_boxed_slice());
-    let msg_id = fx.module.declare_data(&(symbol_name.as_str().to_string() + msg), Linkage::Local, false, None).unwrap();
+    let msg_id = fx
+        .module
+        .declare_data(
+            &(symbol_name.name.as_str().to_string() + msg),
+            Linkage::Local,
+            false,
+            None,
+        )
+        .unwrap();
 
     // Ignore DuplicateDefinition error, as the data will be the same
     let _ = fx.module.define_data(msg_id, &data_ctx);
 
     let local_msg_id = fx.module.declare_data_in_func(msg_id, fx.bcx.func);
-    #[cfg(debug_assertions)] {
+    #[cfg(debug_assertions)]
+    {
         fx.add_entity_comment(local_msg_id, msg);
     }
     let msg_ptr = fx.bcx.ins().global_value(pointer_ty(fx.tcx), local_msg_id);
@@ -31,7 +48,10 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, ms
 /// Use this when `rustc_codegen_llvm` would insert a call to the panic handler.
 ///
 /// Trap code: user0
-pub fn trap_panic(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: impl AsRef<str>) {
+pub fn trap_panic(
+    fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>,
+    msg: impl AsRef<str>,
+) {
     codegen_print(fx, msg.as_ref());
     fx.bcx.ins().trap(TrapCode::User(0));
 }
@@ -40,7 +60,10 @@ pub fn trap_panic(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, m
 /// so you can **not** add instructions to it afterwards.
 ///
 /// Trap code: user65535
-pub fn trap_unreachable(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: impl AsRef<str>) {
+pub fn trap_unreachable(
+    fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>,
+    msg: impl AsRef<str>,
+) {
     codegen_print(fx, msg.as_ref());
     fx.bcx.ins().trap(TrapCode::User(!0));
 }
@@ -50,7 +73,10 @@ pub fn trap_unreachable(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backe
 /// to it afterwards.
 ///
 /// Trap code: user65535
-pub fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>, msg: impl AsRef<str>) {
+pub fn trap_unimplemented(
+    fx: &mut FunctionCx<'_, '_, impl cranelift_module::Backend>,
+    msg: impl AsRef<str>,
+) {
     codegen_print(fx, msg.as_ref());
     let true_ = fx.bcx.ins().iconst(types::I32, 1);
     fx.bcx.ins().trapnz(true_, TrapCode::User(!0));
@@ -59,17 +85,11 @@ pub fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, impl cranelift_module::Bac
 /// Like `trap_unreachable` but returns a fake value of the specified type.
 ///
 /// Trap code: user65535
-pub fn trap_unreachable_ret_value<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>, dest_layout: TyLayout<'tcx>, msg: impl AsRef<str>) -> CValue<'tcx> {
+pub fn trap_unreachable_ret_value<'tcx>(
+    fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>,
+    dest_layout: TyLayout<'tcx>,
+    msg: impl AsRef<str>,
+) -> CValue<'tcx> {
     trap_unimplemented(fx, msg);
-    let zero = fx.bcx.ins().iconst(fx.pointer_type, 0);
-    CValue::by_ref(zero, dest_layout)
-}
-
-/// Like `trap_unreachable` but returns a fake place for the specified type.
-///
-/// Trap code: user65535
-pub fn trap_unreachable_ret_place<'tcx>(fx: &mut FunctionCx<'_, 'tcx, impl cranelift_module::Backend>, dest_layout: TyLayout<'tcx>, msg: impl AsRef<str>) -> CPlace<'tcx> {
-    trap_unimplemented(fx, msg);
-    let zero = fx.bcx.ins().iconst(fx.pointer_type, 0);
-    CPlace::for_addr(zero, dest_layout)
+    CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout)
 }