let ret_block = fx.get_block(dest);
fx.bcx.ins().jump(ret_block, &[]);
} else {
- trap_unreachable(fx, "[corruption] Diverging function returned");
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
}
} else if arg_uninhabited {
fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
- crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument");
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
} else {
tcx.sess.time("codegen clif ir", || {
tcx.sess
fx.bcx.ins().jump(destination_block, &[]);
}
None => {
- crate::trap::trap_unreachable(
- fx,
- "[corruption] Returned from noreturn inline asm",
- );
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
}
}
TerminatorKind::Resume | TerminatorKind::Abort => {
- trap_unreachable(fx, "[corruption] Unwinding bb reached.");
+ // FIXME implement unwinding
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
TerminatorKind::Unreachable => {
- trap_unreachable(fx, "[corruption] Hit unreachable code.");
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
TerminatorKind::Yield { .. }
| TerminatorKind::FalseEdge { .. }
args,
);
- crate::trap::trap_unreachable(fx, "panic lang item returned");
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
let layout = value.layout();
if layout.abi == Abi::Uninhabited {
- return trap_unreachable_ret_value(
- fx,
- dest_layout,
- "[panic] Tried to get discriminant for uninhabited type.",
- );
+ let true_ = fx.bcx.ins().iconst(types::I32, 1);
+ fx.bcx.ins().trapnz(true_, TrapCode::UnreachableCodeReached);
+ // Return a dummy value
+ return CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout);
}
let (tag_scalar, tag_field, tag_encoding) = match &layout.variants {
};
}
- if let Some((_, dest)) = destination {
- let ret_block = fx.get_block(dest);
- fx.bcx.ins().jump(ret_block, &[]);
- } else {
- trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
- }
+ let dest = destination.expect("all llvm intrinsics used by stdlib should return").1;
+ let ret_block = fx.get_block(dest);
+ fx.bcx.ins().jump(ret_block, &[]);
}
// llvm.x86.avx2.vperm2i128
// Insert non returning intrinsics here
match intrinsic {
sym::abort => {
- trap_abort(fx, "Called intrinsic::abort.");
+ fx.bcx.ins().trap(TrapCode::User(0));
}
sym::transmute => {
crate::base::codegen_panic(fx, "Transmuting to uninhabited type.", span);
let ret_block = fx.get_block(dest);
fx.bcx.ins().jump(ret_block, &[]);
} else {
- trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
+ fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
}
pub(crate) use crate::common::*;
pub(crate) use crate::debuginfo::{DebugContext, UnwindContext};
pub(crate) use crate::pointer::Pointer;
- pub(crate) use crate::trap::*;
pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue};
}
fx.bcx.ins().call(puts, &[msg_ptr]);
}
-/// Trap code: user1
-pub(crate) fn trap_abort(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef<str>) {
- codegen_print(fx, msg.as_ref());
- fx.bcx.ins().trap(TrapCode::User(1));
-}
-
/// Use this for example when a function call should never return. This will fill the current block,
/// so you can **not** add instructions to it afterwards.
///
codegen_print(fx, msg.as_ref());
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}
-
-/// Like `trap_unreachable` but returns a fake value of the specified type.
-///
-/// Trap code: user65535
-pub(crate) fn trap_unreachable_ret_value<'tcx>(
- fx: &mut FunctionCx<'_, '_, 'tcx>,
- dest_layout: TyAndLayout<'tcx>,
- msg: impl AsRef<str>,
-) -> CValue<'tcx> {
- codegen_print(fx, msg.as_ref());
- let true_ = fx.bcx.ins().iconst(types::I32, 1);
- fx.bcx.ins().trapnz(true_, TrapCode::UnreachableCodeReached);
- CValue::by_ref(Pointer::const_addr(fx, 0), dest_layout)
-}
-
/// Use this when something is unimplemented, but `libcore` or `libstd` requires it to codegen.
/// Unlike `trap_unreachable` this will not fill the current block, so you **must** add instructions
/// to it afterwards.