1 //! Helpers used to print a message and abort in case of certain panics and some detected UB.
5 fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) {
12 call_conv: fx.target_config.default_call_conv,
13 params: vec![AbiParam::new(fx.pointer_type)],
14 returns: vec![AbiParam::new(types::I32)],
18 let puts = fx.module.declare_func_in_func(puts, &mut fx.bcx.func);
19 if fx.clif_comments.enabled() {
20 fx.add_comment(puts, "puts");
23 let real_msg = format!("trap at {:?} ({}): {}\0", fx.instance, fx.symbol_name, msg);
24 let msg_ptr = fx.anonymous_str(&real_msg);
25 fx.bcx.ins().call(puts, &[msg_ptr]);
28 /// Use this when something is unimplemented, but `libcore` or `libstd` requires it to codegen.
30 /// Trap code: user65535
31 pub(crate) fn trap_unimplemented(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef<str>) {
32 codegen_print(fx, msg.as_ref());
33 fx.bcx.ins().trap(TrapCode::User(!0));