Merge pull request #1220 from bjorn3/dont_print_on_trap

Replace a lot of print+trap with plain trap
This commit is contained in:
bjorn3 2022-03-14 12:51:47 +01:00 committed by GitHub
commit 4ba83cbfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 44 deletions

View File

@ -507,7 +507,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
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);
}
}

View File

@ -90,7 +90,7 @@ pub(crate) fn codegen_fn<'tcx>(
} 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
@ -424,18 +424,16 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, '_>) {
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 { .. }
@ -925,5 +923,5 @@ pub(crate) fn codegen_panic_inner<'tcx>(
args,
);
crate::trap::trap_unreachable(fx, "panic lang item returned");
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
}

View File

@ -68,11 +68,10 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
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 {

View File

@ -126,12 +126,9 @@ pub(crate) fn codegen_llvm_intrinsic_call<'tcx>(
};
}
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

View File

@ -229,7 +229,7 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
// 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);
@ -1119,6 +1119,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
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);
}
}

View File

@ -105,7 +105,6 @@ mod prelude {
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};
}

View File

@ -25,12 +25,6 @@ fn codegen_print(fx: &mut FunctionCx<'_, '_, '_>, msg: &str) {
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.
///
@ -39,21 +33,6 @@ pub(crate) fn trap_unreachable(fx: &mut FunctionCx<'_, '_, '_>, msg: impl AsRef<
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.