Skip to content

Commit

Permalink
Fixing leak when VM disassembly fails and making failure non-fatal. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benvanik authored Sep 9, 2024
1 parent a730349 commit 7212b48
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
34 changes: 22 additions & 12 deletions runtime/src/iree/vm/bytecode/disassembler.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ static iree_status_t iree_vm_bytecode_disassembler_emit_type_name(
}
}
#define EMIT_TYPE_NAME(type_def) \
iree_vm_bytecode_disassembler_emit_type_name(type_def, b);
IREE_RETURN_IF_ERROR( \
iree_vm_bytecode_disassembler_emit_type_name(type_def, b))

static iree_status_t iree_vm_bytecode_disassembler_emit_operand_list(
const iree_vm_registers_t* regs, const iree_vm_register_list_t* list,
Expand All @@ -194,8 +195,9 @@ static iree_status_t iree_vm_bytecode_disassembler_emit_operand_list(
}
return iree_ok_status();
}
#define EMIT_OPERAND_REG_LIST(reg_list) \
iree_vm_bytecode_disassembler_emit_operand_list(regs, reg_list, format, b)
#define EMIT_OPERAND_REG_LIST(reg_list) \
IREE_RETURN_IF_ERROR(iree_vm_bytecode_disassembler_emit_operand_list( \
regs, reg_list, format, b))
static iree_status_t iree_vm_bytecode_disassembler_emit_result_list(
const iree_vm_register_list_t* list,
iree_vm_bytecode_disassembly_format_t format, iree_string_builder_t* b) {
Expand All @@ -209,7 +211,8 @@ static iree_status_t iree_vm_bytecode_disassembler_emit_result_list(
return iree_ok_status();
}
#define EMIT_RESULT_REG_LIST(reg_list) \
iree_vm_bytecode_disassembler_emit_result_list(reg_list, format, b)
IREE_RETURN_IF_ERROR( \
iree_vm_bytecode_disassembler_emit_result_list(reg_list, format, b))
static iree_status_t iree_vm_bytecode_disassembler_emit_remap_list(
const iree_vm_registers_t* regs,
const iree_vm_register_remap_list_t* remap_list,
Expand All @@ -231,8 +234,9 @@ static iree_status_t iree_vm_bytecode_disassembler_emit_remap_list(
}
return iree_ok_status();
}
#define EMIT_REMAP_LIST(remap_list) \
iree_vm_bytecode_disassembler_emit_remap_list(regs, remap_list, format, b)
#define EMIT_REMAP_LIST(remap_list) \
IREE_RETURN_IF_ERROR(iree_vm_bytecode_disassembler_emit_remap_list( \
regs, remap_list, format, b))

#define EMIT_OPTIONAL_VALUE_I32(expr) \
if (regs && (format & IREE_VM_BYTECODE_DISASSEMBLY_FORMAT_INLINE_VALUES)) { \
Expand Down Expand Up @@ -2742,16 +2746,20 @@ iree_status_t iree_vm_bytecode_trace_disassembly(
if (iree_status_is_ok(status)) {
iree_string_view_t module_name =
iree_vm_module_name(frame->function.module);
IREE_RETURN_IF_ERROR(iree_string_builder_append_format(
&b, "[%.*s", (int)module_name.size, module_name.data));
status = iree_string_builder_append_format(
&b, "[%.*s", (int)module_name.size, module_name.data);
}
if (iree_status_is_ok(status)) {
iree_string_view_t function_name = iree_vm_function_name(&frame->function);
if (iree_string_view_is_empty(function_name)) {
IREE_RETURN_IF_ERROR(iree_string_builder_append_format(
&b, "@%u", (uint32_t)frame->function.ordinal));
status = iree_string_builder_append_format(
&b, "@%u", (uint32_t)frame->function.ordinal);
} else {
IREE_RETURN_IF_ERROR(iree_string_builder_append_format(
&b, ".%.*s", (int)function_name.size, function_name.data));
status = iree_string_builder_append_format(
&b, ".%.*s", (int)function_name.size, function_name.data);
}
}
if (iree_status_is_ok(status)) {
status = iree_string_builder_append_format(&b, "+%08" PRIX64 "] ", pc);
}

Expand All @@ -2766,6 +2774,8 @@ iree_status_t iree_vm_bytecode_trace_disassembly(
if (iree_status_is_ok(status)) {
fprintf(file, "%.*s\n", (int)iree_string_builder_size(&b),
iree_string_builder_buffer(&b));
} else {
fprintf(file, "<<disassembly failed>>\n");
}

iree_string_builder_deinitialize(&b);
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/iree/vm/bytecode/dispatch_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ static inline iree_vm_type_def_t iree_vm_map_type(
#endif // IREE_VM_EXECUTION_TRACING_FORCE_ENABLE

#if IREE_VM_EXECUTION_TRACING_ENABLE
#define IREE_DISPATCH_TRACE_INSTRUCTION(pc_offset, op_name) \
if (IREE_IS_DISPATCH_TRACING_ENABLED()) { \
IREE_RETURN_IF_ERROR(iree_vm_bytecode_trace_disassembly( \
current_frame, (pc - (pc_offset)), &regs, stderr)); \
#define IREE_DISPATCH_TRACE_INSTRUCTION(pc_offset, op_name) \
if (IREE_IS_DISPATCH_TRACING_ENABLED()) { \
IREE_IGNORE_ERROR(iree_vm_bytecode_trace_disassembly( \
current_frame, (pc - (pc_offset)), &regs, stderr)); \
}

#else
Expand Down

0 comments on commit 7212b48

Please sign in to comment.