authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-03 12:11:06-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-04 01:54:12-04:00
log7b1a644d6ee50740196328bd8f7b1a46ac46b4d2
tree2fc53e03788e484d056263166a5c461977905c8b
parent46d3e5bb04393c6be196b10e262d122e008403aa

print_zir: fix more crashes during printing


2 files changed, 7 insertions(+), 9 deletions(-)

src/main.zig+1
......@@ -6492,6 +6492,7 @@ pub fn cmdDumpZir(
64926492 .mod = undefined,
64936493 .root_decl = .none,
64946494 };
6495 defer file.zir.deinit(gpa);
64956496
64966497 {
64976498 const instruction_bytes = file.zir.instructions.len *
src/print_zir.zig+6-9
......@@ -2456,20 +2456,15 @@ const Writer = struct {
24562456 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
24572457
24582458 try self.writeInstRef(stream, inst_data.operand);
2459
24592460 try stream.writeAll(")");
24602461 }
24612462
24622463 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
24632464 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
24642465
2465 if (inst_data.block != .none) {
2466 try self.writeInstRef(stream, inst_data.block);
2467 }
2468
2469 if (inst_data.operand != .none) {
2470 if (inst_data.block != .none) try stream.writeAll(", ");
2471 try self.writeInstRef(stream, inst_data.operand);
2472 }
2466 try self.writeInstRef(stream, inst_data.block);
2467 try self.writeInstRef(stream, inst_data.operand);
24732468
24742469 try stream.writeAll(")");
24752470 }
......@@ -2615,7 +2610,9 @@ const Writer = struct {
26152610 }
26162611
26172612 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
2618 if (ref.toIndex()) |i| {
2613 if (ref == .none) {
2614 return stream.writeAll(".none");
2615 } else if (ref.toIndex()) |i| {
26192616 return self.writeInstIndex(stream, i);
26202617 } else {
26212618 const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));