Improve abort/panic messages to be more distinctive.

This commit is contained in:
Eduard-Mihai Burtescu 2023-07-20 10:15:43 +03:00 committed by Eduard-Mihai Burtescu
parent 883d5aaade
commit 34e1c90c32
3 changed files with 12 additions and 6 deletions

View File

@ -2648,7 +2648,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
// HACK(eddyb) redirect any possible panic call to an abort, to avoid
// needing to materialize `&core::panic::Location` or `format_args!`.
// FIXME(eddyb) find a way to extract the original message.
self.abort_with_message("panic!(...)".into());
self.abort_with_message("panicked: <unknown message>".into());
self.undef(result_type)
} else if let Some(mode) = buffer_load_intrinsic {
self.codegen_buffer_load_intrinsic(result_type, args, mode)

View File

@ -339,7 +339,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> {
}
fn abort(&mut self) {
self.abort_with_message("intrinsics::abort()".into());
self.abort_with_message("aborted: intrinsics::abort() called".into());
}
fn assume(&mut self, _val: Self::Value) {

View File

@ -332,11 +332,15 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
// HACK(eddyb) this improves readability w/ very verbose Vulkan loggers.
fmt += "\n";
if let Some((file, line, col)) = current_debug_src_loc.take() {
fmt += &format!("{file}:{line}:{col}: ").replace('%', "%%");
}
fmt += "[RUST-GPU] ";
fmt += &cx[const_str(message)].replace('%', "%%");
// FIXME(eddyb) deduplicate with "called at" form below
// (not trivial becasue both closures would borrow `fmt`).
if let Some((file, line, col)) = current_debug_src_loc.take() {
fmt += &format!("\n at {file}:{line}:{col}").replace('%', "%%");
}
let mut innermost = true;
let mut append_call = |callsite_debug_src_loc, callee: &str| {
if innermost {
@ -360,6 +364,8 @@ pub fn convert_custom_aborts_to_unstructured_returns_in_entry_points(
}
append_call(None, &debug_printf_context_fmt_str);
fmt += "\n";
let abort_inst_def = &mut func_def_body.data_insts[abort_inst];
abort_inst_def.kind = DataInstKind::SpvExtInst {
ext_set: cx.intern("NonSemantic.DebugPrintf"),